Fixes #247 implement scroll widget (#406)

This commit is contained in:
viandox 2022-04-13 15:07:38 +02:00 committed by GitHub
parent b100704bc7
commit 1e0a2a6341
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -67,6 +67,7 @@ pub(super) fn widget_use_to_gtk_widget(bargs: &mut BuilderArgs) -> Result<gtk::W
"combo-box-text" => 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<gtk::Box> {
}
}
/// @widget scroll
/// @desc a container with a single child that can scroll.
fn build_gtk_scrolledwindow(bargs: &mut BuilderArgs) -> Result<gtk::ScrolledWindow> {
// I don't have single idea of what those two generics are supposed to be, but this works.
let gtk_widget = gtk::ScrolledWindow::new::<gtk::Adjustment, gtk::Adjustment>(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<gtk::EventBox> {