From 64cd50c1306258460becf81ff06058e09a357929 Mon Sep 17 00:00:00 2001 From: Albrecht Schlosser Date: Thu, 27 Jun 2024 03:19:26 +0200 Subject: [PATCH] Update test/input_choice demo (#978) - add Fl_Choice widget for layout comparison - rewrite button callbacks - improve layout and other details This is a follow-up to issue #978, "merging" the existing input_choice demo with "choicetest_v3" as mentioned. --- test/input_choice.cxx | 98 ++++++++++++++++++++++++++++--------------- 1 file changed, 64 insertions(+), 34 deletions(-) diff --git a/test/input_choice.cxx b/test/input_choice.cxx index c5bb1dcd6..d0a915369 100644 --- a/test/input_choice.cxx +++ b/test/input_choice.cxx @@ -1,7 +1,7 @@ // -// Test program for Fl_Input_Choice +// Test program for Fl_Input_Choice and Fl_Choice // -// Copyright 1998-2010 by Bill Spitzak and others. +// Copyright 1998-2024 by Bill Spitzak and others. // // This library is free software. Distribution and use rights are outlined in // the file "COPYING" which should have been included with this file. If this @@ -14,54 +14,84 @@ // https://www.fltk.org/bugs.php // -#include -#include #include #include +#include #include +#include #include -#define TERMINAL_HEIGHT 120 +#define TERMINAL_HEIGHT 150 // Globals Fl_Terminal *G_tty = 0; -void buttcb(Fl_Widget*,void*data) { - Fl_Input_Choice *in=(Fl_Input_Choice *)data; - static int flag = 1; - flag ^= 1; - if ( flag ) in->activate(); - else in->deactivate(); - if (in->changed()) { - G_tty->printf("Callback: changed() is set\n"); - in->clear_changed(); - } +void active_cb(Fl_Widget *w, void *data) { + Fl_Check_Button *b = (Fl_Check_Button *)w; + Fl_Group *g = (Fl_Group *)data; + if (b->value()) { + g->activate(); + G_tty->printf("activate group\n"); + } else { + g->deactivate(); + G_tty->printf("deactivate group\n"); + } + g->redraw(); + if (b->changed()) { + G_tty->printf("Callback: changed() is set\n"); + b->clear_changed(); + } } -void input_choice_cb(Fl_Widget*,void*data) { - Fl_Input_Choice *in=(Fl_Input_Choice *)data; - G_tty->printf("Value='%s'\n", (const char*)in->value()); +void input_choice_cb(Fl_Widget *, void *data) { + Fl_Input_Choice *in = (Fl_Input_Choice *)data; + G_tty->printf("Fl_Input_Choice value='%s'\n", (const char *)in->value()); +} + +void choice_cb(Fl_Widget *, void *data) { + Fl_Choice *in = (Fl_Choice *)data; + G_tty->printf("Fl_Choice value='%d'\n", in->value()); } int main(int argc, char **argv) { - Fl_Double_Window win(300, 200+TERMINAL_HEIGHT); - G_tty = new Fl_Terminal(0,200,win.w(),TERMINAL_HEIGHT); + Fl_Window *win = new Fl_Double_Window(300, 200 + TERMINAL_HEIGHT); - Fl_Input_Choice in(40,40,100,28,"Test"); - in.callback(input_choice_cb, (void*)&in); - in.add("one"); - in.add("two"); - in.add("three"); - in.value(1); + G_tty = new Fl_Terminal(0, 200, win->w(), TERMINAL_HEIGHT); - // Interactive control of scheme - Fl_Scheme_Choice sch(100, 120, 140, 25, "Scheme"); + // this group can be activated and deactivated: + Fl_Group *active_group = new Fl_Group(0, 0, 300, 120); - Fl_Button onoff(40,150,200,28,"Activate/Deactivate"); - onoff.callback(buttcb, (void*)&in); + // all *_Choice widgets must be aligned for easier visual comparison: - win.end(); - win.resizable(win); - win.show(argc, argv); - return Fl::run(); + Fl_Input_Choice *in = new Fl_Input_Choice(180, 40, 100, 25, "Fl_Input_Choice:"); + in->callback(input_choice_cb, (void *)in); + in->add("one"); + in->add("two"); + in->add("three"); + in->value(0); + + Fl_Choice *choice = new Fl_Choice(180, 70, 100, 25, "Fl_Choice:"); + choice->callback(choice_cb, (void *)choice); + choice->add("aaa"); + choice->add("bbb"); + choice->add("ccc"); + choice->value(1); + + active_group->end(); + + // Interactive control of scheme + Fl_Scheme_Choice *sch = new Fl_Scheme_Choice(180, 120, 100, 25, "Choose scheme:"); + sch->visible_focus(0); + + Fl_Check_Button *active = new Fl_Check_Button(50, 160, 160, 30, "Activate/deactivate"); + active->callback(active_cb, (void *)active_group); + active->value(1); + + win->end(); + win->resizable(win); + win->size_range(200, 160); + win->show(argc, argv); + Fl::run(); + delete win; + return 0; }