-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
proposal: Event Container #12
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense to me!
I would call it MouseListener
instead of Event Container or EventMessages
, but besides that I think this would be a nice addition to iced
.
Almost finished with implementing this. Working on an example to use with it. |
9cb5795
to
ca157d8
Compare
ca157d8
to
8f99f8b
Compare
I just started using Maybe this is outside the scope of this RFC, but I was wondering: For simpler use-cases, would it be desirable to also do something similar to the let icon_button = mouse_area(|mouse_state| {
let icon_style = if mouse_state.is_pressed {
pressed_icon_style
} else if mouse_state.is_hovered {
hovered_icon_stye
} else {
normal_icon_style
};
button(svg(icon_handle).style(icon_style))
}); I've put some motivations, prior art and the drawbacks of this suggestion in the details below: MotivationI would like to draw the view differently depending on the mouse state of something. For example:
While this is doable with the current Prior art
/* (css pseudocode - might not be entirely accurate) */
button svg {
color: black;
}
button:hover svg {
color: grey;
}
Item {
MouseArea {
id: theMouseArea
hoverEnabled: true
Icon {
// We can access the hover state as a child of the MouseArea
color: theMouseArea.containsMouse ? 'green' : 'blue'
}
}
Icon {
// We can access the hover state even outside the MouseArea, as long
// as we can refer to the MouseArea via its id
color: theMouseArea.containsMouse ? 'green' : 'blue'
}
}
// Haven't tested this so it might not be correct, but it's based on the docs:
let response = ui.allocate_response(egui::vec2(100.0, 200.0), egui::Sense::hover());
let color = if response.hovered() {
egui::Color32::WHITE
} else {
egui::Color32::GRAY
}
ui.painter().rect_stroke(response.rect, 0.0, (1.0, color)); Drawbacks
Alternatives
Example use cases for getting the currently pressed keys:
|
@ErnWong You can find the implementation at iced-rs/iced#1594 to experiment with |
content: Element<'a, Message, Renderer>, | ||
|
||
/// Sets the message to emit on a left mouse button press. | ||
on_press: Option<Message>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bikeshedding: I wonder if the name on_press
would be confusing as it seems to have a different meaning to a Button
's on_press
, since the Button
's on_press
seems to be about the mouse_or_touch_down + mouse_or_touch_up
sequence whereas MouseListener
's is just about mouse_down
. Do you think this consistency is important enough that we should rename either MouseListener
's on_press
or the Button
's on_press
?
I am curious: given that iced-rs/iced#1594 is now merged, which references this PR, is this RFC now considered accepted and should be merged? or should it be tweaked? or is it still not fully ready or something because of lacking mouse-enter/-leave events implementation? it looks kinda weird and confusing to me, that an implementation was merged, but its RFC is open 🤪🤔 or am I misunderstanding something? |
I it also in scope for this widget to provide a custom |
Rendered