diff --git a/crates/app/src/ui/ribbon.rs b/crates/app/src/ui/ribbon.rs index 9d3d0809..f718d965 100644 --- a/crates/app/src/ui/ribbon.rs +++ b/crates/app/src/ui/ribbon.rs @@ -14,6 +14,7 @@ use plotium_core::state::{ArrangeGridDraft, PlotiumApp, ToolGroup, WorkflowTab}; use super::clipboard_table::ClipboardTablePaste; use super::commands::{self, CommandDescriptor, CommandId}; +use super::ribbon_chrome as chrome_layout; use buttons::{collapsed_tile, overflow_item, ribbon_button}; use layout::{CAPTION_BAND, GroupScale, STACK_GAP, TILE_HEIGHT, TabPlan}; @@ -62,11 +63,12 @@ fn task_row( chrome: super::RibbonChrome, ) { let Some(traffic_lights) = chrome.macos_traffic_lights else { - // Windows and Linux: the separate custom title bar owns window chrome - // and dragging, so the row only compacts its controls to fit. + if cfg!(target_os = "windows") && render_narrow_windows_task_row(app, clipboard, ui) { + return; + } ui.horizontal(|ui| { let compact = - super::ribbon_chrome::controls_need_compacting(app, ui, 0.0, ui.available_width()); + chrome_layout::controls_need_compacting(app, ui, 0.0, ui.available_width()); render_task_row_contents(app, clipboard, ui, compact, None); }); return; @@ -98,22 +100,46 @@ fn task_row( ); let leading = traffic_lights.x + 4.0; ui.add_space(leading); - let compact_controls = - super::ribbon_chrome::controls_need_compacting(app, &ui, leading, row_rect.width()); - let inline_title_width = super::ribbon_chrome::available_title_width( - app, - &ui, - leading, - row_rect.width(), - compact_controls, - ); - render_task_row_contents( - app, - clipboard, - &mut ui, - compact_controls, - inline_title_width, - ); + let compact = chrome_layout::controls_need_compacting(app, &ui, leading, row_rect.width()); + let title_width = + chrome_layout::available_title_width(app, &ui, leading, row_rect.width(), compact); + render_task_row_contents(app, clipboard, &mut ui, compact, title_width); +} + +fn render_narrow_windows_task_row( + app: &mut PlotiumApp, + clipboard: &mut ClipboardTablePaste, + ui: &mut Ui, +) -> bool { + let width = ui.available_width(); + let tabs = chrome_layout::task_tabs_width(ui); + let controls = chrome_layout::windows_compact_controls_width(app, ui); + // The native minimum size does not track later changes to egui's zoom. + if tabs + controls + chrome_layout::TASK_TAB_SPACING <= width { + return false; + } + + task_strip(ui, "ribbon_task_tabs", tabs, |ui| { + ui.horizontal(|ui| render_task_tabs(app, ui)); + }); + task_strip(ui, "ribbon_split_controls", controls, |ui| { + ui.horizontal(move |ui| render_task_controls(app, clipboard, ui, true)); + }); + true +} + +fn task_strip(ui: &mut Ui, id: &str, needed: f32, contents: impl FnOnce(&mut Ui)) { + if needed > ui.available_width() { + egui::ScrollArea::horizontal() + .id_salt(id) + .auto_shrink([false, true]) + .show(ui, |ui| { + ui.set_min_width(needed); + contents(ui); + }); + } else { + contents(ui); + } } fn render_task_row_contents( @@ -121,8 +147,14 @@ fn render_task_row_contents( clipboard: &mut ClipboardTablePaste, ui: &mut Ui, compact_controls: bool, - inline_title_width: Option, + title_width: Option, ) { + render_task_tabs(app, ui); + render_inline_title(app, ui, title_width); + render_task_controls(app, clipboard, ui, compact_controls); +} + +fn render_task_tabs(app: &mut PlotiumApp, ui: &mut Ui) { for (tab, response) in task_tab_buttons(ui, app.session.ui.ribbon_tab) { if response.clicked() { select_workflow_tab(app, tab); @@ -130,7 +162,9 @@ fn render_task_row_contents( app.session.ui.ribbon_expanded = true; } } +} +fn render_inline_title(app: &PlotiumApp, ui: &mut Ui, inline_title_width: Option) { if let Some(width) = inline_title_width { let title = super::ribbon_chrome::inline_project_title(app); ui.separator(); @@ -144,7 +178,14 @@ fn render_task_row_contents( ); titlebar_interaction(&title); } +} +fn render_task_controls( + app: &mut PlotiumApp, + clipboard: &mut ClipboardTablePaste, + ui: &mut Ui, + compact_controls: bool, +) { ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| { // The controls keep their own spacing instead of inheriting the tab // strip's gap. diff --git a/crates/app/src/ui/ribbon_chrome.rs b/crates/app/src/ui/ribbon_chrome.rs index 1ff218ef..c156672a 100644 --- a/crates/app/src/ui/ribbon_chrome.rs +++ b/crates/app/src/ui/ribbon_chrome.rs @@ -86,7 +86,7 @@ pub(super) fn available_title_width( (remaining >= INLINE_TITLE_MIN_WIDTH).then(|| remaining.min(INLINE_TITLE_MAX_WIDTH)) } -fn task_tabs_width(ui: &Ui) -> f32 { +pub(super) fn task_tabs_width(ui: &Ui) -> f32 { WorkflowTab::ALL .iter() .map(|tab| { @@ -101,6 +101,17 @@ fn task_tabs_width(ui: &Ui) -> f32 { } fn controls_width(app: &PlotiumApp, ui: &Ui, compact: bool) -> f32 { + let (search, update) = control_labels(app, compact); + [search, update] + .into_iter() + .filter(|text| !text.is_empty()) + .map(|text| text_width(ui, text, TextStyle::Button)) + .sum::() + + fixed_controls_width() + + 8.0 * CONTROL_SPACING +} + +fn control_labels(app: &PlotiumApp, compact: bool) -> (String, String) { use plotium_core::update::UpdateStatus; let search = if compact { @@ -121,19 +132,37 @@ fn controls_width(app: &PlotiumApp, ui: &Ui, compact: bool) -> f32 { } _ => String::new(), }; - let spacing = CONTROL_SPACING; - [search, update] - .into_iter() - .filter(|text| !text.is_empty()) - .map(|text| text_width(ui, text, TextStyle::Button)) - .sum::() - // The two sidebar toggles, Ribbon toggle, separator, and - // their share of the item spacing. - + 3.0 * SIDEBAR_TOGGLE_WIDTH - + 6.0 - + 5.0 * spacing - // The follow, history, and AI connection buttons and their gaps. - + 3.0 * (SIDEBAR_TOGGLE_WIDTH + CONTROL_SPACING) + (search, update) +} + +pub(super) fn windows_compact_controls_width(app: &PlotiumApp, ui: &Ui) -> f32 { + let (search, update) = control_labels(app, true); + // Six fixed buttons, search, and the separator have seven internal gaps. + let update_width = match app.session.updates.status() { + plotium_core::update::UpdateStatus::Downloading { .. } => { + WidgetText::from(egui::RichText::new(update).small()) + .into_galley( + ui, + Some(TextWrapMode::Extend), + f32::INFINITY, + TextStyle::Small, + ) + .size() + .x + + CONTROL_SPACING + } + _ if !update.is_empty() => text_width(ui, update, TextStyle::Button) + CONTROL_SPACING, + _ => 0.0, + }; + fixed_controls_width() + + text_width(ui, search, TextStyle::Button) + + 7.0 * CONTROL_SPACING + + update_width +} + +fn fixed_controls_width() -> f32 { + // Sidebar toggles, Ribbon toggle, separator, follow, history, and AI. + 6.0 * SIDEBAR_TOGGLE_WIDTH + 6.0 } /// Fixed width of one sidebar layout toggle; shared with the width estimate diff --git a/crates/app/src/ui/ribbon_titlebar_tests.rs b/crates/app/src/ui/ribbon_titlebar_tests.rs index 9bb62993..c281ddec 100644 --- a/crates/app/src/ui/ribbon_titlebar_tests.rs +++ b/crates/app/src/ui/ribbon_titlebar_tests.rs @@ -6,6 +6,8 @@ struct Titlebar { app: PlotiumApp, clipboard: ClipboardTablePaste, time: f64, + width: f32, + traffic_lights: Option, maximized: bool, fullscreen: bool, } @@ -19,6 +21,8 @@ impl Titlebar { app, clipboard: ClipboardTablePaste::default(), time: 0.0, + width: 1500.0, + traffic_lights: Some(vec2(76.0, 28.0)), maximized: false, fullscreen: false, } @@ -27,7 +31,7 @@ impl Titlebar { fn frame(&mut self, events: Vec) -> FullOutput { self.time += 0.05; let mut input = RawInput { - screen_rect: Some(Rect::from_min_size(Pos2::ZERO, vec2(1500.0, 300.0))), + screen_rect: Some(Rect::from_min_size(Pos2::ZERO, vec2(self.width, 300.0))), time: Some(self.time), events, ..Default::default() @@ -35,13 +39,13 @@ impl Titlebar { let viewport = input.viewports.get_mut(&ViewportId::ROOT).unwrap(); viewport.maximized = Some(self.maximized); viewport.fullscreen = Some(self.fullscreen); + let chrome = self + .traffic_lights + .map_or_else(super::super::RibbonChrome::default, |size| { + super::super::RibbonChrome::macos(size, self.fullscreen) + }); self.ctx.run_ui(input, |ui| { - task_row( - &mut self.app, - &mut self.clipboard, - ui, - super::super::RibbonChrome::macos(vec2(76.0, 28.0), self.fullscreen), - ); + task_row(&mut self.app, &mut self.clipboard, ui, chrome); }) } @@ -151,3 +155,63 @@ fn titlebar_double_click_does_not_change_fullscreen_window() { let pos = bar.text_center("* Untitled"); assert!(bar.double_click(pos, PointerButton::Primary).is_empty()); } + +#[test] +#[cfg(target_os = "windows")] +fn narrow_ribbon_moves_controls_below_clickable_tabs() { + let mut bar = Titlebar::new(); + bar.traffic_lights = None; + bar.width = 480.0; + let view = bar.text_center("View"); + let search = bar.text_center(icon::MAGNIFYING_GLASS); + assert!(search.y > view.y + 10.0); + assert!(view.x < bar.width && search.x < bar.width); + bar.press(view, PointerButton::Primary, true); + bar.press(view, PointerButton::Primary, false); + assert_eq!(bar.app.session.ui.ribbon_tab, WorkflowTab::View); + + bar.width = 1500.0; + let view = bar.text_center("View"); + let search = bar.text_center(&format!("{} Search commands", icon::MAGNIFYING_GLASS)); + assert!((search.y - view.y).abs() < 2.0); + assert!(search.x > view.x); +} + +#[test] +#[cfg(target_os = "windows")] +fn ribbon_wraps_close_to_the_last_tab() { + let mut bar = Titlebar::new(); + bar.traffic_lights = None; + bar.app.session.ui.ribbon_tab = WorkflowTab::View; + + // Start wide, then find the first split during a resize. Measure the + // actual gap in the last single row, with View's highlight showing its edge. + let mut last_gap = None; + for width in (480..=760).rev().step_by(2) { + bar.width = width as f32; + let output = bar.frame(vec![]); + let pill = output.shapes.iter().find_map(|shape| match &shape.shape { + egui::Shape::Vec(shapes) => shapes.iter().find_map(|shape| match shape { + egui::Shape::Rect(rect) => Some(rect.rect), + _ => None, + }), + _ => None, + }); + let mut toggles = output.shapes.iter().filter_map(|shape| match &shape.shape { + egui::Shape::Rect(rect) if rect.rect.size() == vec2(16.0, 12.0) => Some(rect.rect), + _ => None, + }); + let (Some(pill), Some(left_toggle)) = (pill, toggles.next_back()) else { + continue; + }; + if left_toggle.center().y > pill.bottom() { + let gap = last_gap.expect("a one-row layout before the split"); + assert!((0.0..=16.0).contains(&gap), "gap before wrapping: {gap}"); + return; + } + // The sidebar glyph is centered in a wider clickable button. + let glyph_inset = (chrome_layout::SIDEBAR_TOGGLE_WIDTH - left_toggle.width()) / 2.0; + last_gap = Some(left_toggle.left() - glyph_inset - pill.right()); + } + panic!("Ribbon did not wrap in the tested width range"); +} diff --git a/docs/src/content/docs/reference/ribbon.md b/docs/src/content/docs/reference/ribbon.md index fd2e66fa..0493caa9 100644 --- a/docs/src/content/docs/reference/ribbon.md +++ b/docs/src/content/docs/reference/ribbon.md @@ -48,8 +48,8 @@ The Ribbon measures the active tab's content against the window: lower priority, and every group keeps its position. - Only when every group is already a single button and the row still does not fit do whole groups move into the **More** menu. -- The command area never hides by itself. **Collapse ribbon** (the window icon with a top band at - the right end of the task row) puts it away and brings it back. +- The command area never hides by itself. **Collapse ribbon** (the window icon with a top band on + the right side of the Ribbon) puts it away and brings it back. Buttons that start a computation, such as **Run Peak Fit**, use the filled accent style — the same as a task card's Run button. diff --git a/docs/src/content/docs/zh-cn/reference/ribbon.md b/docs/src/content/docs/zh-cn/reference/ribbon.md index 2bedb9d6..f16eea82 100644 --- a/docs/src/content/docs/zh-cn/reference/ribbon.md +++ b/docs/src/content/docs/zh-cn/reference/ribbon.md @@ -42,7 +42,7 @@ Ribbon 以活动页签的内容对照窗口宽度实测: 一个带组名的按钮,点击即在弹出面板中展开整组。任何分组都不会比优先级更低的 分组缩得更小,且每个分组始终留在原位。 - 只有当所有分组都已折成单个按钮而仍然放不下时,整组才会移入 **More** 菜单。 -- 命令区不会自行隐藏。**Collapse ribbon**(任务行右端带顶部条带的窗口图标)负责收起与 +- 命令区不会自行隐藏。**Collapse ribbon**(Ribbon 右侧带顶部条带的窗口图标)负责收起与 展开。 启动计算的按钮(如 **Run Peak Fit**)使用强调色填充样式——与任务卡片的