Add support for :active on event box (#529)

This commit is contained in:
viandox 2022-08-18 15:11:10 +02:00 committed by GitHub
parent 39eeeff7cf
commit d814edd0d5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -634,7 +634,7 @@ fn build_gtk_scrolledwindow(bargs: &mut BuilderArgs) -> Result<gtk::ScrolledWind
const WIDGET_NAME_EVENTBOX: &str = "eventbox"; const WIDGET_NAME_EVENTBOX: &str = "eventbox";
/// @widget eventbox /// @widget eventbox
/// @desc a container which can receive events and must contain exactly one child. Supports `:hover` css selectors. /// @desc a container which can receive events and must contain exactly one child. Supports `:hover` and `:active` css selectors.
fn build_gtk_event_box(bargs: &mut BuilderArgs) -> Result<gtk::EventBox> { fn build_gtk_event_box(bargs: &mut BuilderArgs) -> Result<gtk::EventBox> {
let gtk_widget = gtk::EventBox::new(); let gtk_widget = gtk::EventBox::new();
@ -653,6 +653,17 @@ fn build_gtk_event_box(bargs: &mut BuilderArgs) -> Result<gtk::EventBox> {
gtk::Inhibit(false) gtk::Inhibit(false)
}); });
// Support :active selector
gtk_widget.connect_button_press_event(|gtk_widget, _| {
gtk_widget.clone().set_state_flags(gtk::StateFlags::ACTIVE, false);
gtk::Inhibit(false)
});
gtk_widget.connect_button_release_event(|gtk_widget, _| {
gtk_widget.clone().unset_state_flags(gtk::StateFlags::ACTIVE);
gtk::Inhibit(false)
});
def_widget!(bargs, _g, gtk_widget, { def_widget!(bargs, _g, gtk_widget, {
// @prop timeout - timeout of the command // @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`. // @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`.