-
Notifications
You must be signed in to change notification settings - Fork 568
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
[feature request] A widget that sets the cursor on hover. #1478
Comments
I'll wait for people to comment on whether it's a good idea before I say people should have a go at implementing it. |
Here's a controller I made to do something like this. It's probably better to use a /// Button controller.
///
/// Responsible for setting the cursor and calling a contained on_click function on click.
struct BtnController<T> {
cursor: Cursor,
on_click: Box<dyn Fn(&mut EventCtx, &mut T, &Env)>,
}
impl<T> BtnController<T> {
fn new(cursor: Cursor, on_click: impl Fn(&mut EventCtx, &mut T, &Env) + 'static) -> Self {
BtnController {
cursor,
on_click: Box::new(on_click),
}
}
}
impl<T, W: Widget<T>> Controller<T, W> for BtnController<T> {
fn event(&mut self, child: &mut W, ctx: &mut EventCtx, event: &Event, data: &mut T, env: &Env) {
match event {
Event::MouseMove(_) => ctx.set_cursor(&self.cursor),
Event::MouseDown(MouseEvent { buttons, .. }) if buttons.has_left() => {
ctx.set_active(true)
}
Event::MouseUp(MouseEvent { buttons, .. }) if !buttons.has_left() => {
if ctx.is_active() {
(*self.on_click)(ctx, data, env);
ctx.set_active(false);
}
}
_ => (),
}
}
} a |
Do the changes in #1433 help here? I think they should give more-or-less the behavior you want without adding wrapper widget... |
@jneem say I have a widget like |
Oh, right, I was thinking of the case where you already have a custom widget. What if we added
|
Hmm yeah that would work as well. So this is a custom controller that runs the callback on |
That's what I was thinking, yes. If there are other things that are worth having callbacks for, they could be included as well, of course. |
Cool, then if we wanted then we could add a @cmyr or @raphlinus what do you think about a |
I think this makes a lot of sense! (I think that |
Ok sounds like just adding Edit: probably makes sense to create a new issue. I want it to be a "good first issue" kinda issue, so someone new could implement it if they so chose. |
Currently if you want to set the cursor for a widget you need to intercept
event
s. This means using a customController
, which can be fiddly and error-prone.This request involves adding a new widget (probably called
Cursor
) todruid::widget
that sets the cursor whenever it is hovered, and acursor
method toWidgetExt
that wraps the widget in aCursor
.The text was updated successfully, but these errors were encountered: