diff options
| author | Albrecht Schlosser <albrechts.fltk@online.de> | 2023-01-01 21:53:07 +0100 |
|---|---|---|
| committer | Albrecht Schlosser <albrechts.fltk@online.de> | 2023-01-12 19:21:09 +0100 |
| commit | bafd3fd3d792b530d39d3af06e087dc63d2a25a2 (patch) | |
| tree | 42f4d533490191a92a13863d07378820b04a7b9c /test | |
| parent | 79832b679f2d195eb3b0f30ca920a857cc133b2b (diff) | |
Add Fl_Scheme_Choice widget and use it in test programs
This widget offers the selection of all known FLTK schemes as a simple
widget based on Fl_Choice.
Some test and demo programs use Fl_Scheme_Choice to enable the developer
or user to switch schemes quickly for comparison.
Todo:
- add features to add new schemes during runtime (partially done)
- update status when the scheme is changed by Fl::scheme("...")
Diffstat (limited to 'test')
| -rw-r--r-- | test/boxtype.cxx | 2 | ||||
| -rw-r--r-- | test/buttons.cxx | 28 | ||||
| -rw-r--r-- | test/demo.cxx | 34 | ||||
| -rw-r--r-- | test/menubar.cxx | 5 | ||||
| -rw-r--r-- | test/unittest_schemes.cxx | 30 |
5 files changed, 45 insertions, 54 deletions
diff --git a/test/boxtype.cxx b/test/boxtype.cxx index 29a89c3b6..24d176eb1 100644 --- a/test/boxtype.cxx +++ b/test/boxtype.cxx @@ -19,6 +19,7 @@ #include <FL/Fl.H> #include <FL/Fl_Double_Window.H> #include <FL/Fl_Box.H> +#include <FL/Fl_Scheme_Choice.H> #include <FL/fl_draw.H> int N = 0; @@ -176,6 +177,7 @@ int main(int argc, char ** argv) { bt("FL_GTK_ROUND_DOWN_BOX",FL_GTK_ROUND_DOWN_BOX); bg->end(); window->resizable(window); + Fl_Scheme_Choice scheme_choice(610, 10, 150, 30, "Scheme:"); window->end(); window->show(); return Fl::run(); diff --git a/test/buttons.cxx b/test/buttons.cxx index ffd5678ff..e93f4dc8e 100644 --- a/test/buttons.cxx +++ b/test/buttons.cxx @@ -22,16 +22,28 @@ #include <FL/Fl_Check_Button.H> #include <FL/Fl_Light_Button.H> #include <FL/Fl_Round_Button.H> +#include <FL/Fl_Scheme_Choice.H> int main(int argc, char **argv) { - Fl_Window *window = new Fl_Window(320, 130); - Fl_Button *b = new Fl_Button(10, 10, 130, 30, "Fl_Button"); - b->tooltip("This is a Tooltip."); - new Fl_Return_Button(150, 10, 160, 30, "Fl_Return_Button"); - new Fl_Repeat_Button(10, 50, 130, 30, "Fl_Repeat_Button"); - new Fl_Round_Button(150, 50, 160, 30, "Fl_Round_Button"); - new Fl_Light_Button(10, 90, 130, 30, "Fl_Light_Button"); - new Fl_Check_Button(150, 90, 160, 30, "Fl_Check_Button"); + Fl_Window *window = new Fl_Window(320, 170); + Fl_Button *b1 = new Fl_Button(10, 10, 130, 30, "Fl_Button"); + b1->tooltip("Fl_Button"); + Fl_Button *b2 = new Fl_Return_Button(150, 10, 160, 30, "Fl_Return_Button"); + b2->tooltip("Fl_Return_Button"); + Fl_Button *b3 = new Fl_Repeat_Button(10, 50, 130, 30, "Fl_Repeat_Button"); + b3->tooltip("Fl_Repeat_Button"); + Fl_Button *b4 = new Fl_Round_Button(150, 50, 160, 30, "Fl_Round_Button"); + b4->tooltip("Fl_Round_Button"); + Fl_Button *b5 = new Fl_Light_Button(10, 90, 130, 30, "Fl_Light_Button"); + b5->tooltip("Fl_Light_Button"); + Fl_Button *b6 = new Fl_Check_Button(150, 90, 160, 30, "Fl_Check_Button"); + b6->tooltip("Fl_Check_Button"); + + // Add a scheme choice widget for easier testing. Position the widget at + // the right window border so the menu popup doesn't cover the check boxes etc. + Fl_Scheme_Choice *scheme_choice = new Fl_Scheme_Choice(180, 130, 130, 30, "Active FLTK Scheme:"); + scheme_choice->tooltip("Fl_Scheme_Choice"); + window->end(); window->resizable(window); window->size_range(320, 130); diff --git a/test/demo.cxx b/test/demo.cxx index c41b22d45..fa763d420 100644 --- a/test/demo.cxx +++ b/test/demo.cxx @@ -78,7 +78,7 @@ #include <FL/Fl_Box.H> #include <FL/Fl_Button.H> #include <FL/Fl_Menu_Button.H> // right click popup menu -#include <FL/Fl_Choice.H> +#include <FL/Fl_Scheme_Choice.H> #include <FL/Fl_Simple_Terminal.H> // tty #include <FL/filename.H> #include <FL/platform.H> @@ -95,13 +95,11 @@ void doexit(Fl_Widget *, void *); void doback(Fl_Widget *, void *); void dobut(Fl_Widget *, long); -void doscheme(Fl_Choice *c, void *) { - Fl::scheme(c->text(c->value())); -} Fl_Double_Window *form = 0; Fl_Group *demogrp = 0; Fl_Simple_Terminal *tty = 0; +Fl_Scheme_Choice *scheme_choice = 0; Fl_Button *but[9]; Fl_Button *exit_button; @@ -185,21 +183,8 @@ void create_the_forms() { obj = new Fl_Box(FL_FRAME_BOX, 10, 65, 330, 330, 0); obj->color(FL_GRAY-8); - Fl_Choice *choice = new Fl_Choice(90, 405, 100, 25, "Scheme:"); - choice->labelfont(FL_HELVETICA_BOLD); - choice->add("none"); - choice->add("gtk+"); - choice->add("gleam"); - choice->add("oxy"); - choice->add("plastic"); - choice->callback((Fl_Callback *)doscheme); - Fl::scheme(NULL); - if (!Fl::scheme()) choice->value(0); - else if (!strcmp(Fl::scheme(), "gtk+")) choice->value(1); - else if (!strcmp(Fl::scheme(), "gleam")) choice->value(2); - else if (!strcmp(Fl::scheme(), "oxy")) choice->value(3); - else if (!strcmp(Fl::scheme(), "plastic")) choice->value(4); - else choice->value(0); + scheme_choice = new Fl_Scheme_Choice(90, 405, 100, 25, "Scheme:"); + scheme_choice->labelfont(FL_HELVETICA_BOLD); exit_button = new Fl_Button(280, 405, 60, 25, "Exit"); exit_button->callback(doexit); @@ -639,6 +624,17 @@ int main(int argc, char **argv) { // set size_range() after show() so the window can be resizable (Win + macOS) form->size_range(FORM_W, FORM_H, FORM_W, FORM_H); +#if (0) // DEBUG (remove after testing) + { + const char *const *scheme_names = Fl_Scheme_Choice::scheme_names(); + int ni = 0; + while (scheme_names[ni]) { + printf("scheme[%2d] = '%s'\n", ni, scheme_names[ni]); + ni++; + } + } +#endif // End of debug and test statements + Fl::run(); return 0; } diff --git a/test/menubar.cxx b/test/menubar.cxx index 1f7750007..f8b1aaffc 100644 --- a/test/menubar.cxx +++ b/test/menubar.cxx @@ -23,7 +23,7 @@ #include <FL/Fl_Sys_Menu_Bar.H> #include <FL/Fl_Toggle_Button.H> #include <FL/Fl_Menu_Button.H> -#include <FL/Fl_Choice.H> +#include <FL/Fl_Scheme_Choice.H> #include <FL/Fl_Value_Slider.H> #include <stdio.h> #include <stdlib.h> @@ -229,6 +229,9 @@ int main(int argc, char **argv) { hugemenu[i].text = fl_strdup(buf); } Fl_Double_Window window(WIDTH,400+TERMINAL_HEIGHT); + + Fl_Scheme_Choice scheme_choice(300, 50, 100, 25, "&scheme"); + G_tty = new Fl_Simple_Terminal(0,400,WIDTH,TERMINAL_HEIGHT); window.callback(window_cb); diff --git a/test/unittest_schemes.cxx b/test/unittest_schemes.cxx index 4baec44d8..93ec3c353 100644 --- a/test/unittest_schemes.cxx +++ b/test/unittest_schemes.cxx @@ -18,7 +18,7 @@ #include "unittests.h" -#include <FL/Fl_Choice.H> +#include <FL/Fl_Scheme_Choice.H> // needed by Edmanuel's test layout #include <FL/Fl_Button.H> @@ -45,16 +45,7 @@ #include <FL/Fl_Radio_Round_Button.H> class Ut_Schemes_Test : public Fl_Group { - Fl_Choice *scheme_choice_; - - static void scheme_choice_cb(Fl_Widget*,void *data) { - Ut_Schemes_Test *st = (Ut_Schemes_Test*)data; - const char *name = st->scheme_choice_->text(); - if ( name ) { - Fl::scheme(name); // change scheme - st->window()->redraw(); // redraw window - } - } // SchemeChoice_CB() + Fl_Scheme_Choice *scheme_choice_; static void activate_subwin(Fl_Widget *w, void *data) { Fl_Window *win = (Fl_Window *)data; @@ -82,22 +73,9 @@ public: } Ut_Schemes_Test(int X,int Y,int W,int H) : Fl_Group(X,Y,W,H) { - scheme_choice_ = new Fl_Choice(X+125,Y,140,25,"FLTK Scheme"); - scheme_choice_->add("none"); - scheme_choice_->add("plastic"); - scheme_choice_->add("gtk+"); - scheme_choice_->add("gleam"); - scheme_choice_->add("oxy"); - scheme_choice_->value(0); + + scheme_choice_ = new Fl_Scheme_Choice(X+125,Y,140,25,"FLTK Scheme"); scheme_choice_->labelfont(FL_HELVETICA_BOLD); - const char *name = Fl::scheme(); - if ( name ) { - if ( strcmp(name, "plastic") == 0) { scheme_choice_->value(1); } - else if ( strcmp(name, "gtk+") == 0) { scheme_choice_->value(2); } - else if ( strcmp(name, "gleam") == 0) { scheme_choice_->value(3); } - else if ( strcmp(name, "oxy") == 0) { scheme_choice_->value(4); } - } - scheme_choice_->callback(scheme_choice_cb, (void*)this); Fl_Light_Button *active = new Fl_Light_Button(X + 300, Y, 100, 25, "active"); active->value(1); |
