From 1e0a2a63418fb3b7d11e6626afc675e1dd23c0ad Mon Sep 17 00:00:00 2001 From: viandox <43315863+viandoxdev@users.noreply.github.com> Date: Wed, 13 Apr 2022 15:07:38 +0200 Subject: [PATCH] Fixes #247 implement scroll widget (#406) --- crates/eww/src/widgets/widget_definitions.rs | 21 ++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/crates/eww/src/widgets/widget_definitions.rs b/crates/eww/src/widgets/widget_definitions.rs index 8f8db3d..a7fd0cf 100644 --- a/crates/eww/src/widgets/widget_definitions.rs +++ b/crates/eww/src/widgets/widget_definitions.rs @@ -67,6 +67,7 @@ pub(super) fn widget_use_to_gtk_widget(bargs: &mut BuilderArgs) -> Result build_gtk_combo_box_text(bargs)?.upcast(), "checkbox" => build_gtk_checkbox(bargs)?.upcast(), "revealer" => build_gtk_revealer(bargs)?.upcast(), + "scroll" => build_gtk_scrolledwindow(bargs)?.upcast(), _ => { return Err(AstError::ValidationError(ValidationError::UnknownWidget( bargs.widget_use.name_span, @@ -502,6 +503,26 @@ fn build_center_box(bargs: &mut BuilderArgs) -> Result { } } +/// @widget scroll +/// @desc a container with a single child that can scroll. +fn build_gtk_scrolledwindow(bargs: &mut BuilderArgs) -> Result { + // I don't have single idea of what those two generics are supposed to be, but this works. + let gtk_widget = gtk::ScrolledWindow::new::(None, None); + + def_widget!(bargs, _g, gtk_widget, { + // @prop hscroll - scroll horizontally + // @prop vscroll - scroll vertically + prop(hscroll: as_bool = true, vscroll: as_bool = true) { + gtk_widget.set_policy( + if hscroll { gtk::PolicyType::Automatic } else { gtk::PolicyType::Never }, + if vscroll { gtk::PolicyType::Automatic } else { gtk::PolicyType::Never }, + ) + }, + }); + + Ok(gtk_widget) +} + /// @widget eventbox /// @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 {