From 8523f7fbcf145a23a52fce502089cbee0b1a6459 Mon Sep 17 00:00:00 2001 From: Kayshen-X Date: Sun, 10 May 2026 12:20:44 +0800 Subject: [PATCH] refactor(shell): single canonical MIN_RAIL_WIDTH in shell-core MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Codex Step 3 R1 BLOCK: `MIN_RAIL_WIDTH: f32 = 80.0` was defined twice — once in `crates/openpencil-shell-web/src/widget_host.rs` and once in `crates/openpencil-shell-native/src/widget_host.rs`. Each had a comment claiming "mirrors the other"; nothing enforced agreement. A future drift on one side would silently break cross-platform layout parity. Move to a single canonical `pub const MIN_RAIL_WIDTH: f32 = 80.0` in `crates/openpencil-shell-core/src/widgets/mod.rs`. Both hosts import it via the existing `widgets::*` use list. Verification: - `cargo build -p openpencil-shell-native --example inspector_window` — green - `cargo build -p openpencil-shell-web --target wasm32-unknown-unknown --features skia --release` — green - `cargo test -p openpencil-shell-core --lib` — 39 tests passing - grep confirms one definition + two imports + 4 use sites --- crates/openpencil-shell-core/src/widgets/mod.rs | 9 +++++++++ crates/openpencil-shell-native/src/widget_host.rs | 8 +------- crates/openpencil-shell-web/src/widget_host.rs | 9 +-------- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/crates/openpencil-shell-core/src/widgets/mod.rs b/crates/openpencil-shell-core/src/widgets/mod.rs index 3205bc639..29e9d6dd4 100644 --- a/crates/openpencil-shell-core/src/widgets/mod.rs +++ b/crates/openpencil-shell-core/src/widgets/mod.rs @@ -17,6 +17,15 @@ use crate::{Point2D, Rect, RenderBackend}; +/// Minimum width (in CSS / physical px) below which the editor-UI +/// host paints the Toolbar only and skips the LayerPanel / +/// CanvasViewport / PropertyPanel rails. Single canonical +/// definition consumed by both `openpencil-shell-web::WidgetHost` +/// and `openpencil-shell-native::WidgetHostNative` so they stay in +/// lock-step (codex Step 3 R1 BLOCK fix — was duplicated as +/// `const MIN_RAIL_WIDTH` in each host). +pub const MIN_RAIL_WIDTH: f32 = 80.0; + // Phase B primitives. pub mod dropdown; pub mod prop_row; diff --git a/crates/openpencil-shell-native/src/widget_host.rs b/crates/openpencil-shell-native/src/widget_host.rs index 4ab6378b0..3a59ce032 100644 --- a/crates/openpencil-shell-native/src/widget_host.rs +++ b/crates/openpencil-shell-native/src/widget_host.rs @@ -52,16 +52,10 @@ use crate::backend::NativeBackend; use openpencil_shell_core::document::Document; use openpencil_shell_core::widgets::{ - CanvasViewport, LayerPanel, LayoutCx, PaintCx, PropertyPanel, Toolbar, Widget, + CanvasViewport, LayerPanel, LayoutCx, PaintCx, PropertyPanel, Toolbar, Widget, MIN_RAIL_WIDTH, }; use openpencil_shell_core::{Color, Point2D, Rect, RenderBackend, TextLayout}; -/// Below this viewport width (in physical px) we paint the Toolbar -/// only and skip both rails. Mirrors shell-web's `MIN_RAIL_WIDTH` -/// constant so cross-platform behaviour at narrow viewports stays -/// in sync. Codex Step 2 R1 CONCERN-3. -const MIN_RAIL_WIDTH: f32 = 80.0; - /// Frame-scoped `RenderBackend` adapter over `NativeBackend` + /// `&Canvas`. Lifetime-bound to the `SharedSkiaContext::with_frame` /// closure body so widget code never sees the canvas borrow directly. diff --git a/crates/openpencil-shell-web/src/widget_host.rs b/crates/openpencil-shell-web/src/widget_host.rs index ae0bdd4be..681b331f8 100644 --- a/crates/openpencil-shell-web/src/widget_host.rs +++ b/crates/openpencil-shell-web/src/widget_host.rs @@ -24,17 +24,10 @@ use crate::backend::WebBackend; use openpencil_shell_core::document::Document; use openpencil_shell_core::widgets::{ - CanvasViewport, LayerPanel, LayoutCx, PaintCx, PropertyPanel, Toolbar, Widget, + CanvasViewport, LayerPanel, LayoutCx, PaintCx, PropertyPanel, Toolbar, Widget, MIN_RAIL_WIDTH, }; use openpencil_shell_core::{Point2D, Rect, RenderBackend}; -/// Below this viewport width (in CSS px) we paint the Toolbar -/// only and skip both rails — there's not enough horizontal -/// space for a usable LayerPanel + PropertyPanel split. Codex -/// Step 2 R1 CONCERN-3: clamp `rail_w` to non-negative AND skip -/// when too small to be useful. -const MIN_RAIL_WIDTH: f32 = 80.0; - /// The Step 3 editor-UI host. Owns the document model + toolbar /// tool selection; per-frame builds LayerPanel / PropertyPanel / /// CanvasViewport from the document. Aux Dropdown / TextInput