diff options
| author | Matthias Melcher <github@matthiasm.com> | 2025-03-29 22:40:13 +0100 |
|---|---|---|
| committer | Matthias Melcher <github@matthiasm.com> | 2025-03-29 22:40:18 +0100 |
| commit | b7189192e2e31ce5ca1f2eaac2a303f9b8216ded (patch) | |
| tree | 06d38b355a35fa1bcd11a215d467130e2d9aa0a7 /test | |
| parent | cb86a37676e26a8de209a371132d8154986b457a (diff) | |
Adds a new event FL_TOOLTIP_EVENT...
... and Fl_Tootip::override_text() to allow users to dynamically
generate tooltips.
Diffstat (limited to 'test')
| -rw-r--r-- | test/color_chooser.cxx | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/test/color_chooser.cxx b/test/color_chooser.cxx index 61fbc4caf..a9a7a5ca1 100644 --- a/test/color_chooser.cxx +++ b/test/color_chooser.cxx @@ -21,6 +21,7 @@ #include <FL/fl_show_colormap.H> #include <FL/Fl_Color_Chooser.H> #include <FL/Fl_Image.H> +#include <FL/Fl_Tooltip.H> #include <FL/platform.H> #include <FL/fl_draw.H> @@ -84,6 +85,22 @@ void cb2(Fl_Widget *, void *v) { bx->parent()->redraw(); } +class Image_Box: public Fl_Box { +public: + Image_Box(int x, int y, int w, int h, const char *label = nullptr) + : Fl_Box(x, y, w, h, label) { } + int handle(int event) { + if (event == FL_TOOLTIP_EVENT) { + const char *color_name_lut[] = { "blue", "green", "black", "red" }; + int quadrant = (Fl::event_x() < x()+w()/2) + 2*(Fl::event_y() < y()+h()/2); + char buf[80]; + ::snprintf(buf, 79, "Color %s at x=%d, y=%d", color_name_lut[quadrant], Fl::event_x(), Fl::event_y()); + return Fl_Tooltip::override_text(buf); + } + return Fl_Box::handle(event); + } +}; + int main(int argc, char ** argv) { Fl::set_color(fullcolor_cell,145,159,170); Fl_Window window(400,400); @@ -98,7 +115,8 @@ int main(int argc, char ** argv) { b1.callback(cb1,&box); Fl_Button b2(120,120,180,30,"fl_color_chooser()"); b2.callback(cb2,&box); - Fl_Box image_box(160,190,width,height,0); + Image_Box image_box(160,190,width,height,0); + image_box.tooltip("Image Box"); make_image(); (new Fl_RGB_Image(image, width, height))->label(&image_box); Fl_Box b(160,310,120,30,"Example of fl_draw_image()"); |
