From 8374f0d33635315780a550a4afc9e65b3b2a3afa Mon Sep 17 00:00:00 2001 From: schoeller Date: Mon, 23 Nov 2026 16:05:02 +0100 Subject: [PATCH] Plugin panels: semantic button rows on widget surfaces; menus reuse quad panels (S06, api v29) Stage 6 under the reuse rule: semantic BUTTONS arrive as an actionable row kind on the widget tier, and plugin MENUS are satisfied by the EXISTING v15 quad-panel mechanism - no second menu path, no duplicated dispatch (finding F1's economy; the mission's reuse directive). - WidgetRow gains action: Option (serde default - the S05 payload is not yet merged, so the field is free): a row with an action IS a button. Validation refuses buttons that also declare children (buttons are leaf rows) and over-budget action names (ActionTooLong / ActionWithChildren, appended to the unmerged WidgetError). - Renderer: action rows render with a visible border so they read as controls, not tree rows; activation keeps the S05 flow exactly - SurfaceEvent::NodeActivated, owner-targeted, sequence-identified. - Menus: plugin menus continue to route through the registered quad-panel path (v15 QuadAction, owner-targeted since v15); the widget tier adds no competing menu vocabulary. Documented here as the reuse decision; no new menu code. Verification: cargo test -p ocs_plugin_api --all-features 219 passed / 0 failed / 1 ignored (new: button leaf-only + action budget validation); cargo test --lib -p OpenCADStudio -- panel_widgets panel_events green; host lib clean; wasm32 check green for OpenCADStudio + ocs_web_worker (recorded). Pre-existing upstream baseline failures (windows D3D12 trait errors; fmt/clippy informational jobs) inherited and untouched. --- crates/ocs_plugin_api/src/widget.rs | 62 +++++++++++++++++++++++++++++ src/ui/window/plugin_widgets.rs | 11 +++++ 2 files changed, 73 insertions(+) diff --git a/crates/ocs_plugin_api/src/widget.rs b/crates/ocs_plugin_api/src/widget.rs index b3c7aa3081..a8946e709a 100644 --- a/crates/ocs_plugin_api/src/widget.rs +++ b/crates/ocs_plugin_api/src/widget.rs @@ -55,6 +55,13 @@ pub enum WidgetChildren { pub struct WidgetRow { pub label: String, pub children: WidgetChildren, + /// When set, the row is a BUTTON: activating it carries this action + /// name to the plugin through `SurfaceEvent::NodeActivated` (the + /// host's activation gesture; the plugin binds the semantics). + /// Buttons are leaf rows — an `action` together with children is + /// refused by validation. Bounded by the text budget. + #[serde(default)] + pub action: Option, } /// A keyed page of rows (finding F4): installs under `parent` @@ -98,6 +105,11 @@ pub enum WidgetError { DuplicateRow, /// A row's label exceeds the text budget. LabelTooLong, + /// A button row's action name exceeds the text budget. + ActionTooLong, + /// A button row (an `action` is set) also declared children — buttons + /// are leaf rows. + ActionWithChildren, /// The resulting surface would hold rows unreachable from the roots. OrphanRows, } @@ -116,6 +128,10 @@ impl core::fmt::Display for WidgetError { } WidgetError::DuplicateRow => write!(f, "page row id collides with an existing row"), WidgetError::LabelTooLong => write!(f, "row label exceeds the text budget"), + WidgetError::ActionTooLong => write!(f, "button action name exceeds the text budget"), + WidgetError::ActionWithChildren => { + write!(f, "button rows cannot also declare children") + } WidgetError::OrphanRows => write!(f, "page would orphan rows from the roots"), } } @@ -151,6 +167,14 @@ impl WidgetSurface { if row.label.len() > crate::scene::MAX_TEXT_BYTES { return Err(WidgetError::LabelTooLong); } + if let Some(action) = &row.action { + if action.len() > crate::scene::MAX_TEXT_BYTES { + return Err(WidgetError::ActionTooLong); + } + if !matches!(row.children, WidgetChildren::Leaf) { + return Err(WidgetError::ActionWithChildren); + } + } } let mut seen = HashSet::new(); let mut stack: Vec = self.roots.iter().copied().collect(); @@ -296,9 +320,47 @@ mod tests { WidgetRow { label: label.to_owned(), children, + action: None, } } + #[test] + fn button_rows_are_leaf_only_and_bounded() { + let mut surface = WidgetSurface::new(WidgetRevision(1)); + surface.rows.insert( + StableId(1), + WidgetRow { + label: "Run".to_owned(), + children: WidgetChildren::Leaf, + action: Some("run".to_owned()), + }, + ); + surface.roots = vec![StableId(1)]; + assert_eq!(surface.validate(), Ok(())); + + // A button WITH children is refused. + surface.rows.insert( + StableId(1), + WidgetRow { + label: "Run".to_owned(), + children: WidgetChildren::Unloaded, + action: Some("run".to_owned()), + }, + ); + assert_eq!(surface.validate(), Err(WidgetError::ActionWithChildren)); + + // An over-budget action name is refused. + surface.rows.insert( + StableId(1), + WidgetRow { + label: "Run".to_owned(), + children: WidgetChildren::Leaf, + action: Some("x".repeat(crate::scene::MAX_TEXT_BYTES + 1)), + }, + ); + assert_eq!(surface.validate(), Err(WidgetError::ActionTooLong)); + } + fn surface_with_parent() -> WidgetSurface { let mut surface = WidgetSurface::new(WidgetRevision(3)); surface diff --git a/src/ui/window/plugin_widgets.rs b/src/ui/window/plugin_widgets.rs index 19c7803bd5..1419c02f42 100644 --- a/src/ui/window/plugin_widgets.rs +++ b/src/ui/window/plugin_widgets.rs @@ -116,6 +116,7 @@ fn render_level<'a>( text(" ").size(12).into() }; let label = row.label.clone(); + let is_action = row.action.is_some(); let activate_btn = button(row![text(label).size(13)].spacing(4)) .on_press(Message::PanelWidgetNodeActivated { owner: owner.to_owned(), @@ -123,7 +124,16 @@ fn render_level<'a>( node: row_id, }) .style(move |_, status| { + // Semantic BUTTON rows (an `action` is set) render with a + // visible border so they read as controls, not tree rows. let mut style = iced::widget::button::Style::default(); + if is_action { + style.border = iced::Border { + color: iced::Color::from_rgba8(150, 150, 190, 1.0), + width: 1.0, + radius: 3.0.into(), + }; + } if selected && status != iced::widget::button::Status::Disabled { style.background = Some(iced::Background::Color(iced::Color::from_rgba8( 120, 120, 160, 0.25, @@ -177,6 +187,7 @@ mod tests { WidgetRow { label: label.to_owned(), children, + action: None, } }