FLTK logo

Re: [fltk.general] Button Hover (mouse-over) visual state?

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.general  ]
 
Previous Message ]New Message | Reply ]Next Message ]

Re: Button Hover (mouse-over) visual state? Mo_Al_ Sep 20, 2021  
  You would have to subclass the widget for which you need hover support:

<code>
#include <FL/Enumerations.H>
#include <FL/Fl.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Double_Window.H>

class MyButton : public Fl_Button {
  Fl_Color default_color;
  public:
    MyButton(int x, int y, int w, int h, const char* label = NULL)
        : Fl_Button(xywhlabel) {}

    int handle(int e) {
        int ret = Fl_Button::handle(e);
        switch (e) {
        case FL_ENTER:
            default_color = color();
            color(fl_lighter(default_color));
            redraw();
            return 1;
        case FL_LEAVE:
            color(default_color);
            redraw();
            return 1;
        }
        return ret;
    }
};

int main() {
    auto win = new Fl_Double_Window(400, 300);
    auto btn = new MyButton(160, 200, 80, 30, "Click");
    win->end();
    win->show();
    return Fl::run();
}
</code>

I needed to see if the code blocks work here!

On Monday, September 20, 2021 at 8:52:04 PM UTC+3 Ian MacArthur wrote:
On Mon, 20 Sep 2021, 18:43 Tom Shirley wrote:
Hello,

I am trying out FLTK for the first time, and it looks like buttons do not seem to change visually when the mouse cursor is over them. Is there a way to make buttons change visually on mouse-over/mouse-out?

Sure, you can do that, but it isn't done by default because that sort of visual feedback tends to be neither "fast" nor "light" so fltk widgets don't have that as a stock feature.

That said, some of the test folder demos do have that (not sure which ones, off the top of my head, but maybe the subwindow for one) and I'm pretty sure Greg has demos for this on his "Cheat sheet".

--
Ian
From my Fairphone FP3
 

--
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/868e4a6e-5d34-473f-a732-00fed4d8d7f1n%40googlegroups.com.
Direct Link to Message ]
 
     
Previous Message ]New Message | Reply ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.