gansm / finalcut

A text-based widget toolkit
https://github.com/gansm/finalcut/wiki/First-steps#first-steps-with-the-final-cut-widget-toolkit
GNU Lesser General Public License v3.0
981 stars 52 forks source link

Tab order #106

Closed wimstockman closed 1 year ago

wimstockman commented 1 year ago

Hi , I was wondering how I can change the taborder of the nextchild focus. Kind Regards Wim

gansm commented 1 year ago

Hi Wim, it's generally intended that the child adding order determines the tab order. But you can change the order afterward (for example, by sorting the children's list).

#include <final/final.h>

using namespace finalcut;

int main (int argc, char* argv[])
{
  FApplication app(argc, argv);

  // The dialog window
  FDialog dialog("The window title", &app);
  dialog.setGeometry (FPoint{20, 5}, FSize{40, 12});

  // The child objects from dialog
  FButton child4("&4", &dialog);  // 1st child
  FButton child1("&1", &dialog);  // 2nd child
  FButton child3("&3", &dialog);  // 3rd child
  FButton child2("&2", &dialog);  // 4th child
  child1.setGeometry(FPoint{6, 2}, FSize{28, 1});
  child2.setGeometry(FPoint{6, 4}, FSize{28, 1});
  child3.setGeometry(FPoint{6, 6}, FSize{28, 1});
  child4.setGeometry(FPoint{6, 8}, FSize{28, 1});

  // Sort by button name to change the initial tab order of the widgets
  std::sort ( dialog.begin()
            , dialog.end()
            , [] (const auto lhs, const auto rhs)
              {
                // Skip non-button widgets
                if ( ! lhs->isInstanceOf("FButton")
                  || ! rhs->isInstanceOf("FButton") )
                  return false;

                const auto& lhs_btn = static_cast<FButton*>(lhs);
                const auto& rhs_btn = static_cast<FButton*>(rhs);
                return lhs_btn->getText() < rhs_btn->getText();
              } );

  FWidget::setMainWidget(&dialog);
  dialog.show();
  return app.exec();
}

grafik

wimstockman commented 1 year ago

Hi gansm,

Thanks for this example. Just what I needed.