From b06c3e0e3f1cd7365772bccc7ea9d99c3efffc7b Mon Sep 17 00:00:00 2001 From: Byson94 Date: Tue, 21 Oct 2025 18:52:30 +0530 Subject: [PATCH] feat: add new properties to eventbox --- CHANGELOG.md | 3 ++ .../ewwii/src/widgets/widget_definitions.rs | 37 +++++++++++++++++-- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a66413..6a48aac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/). - `--with-plugin` flag for `daemon` command. - `register_function` API in ewwii_plugin_api for registering functions that rhai can call to. - `slib` rhai module for calling functions registered via `register_function`. +- `orientation` property to eventbox. +- `spacing` property to eventbox. +- `space_evenly` property to eventbox. ### Fixed diff --git a/crates/ewwii/src/widgets/widget_definitions.rs b/crates/ewwii/src/widgets/widget_definitions.rs index efa1237..e8454a4 100644 --- a/crates/ewwii/src/widgets/widget_definitions.rs +++ b/crates/ewwii/src/widgets/widget_definitions.rs @@ -379,7 +379,20 @@ pub(super) fn build_event_box( children: &Vec, widget_registry: &mut WidgetRegistry, ) -> Result { - let gtk_widget = gtk4::Box::new(gtk4::Orientation::Horizontal, 0); + let orientation = props + .get("orientation") + .and_then(|v| v.clone().try_cast::()) + .map(|s| parse_orientation(&s)) + .transpose()? + .unwrap_or(gtk4::Orientation::Horizontal); + + let spacing = + props.get("spacing").and_then(|v| v.clone().try_cast::()).unwrap_or(0) as i32; + + let space_evenly = get_bool_prop(&props, "space_evenly", Some(true))?; + + let gtk_widget = gtk4::Box::new(orientation, spacing); + gtk_widget.set_homogeneous(space_evenly); // controllers let hover_controller = EventControllerMotion::new(); @@ -620,7 +633,7 @@ pub(super) fn build_event_box( gtk_widget.add_controller(drag_source); gtk_widget.add_controller(key_controller); - let apply_props = |props: &Map, controller_data: Rc>| -> Result<()> { + let apply_props = |props: &Map, controller_data: Rc>, gtk_widget: >k4::Box| -> Result<()> { // timeout - timeout of the command. Default: "200ms" controller_data.borrow_mut().cmd_timeout = get_duration_prop(&props, "timeout", Some(Duration::from_millis(200)))?; @@ -683,14 +696,30 @@ pub(super) fn build_event_box( controller_data.borrow_mut().onkeyrelease_cmd = Some(onkeyrelease); } + if let Some(orientation_str) = + props.get("orientation").and_then(|v| v.clone().try_cast::()) + { + if let Ok(orientation) = parse_orientation(&orientation_str) { + gtk_widget.set_orientation(orientation); + } + } + + if let Some(spacing_val) = props.get("spacing").and_then(|v| v.clone().try_cast::()) { + gtk_widget.set_spacing(spacing_val as i32); + } + + if let Ok(space_evenly) = get_bool_prop(props, "space_evenly", None) { + gtk_widget.set_homogeneous(space_evenly); + } + Ok(()) }; - apply_props(&props, controller_data.clone())?; + apply_props(&props, controller_data.clone(), >k_widget)?; let gtk_widget_clone = gtk_widget.clone(); let update_fn: UpdateFn = Box::new(move |props: &Map| { - let _ = apply_props(props, controller_data.clone()); + let _ = apply_props(props, controller_data.clone(), >k_widget_clone); // now re-apply generic widget attrs if let Err(err) =