如何通过按 Fl_Button 更改 Fl_Window 的背景颜色
how to change the background color of Fl_Window by pressing Fl_Button
谁能告诉我,如何通过按 Fl_Button 来更改 Fl_Window 的背景颜色。我正在尝试这样做,但它不起作用。
void new_color(Fl_Widget* w, void*){
Fl_Button* b = (Fl_Button*)w;
b->parent()->color(FL_RED);
}
int main()
}
Fl_Window* win = new Fl_Window(...);
win->color(FL_WHITE);
win->begin();
Fl_Button* but = new Fl_Button(...);
but->callback(new_color);
win->end();
...
}
谢谢!!!
正如 cup 所指出的那样,重绘可以解决问题:
#include <FL/Fl.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Window.H>
int main()
{
Fl_Window win(200, 200, "Color changer");
win.color(FL_WHITE);
Fl_Button but(50, 80, 100, 20, "Click Me!");
but.callback([](Fl_Widget* w, void*) {
Fl_Widget* p = w->parent();
p->color(p->color() == FL_WHITE ? FL_RED : FL_WHITE);
p->redraw();
});
win.show();
return Fl::run();
}
谁能告诉我,如何通过按 Fl_Button 来更改 Fl_Window 的背景颜色。我正在尝试这样做,但它不起作用。
void new_color(Fl_Widget* w, void*){
Fl_Button* b = (Fl_Button*)w;
b->parent()->color(FL_RED);
}
int main()
}
Fl_Window* win = new Fl_Window(...);
win->color(FL_WHITE);
win->begin();
Fl_Button* but = new Fl_Button(...);
but->callback(new_color);
win->end();
...
}
谢谢!!!
正如 cup 所指出的那样,重绘可以解决问题:
#include <FL/Fl.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Window.H>
int main()
{
Fl_Window win(200, 200, "Color changer");
win.color(FL_WHITE);
Fl_Button but(50, 80, 100, 20, "Click Me!");
but.callback([](Fl_Widget* w, void*) {
Fl_Widget* p = w->parent();
p->color(p->color() == FL_WHITE ? FL_RED : FL_WHITE);
p->redraw();
});
win.show();
return Fl::run();
}