Add support for :hover css selectors for eventbox (#323)

This commit is contained in:
Pedro Burgos 2021-10-25 01:03:21 +02:00 committed by GitHub
parent f9153bf37d
commit 08eef05ae8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -528,7 +528,7 @@ fn build_center_box(bargs: &mut BuilderArgs) -> Result<gtk::Box> {
}
/// @widget eventbox extends container
/// @desc a container which can receive events and must contain exactly one child
/// @desc a container which can receive events and must contain exactly one child. Supports `:hover` css selectors.
fn build_gtk_event_box(bargs: &mut BuilderArgs) -> Result<gtk::EventBox> {
let gtk_widget = gtk::EventBox::new();
@ -538,6 +538,21 @@ fn build_gtk_event_box(bargs: &mut BuilderArgs) -> Result<gtk::EventBox> {
let cursor_hover_enter_handler_id: EventHandlerId = Rc::new(RefCell::new(None));
let cursor_hover_leave_handler_id: EventHandlerId = Rc::new(RefCell::new(None));
// Support :hover selector
gtk_widget.connect_enter_notify_event(|gtk_widget, evt| {
if evt.detail() != NotifyType::Inferior {
gtk_widget.clone().set_state_flags(gtk::StateFlags::PRELIGHT, false);
}
gtk::Inhibit(false)
});
gtk_widget.connect_leave_notify_event(|gtk_widget, evt| {
if evt.detail() != NotifyType::Inferior {
gtk_widget.clone().unset_state_flags(gtk::StateFlags::PRELIGHT);
}
gtk::Inhibit(false)
});
resolve_block!(bargs, gtk_widget, {
// @prop timeout - timeout of the command
// @prop onscroll - event to execute when the user scrolls with the mouse over the widget. The placeholder `{}` used in the command will be replaced with either `up` or `down`.