Mikko L wrote:
> Hope this helps somebody.
Yes, thanks -- I see now.
So it looks like I missed the part about assigning
Button::default_style = &G_my_style;
..in main(), and using NamedStyle instead of Style.
Referring to your changes, I was able to slim the code
a bit more (to keep the code as small as possible) which
prevents the need for deriving a custom class.
Here's what I ended up with; comments welcome:
------------------------- snip
#include <fltk/run.h>
#include <fltk/Window.h>
#include <fltk/Button.h>
#include <fltk/Choice.h>
#include <fltk/Style.h>
#include <stdio.h>
#include <string.h>
using namespace fltk;
//
// FLTK 2.x example showing how to use NamedStyle to change widget defaults
//
// Globals for separate window + button styles
NamedStyle G_window_style(*Window::default_style);
NamedStyle G_button_style(*Button::default_style);
void Choice_CB(fltk::Widget *w) {
Choice *c = (Choice*)w;
const char *choice = c->get_item()->label(); // "SmallFont",
"BigFont", etc
printf("You picked: '%s'\n", choice);
if ( strcmp(choice, "SmallFont" ) == 0 ) { G_button_style.labelsize(12);
}
if ( strcmp(choice, "BigFont" ) == 0 ) { G_button_style.labelsize(24);
}
if ( strcmp(choice, "GrayButton" ) == 0 ) {
G_button_style.buttoncolor(GRAY80); }
if ( strcmp(choice, "RedButton" ) == 0 ) {
G_button_style.buttoncolor(RED); }
if ( strcmp(choice, "GrayWindow" ) == 0 ) { G_window_style.color(GRAY80);
}
if ( strcmp(choice, "RedWindow" ) == 0 ) { G_window_style.color(RED); }
w->window()->redraw(); // tell window to
redraw itself..
}
int main(int argc, char** argv) {
// Set our styles as default
Window::default_style = &G_window_style;
Button::default_style = &G_button_style;
// Now do normal widget construction..
Window w(300,200);
w.begin();
Button b(50,10,200,25,"Some Button");
Choice c(50,40,200,25,"Style");
c.add("SmallFont");
c.add("BigFont");
c.add("RedButton");
c.add("GrayButton");
c.add("GrayWindow");
c.add("RedWindow");
c.callback(Choice_CB);
w.end();
w.show(argc,argv);
return(run());
}
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk