|
|
On 2020-10-08 00:30, duncan wrote:
>
> Be sure the pulldown to the right of the above descibed
> Name: prompt is set to "global", so the variable is defined as a global.
>
>
>
> This is the easiest method. I was trying to avoid having globals but if I name them right, everything works.
>
>
> You can always use fluid as a quick design tool, with globals, and then refactor
> into classes where those globals become member variables with accessors.
> It takes a bit more effort but ...
Here's a fluid file that uses subclasses for grp1 and grp4, defining the
source and destination widgets as public member variables that the tab
callback manipulates. (Can easily be modified to use accessors, but I wanted
to keep the example simple)
When you run the app, you see the two groups, 1 and 4 as tabs.
Whatever you type into the multiline input in group 1, when you click
the group 4 tab, it gets copied into the browser first.
Source is an Fl_Input widget called 'input', destination is an Fl_Multiline_Browser
called 'browser', and these are members in custom classes named MyGroup1 and MyGroup4
respectively.
The instances of the groups are globals, G_grp1 and G_grp4, so the tab callback
looks like this:
static void cb_G_tabs(Fl_Tabs*, void*) {
printf("Tab callback:\n");
Fl_Widget *w = G_tabs->value();
if ( !w ) return;
printf(" Clicked '%s'\n", w->label());
if ( strcmp(w->label(), "Group 4") == 0 ) {
printf(" Copying contents of grp1 input -> grp4 browser.\n");
G_grp4->browser->clear();
char *copy = strdup(G_grp1->input->value()); // make a copy we can change
char *s = copy;
while ( *s ) {
char *ss = strchr(s,'\n');
if ( ss ) *ss = 0;
G_grp4->browser->add(s);
if ( !ss ) break;
s = ss + 1;
}
free((void*)copy); // free the copy we made
}
}
Note there's a lot of fluid features being taken advantage of here:
> Defining subclasses of gui widgets in fluid as separate windows
> Custom code in the subclass to initialize the input and browser
> Custom code in main to force the tab group to show group1 (not group4)
> Using Fl_Tabs with dummy groups that are re-classed to use the above defined subclasses
> The callback code defined within the Fl_Tabs properties editor, "C++ -> Callback:"
Changing the group1 or group2 subclass GUI layouts affect the contents of the tab groups
when the app is running.
--
You received this message because you are subscribed to the Google Groups "fltk.general" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fltkgeneral+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fltkgeneral/58d9baba-0288-a962-9cac-148ff879de93%40seriss.com.
[ Direct Link to Message ] | |
|
| |