feat(statusbar): scrollable layout tabs + layout-list dropdown (#199)
Keep the right-side status-bar tools from being pushed off the bar when a drawing has many layouts: the layout tabs now live in a horizontal scrollable that only takes the space left between the menu and the tools, with ‹ › arrows (and the mouse wheel) to scroll them. Repurpose the leftmost hamburger — which previously fired a no-op MENU command — to open a dropdown listing Model and every layout (scrollable, current highlighted); picking one switches to it, an outside click dismisses it. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
4116b85af0
commit
3def2f2034
5 changed files with 173 additions and 9 deletions
|
|
@ -202,6 +202,8 @@ pub(super) struct OpenCADStudio {
|
||||||
scale_popup_open: bool,
|
scale_popup_open: bool,
|
||||||
/// True while the status-bar customization menu is open.
|
/// True while the status-bar customization menu is open.
|
||||||
statusbar_menu_open: bool,
|
statusbar_menu_open: bool,
|
||||||
|
/// True while the leftmost hamburger's Model/layout list dropdown is open.
|
||||||
|
layout_list_open: bool,
|
||||||
/// True while the drawing-units picker is open.
|
/// True while the drawing-units picker is open.
|
||||||
units_popup_open: bool,
|
units_popup_open: bool,
|
||||||
/// True while the Isolate pill's action menu is open.
|
/// True while the Isolate pill's action menu is open.
|
||||||
|
|
@ -1011,6 +1013,9 @@ pub enum Message {
|
||||||
OpenRecent(PathBuf),
|
OpenRecent(PathBuf),
|
||||||
/// Open a URL in the system browser (start-page intro video, links).
|
/// Open a URL in the system browser (start-page intro video, links).
|
||||||
OpenUrl(String),
|
OpenUrl(String),
|
||||||
|
/// Scroll the status-bar layout-tab strip horizontally by `delta` px
|
||||||
|
/// (negative = left). Driven by the ‹ › arrows next to the tabs.
|
||||||
|
ScrollLayoutTabs(f32),
|
||||||
/// Drop a path from the recent-documents list.
|
/// Drop a path from the recent-documents list.
|
||||||
RecentRemove(PathBuf),
|
RecentRemove(PathBuf),
|
||||||
/// User clicked Cancel on the loading overlay. The parser thread keeps
|
/// User clicked Cancel on the loading overlay. The parser thread keeps
|
||||||
|
|
@ -1215,6 +1220,10 @@ pub enum Message {
|
||||||
ToggleScalePopup,
|
ToggleScalePopup,
|
||||||
/// Close the scale picker popup.
|
/// Close the scale picker popup.
|
||||||
CloseScalePopup,
|
CloseScalePopup,
|
||||||
|
/// Toggle the leftmost hamburger's Model/layout list dropdown.
|
||||||
|
ToggleLayoutList,
|
||||||
|
/// Close the Model/layout list dropdown.
|
||||||
|
CloseLayoutList,
|
||||||
/// Toggle the status-bar customization menu open/closed.
|
/// Toggle the status-bar customization menu open/closed.
|
||||||
ToggleStatusBarMenu,
|
ToggleStatusBarMenu,
|
||||||
/// Close the status-bar customization menu.
|
/// Close the status-bar customization menu.
|
||||||
|
|
@ -1794,6 +1803,7 @@ impl OpenCADStudio {
|
||||||
snap_popup_open: false,
|
snap_popup_open: false,
|
||||||
scale_popup_open: false,
|
scale_popup_open: false,
|
||||||
statusbar_menu_open: false,
|
statusbar_menu_open: false,
|
||||||
|
layout_list_open: false,
|
||||||
units_popup_open: false,
|
units_popup_open: false,
|
||||||
isolate_popup_open: false,
|
isolate_popup_open: false,
|
||||||
selection_filter_popup_open: false,
|
selection_filter_popup_open: false,
|
||||||
|
|
|
||||||
|
|
@ -213,6 +213,11 @@ impl OpenCADStudio {
|
||||||
Task::none()
|
Task::none()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Message::ScrollLayoutTabs(dx) => iced::widget::operation::scroll_by(
|
||||||
|
iced::advanced::widget::Id::new(crate::ui::statusbar::LAYOUT_TABS_SCROLL_ID),
|
||||||
|
iced::widget::scrollable::AbsoluteOffset { x: dx, y: 0.0 },
|
||||||
|
),
|
||||||
|
|
||||||
Message::OpenRecent(path) => {
|
Message::OpenRecent(path) => {
|
||||||
// Recents are read from disk every save → the path may be
|
// Recents are read from disk every save → the path may be
|
||||||
// stale. Skip silently if the file no longer exists; the
|
// stale. Skip silently if the file no longer exists; the
|
||||||
|
|
@ -1336,6 +1341,14 @@ impl OpenCADStudio {
|
||||||
self.scale_popup_open = false;
|
self.scale_popup_open = false;
|
||||||
Task::none()
|
Task::none()
|
||||||
}
|
}
|
||||||
|
Message::ToggleLayoutList => {
|
||||||
|
self.layout_list_open ^= true;
|
||||||
|
Task::none()
|
||||||
|
}
|
||||||
|
Message::CloseLayoutList => {
|
||||||
|
self.layout_list_open = false;
|
||||||
|
Task::none()
|
||||||
|
}
|
||||||
Message::ToggleStatusBarMenu => {
|
Message::ToggleStatusBarMenu => {
|
||||||
self.statusbar_menu_open ^= true;
|
self.statusbar_menu_open ^= true;
|
||||||
Task::none()
|
Task::none()
|
||||||
|
|
@ -1946,7 +1959,10 @@ impl OpenCADStudio {
|
||||||
Task::none()
|
Task::none()
|
||||||
}
|
}
|
||||||
|
|
||||||
Message::LayoutSwitch(name) => self.on_layout_switch(name),
|
Message::LayoutSwitch(name) => {
|
||||||
|
self.layout_list_open = false;
|
||||||
|
self.on_layout_switch(name)
|
||||||
|
}
|
||||||
|
|
||||||
Message::LayoutCreate => self.on_layout_create(),
|
Message::LayoutCreate => self.on_layout_create(),
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1222,6 +1222,15 @@ impl OpenCADStudio {
|
||||||
iced::widget::Space::new().width(0).height(0).into()
|
iced::widget::Space::new().width(0).height(0).into()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let layout_list_layer: Element<'_, Message> = if self.layout_list_open && !tab.is_start {
|
||||||
|
crate::ui::statusbar::statusbar_menu::layout_list_overlay(
|
||||||
|
&tab.scene.layout_names(),
|
||||||
|
&tab.scene.current_layout,
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
iced::widget::Space::new().width(0).height(0).into()
|
||||||
|
};
|
||||||
|
|
||||||
let units_layer: Element<'_, Message> = if self.units_popup_open {
|
let units_layer: Element<'_, Message> = if self.units_popup_open {
|
||||||
crate::ui::popup::units_popup::units_popup_overlay(tab.scene.document.header.insertion_units)
|
crate::ui::popup::units_popup::units_popup_overlay(tab.scene.document.header.insertion_units)
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -1286,6 +1295,7 @@ impl OpenCADStudio {
|
||||||
snap_layer,
|
snap_layer,
|
||||||
scale_layer,
|
scale_layer,
|
||||||
statusbar_menu_layer,
|
statusbar_menu_layer,
|
||||||
|
layout_list_layer,
|
||||||
units_layer,
|
units_layer,
|
||||||
isolate_layer,
|
isolate_layer,
|
||||||
sel_filter_layer,
|
sel_filter_layer,
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,18 @@ pub mod statusbar_config;
|
||||||
pub mod statusbar_menu;
|
pub mod statusbar_menu;
|
||||||
|
|
||||||
use iced::widget::tooltip::Position as TipPos;
|
use iced::widget::tooltip::Position as TipPos;
|
||||||
use iced::widget::{button, column, container, mouse_area, row, text, text_input, tooltip, Row};
|
use iced::widget::scrollable::{Direction, Scrollbar};
|
||||||
|
use iced::widget::{
|
||||||
|
button, column, container, mouse_area, row, scrollable, text, text_input, tooltip, Row,
|
||||||
|
};
|
||||||
use iced::{Background, Border, Color, Element, Length, Theme};
|
use iced::{Background, Border, Color, Element, Length, Theme};
|
||||||
|
|
||||||
|
/// Scrollable id of the status-bar layout-tab strip, so the ‹ › arrows (and
|
||||||
|
/// `Message::ScrollLayoutTabs`) can scroll it.
|
||||||
|
pub const LAYOUT_TABS_SCROLL_ID: &str = "statusbar-layout-tabs";
|
||||||
|
/// How far one ‹ / › arrow click scrolls the layout-tab strip.
|
||||||
|
const LAYOUT_TAB_SCROLL_STEP: f32 = 96.0;
|
||||||
|
|
||||||
/// Widget id of the inline layout-rename text input, so the rename can grab
|
/// Widget id of the inline layout-rename text input, so the rename can grab
|
||||||
/// keyboard focus the moment it opens (issue #86).
|
/// keyboard focus the moment it opens (issue #86).
|
||||||
pub const LAYOUT_RENAME_INPUT_ID: &str = "layout_rename_input";
|
pub const LAYOUT_RENAME_INPUT_ID: &str = "layout_rename_input";
|
||||||
|
|
@ -78,10 +87,19 @@ impl StatusBar {
|
||||||
// Which pills the user has chosen to show on the bar.
|
// Which pills the user has chosen to show on the bar.
|
||||||
config: &'a StatusBarConfig,
|
config: &'a StatusBarConfig,
|
||||||
) -> Element<'a, Message> {
|
) -> Element<'a, Message> {
|
||||||
|
// Leftmost hamburger: opens a dropdown listing Model + every layout, so
|
||||||
|
// a layout can be picked directly even when the tab strip is scrolled.
|
||||||
let menu_btn = button(crate::ui::icons::tinted(crate::ui::icons::MENU, 14.0, ICON_COLOR))
|
let menu_btn = button(crate::ui::icons::tinted(crate::ui::icons::MENU, 14.0, ICON_COLOR))
|
||||||
.on_press(Message::Command("MENU".into()))
|
.on_press(Message::ToggleLayoutList)
|
||||||
.style(|_: &Theme, _| button::Style {
|
.style(|_: &Theme, status| button::Style {
|
||||||
background: Some(Background::Color(Color::TRANSPARENT)),
|
background: Some(Background::Color(match status {
|
||||||
|
button::Status::Hovered => PILL_BG,
|
||||||
|
_ => Color::TRANSPARENT,
|
||||||
|
})),
|
||||||
|
border: Border {
|
||||||
|
radius: 3.0.into(),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
.padding([2, 8]);
|
.padding([2, 8]);
|
||||||
|
|
@ -236,16 +254,31 @@ impl StatusBar {
|
||||||
let mut bar = Row::new().align_y(iced::Center).spacing(0);
|
let mut bar = Row::new().align_y(iced::Center).spacing(0);
|
||||||
bar = bar.push(menu_btn);
|
bar = bar.push(menu_btn);
|
||||||
if show_layout_tabs {
|
if show_layout_tabs {
|
||||||
|
// The layout tabs live in a horizontal scrollable that takes only
|
||||||
|
// the space left between the menu and the right-side tools, so many
|
||||||
|
// layouts scroll instead of pushing the tools off the bar (#199).
|
||||||
|
// ‹ › arrows scroll it (the mouse wheel works too).
|
||||||
|
let mut tabs_row = Row::new().align_y(iced::Center).spacing(0);
|
||||||
for name in layouts {
|
for name in layouts {
|
||||||
let is_active = name == current_layout;
|
let is_active = name == current_layout;
|
||||||
let renaming = rename_state
|
let renaming = rename_state
|
||||||
.filter(|(orig, _)| *orig == name)
|
.filter(|(orig, _)| *orig == name)
|
||||||
.map(|(_, edit)| edit.as_str());
|
.map(|(_, edit)| edit.as_str());
|
||||||
bar = bar.push(space_tab(name, is_active, renaming));
|
tabs_row = tabs_row.push(space_tab(name, is_active, renaming));
|
||||||
}
|
|
||||||
bar = bar.push(add_btn);
|
|
||||||
}
|
}
|
||||||
|
tabs_row = tabs_row.push(add_btn);
|
||||||
|
|
||||||
|
let tabs_scroll = scrollable(tabs_row)
|
||||||
|
.direction(Direction::Horizontal(Scrollbar::hidden()))
|
||||||
|
.id(iced::advanced::widget::Id::new(LAYOUT_TABS_SCROLL_ID))
|
||||||
|
.width(Length::Shrink);
|
||||||
|
|
||||||
|
bar = bar.push(scroll_arrow(false));
|
||||||
|
bar = bar.push(container(tabs_scroll).width(Length::Fill));
|
||||||
|
bar = bar.push(scroll_arrow(true));
|
||||||
|
} else {
|
||||||
bar = bar.push(iced::widget::Space::new().width(Length::Fill));
|
bar = bar.push(iced::widget::Space::new().width(Length::Fill));
|
||||||
|
}
|
||||||
bar = bar.push(right_status);
|
bar = bar.push(right_status);
|
||||||
|
|
||||||
container(bar)
|
container(bar)
|
||||||
|
|
@ -271,6 +304,38 @@ fn format_coords(p: glam::Vec3) -> String {
|
||||||
format!("{:.4}, {:.4}, {:.4}", p.x, p.y, p.z)
|
format!("{:.4}, {:.4}, {:.4}", p.x, p.y, p.z)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ── Layout-tab scroll arrow ───────────────────────────────────────────────
|
||||||
|
|
||||||
|
/// A ‹ / › arrow that scrolls the layout-tab strip. `right` picks the
|
||||||
|
/// direction (and step sign).
|
||||||
|
fn scroll_arrow<'a>(right: bool) -> Element<'a, Message> {
|
||||||
|
let glyph = if right {
|
||||||
|
crate::ui::icons::arrow_right(9.0, ICON_COLOR)
|
||||||
|
} else {
|
||||||
|
crate::ui::icons::arrow_left(9.0, ICON_COLOR)
|
||||||
|
};
|
||||||
|
let step = if right {
|
||||||
|
LAYOUT_TAB_SCROLL_STEP
|
||||||
|
} else {
|
||||||
|
-LAYOUT_TAB_SCROLL_STEP
|
||||||
|
};
|
||||||
|
button(glyph)
|
||||||
|
.on_press(Message::ScrollLayoutTabs(step))
|
||||||
|
.style(|_: &Theme, status| button::Style {
|
||||||
|
background: Some(Background::Color(match status {
|
||||||
|
button::Status::Hovered => PILL_BG,
|
||||||
|
_ => Color::TRANSPARENT,
|
||||||
|
})),
|
||||||
|
border: Border {
|
||||||
|
radius: 3.0.into(),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
..Default::default()
|
||||||
|
})
|
||||||
|
.padding([2, 4])
|
||||||
|
.into()
|
||||||
|
}
|
||||||
|
|
||||||
// ── Customization handle ──────────────────────────────────────────────────
|
// ── Customization handle ──────────────────────────────────────────────────
|
||||||
|
|
||||||
fn customize_btn() -> Element<'static, Message> {
|
fn customize_btn() -> Element<'static, Message> {
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
//! opened from the bar's far-right handle. Rendered as a floating overlay
|
//! opened from the bar's far-right handle. Rendered as a floating overlay
|
||||||
//! above the status bar, same pattern as the scale picker.
|
//! above the status bar, same pattern as the scale picker.
|
||||||
|
|
||||||
use iced::widget::{button, column, container, mouse_area, row, text};
|
use iced::widget::{button, column, container, mouse_area, row, scrollable, text};
|
||||||
use iced::{Background, Border, Color, Element, Fill, Length, Padding, Theme};
|
use iced::{Background, Border, Color, Element, Fill, Length, Padding, Theme};
|
||||||
|
|
||||||
use crate::app::Message;
|
use crate::app::Message;
|
||||||
|
|
@ -51,6 +51,69 @@ pub fn statusbar_menu_overlay(config: &StatusBarConfig) -> Element<'static, Mess
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Dropdown listing Model + every paper layout, opened from the leftmost
|
||||||
|
/// hamburger. Pinned bottom-left just above the status bar; a click selects a
|
||||||
|
/// layout (and closes), an outside click just closes.
|
||||||
|
pub fn layout_list_overlay<'a>(layouts: &[String], current: &str) -> Element<'a, Message> {
|
||||||
|
let rows: Vec<Element<'a, Message>> = layouts
|
||||||
|
.iter()
|
||||||
|
.map(|name| layout_row(name.clone(), name == current))
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
let panel = container(scrollable(column(rows)))
|
||||||
|
.style(|_: &Theme| container::Style {
|
||||||
|
background: Some(Background::Color(PANEL_BG)),
|
||||||
|
border: Border {
|
||||||
|
color: PANEL_BORDER,
|
||||||
|
width: 1.0,
|
||||||
|
radius: 3.0.into(),
|
||||||
|
},
|
||||||
|
..Default::default()
|
||||||
|
})
|
||||||
|
.width(Length::Fixed(200.0))
|
||||||
|
.max_height(360.0);
|
||||||
|
|
||||||
|
let positioned = container(panel)
|
||||||
|
.align_left(Fill)
|
||||||
|
.align_bottom(Fill)
|
||||||
|
.padding(Padding {
|
||||||
|
bottom: 27.0,
|
||||||
|
left: 4.0,
|
||||||
|
top: 0.0,
|
||||||
|
right: 0.0,
|
||||||
|
})
|
||||||
|
.width(Fill)
|
||||||
|
.height(Fill);
|
||||||
|
|
||||||
|
mouse_area(positioned)
|
||||||
|
.on_press(Message::CloseLayoutList)
|
||||||
|
.into()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn layout_row<'a>(name: String, is_current: bool) -> Element<'a, Message> {
|
||||||
|
let lbl = text(name.clone())
|
||||||
|
.size(11)
|
||||||
|
.color(if is_current { LABEL_ON } else { LABEL_OFF });
|
||||||
|
button(row![lbl].align_y(iced::Center))
|
||||||
|
.on_press(Message::LayoutSwitch(name))
|
||||||
|
.style(move |_: &Theme, status| button::Style {
|
||||||
|
background: Some(Background::Color(match (is_current, status) {
|
||||||
|
(_, button::Status::Hovered) => ROW_HOVER,
|
||||||
|
(true, _) => Color {
|
||||||
|
r: 0.18,
|
||||||
|
g: 0.26,
|
||||||
|
b: 0.36,
|
||||||
|
a: 1.0,
|
||||||
|
},
|
||||||
|
_ => Color::TRANSPARENT,
|
||||||
|
})),
|
||||||
|
..Default::default()
|
||||||
|
})
|
||||||
|
.width(Fill)
|
||||||
|
.padding([4, 12])
|
||||||
|
.into()
|
||||||
|
}
|
||||||
|
|
||||||
fn menu_row(label: &'static str, checked: bool, msg: Message) -> Element<'static, Message> {
|
fn menu_row(label: &'static str, checked: bool, msg: Message) -> Element<'static, Message> {
|
||||||
let check = crate::ui::icons::check_cell(checked, CHECK_COLOR);
|
let check = crate::ui::icons::check_cell(checked, CHECK_COLOR);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue