forked from 1b-agent/opencadstudio-upstream
feat(statusbar): drawing-units pill with INSUNITS picker
Add a Units pill that shows the drawing's current INSUNITS value and opens a picker to change it (Unitless, mm, cm, m, km, in, ft, mi, yd). Toggleable from the status-bar customization menu like the other pills. Co-Authored-By: Claude Opus 4.8 <[email protected]>
This commit is contained in:
1 parent
d829f80a04
commit
243a0bc923
7 files changed
+219
No files matched your search
@@ -173,6 +173,8 @@ pub(super) struct OpenCADStudio {
|
||||
scale_popup_open: bool,
|
||||
/// True while the status-bar customization menu is open.
|
||||
statusbar_menu_open: bool,
|
||||
/// True while the drawing-units picker is open.
|
||||
units_popup_open: bool,
|
||||
/// Clean-screen mode: hide ribbon and side panels for a full canvas.
|
||||
clean_screen: bool,
|
||||
/// Which status-bar pills the user has chosen to show (persisted).
|
||||
@@ -746,6 +748,12 @@ pub enum Message {
|
||||
ToggleStatusPill(crate::ui::statusbar_config::StatusPill),
|
||||
/// Toggle clean-screen mode (hide ribbon + side panels).
|
||||
ToggleCleanScreen,
|
||||
/// Toggle the drawing-units picker open/closed.
|
||||
ToggleUnitsPopup,
|
||||
/// Close the drawing-units picker.
|
||||
CloseUnitsPopup,
|
||||
/// Set the drawing units (INSUNITS) for the active drawing.
|
||||
SetDrawingUnits(i16),
|
||||
/// Toggle dynamic input overlay (F12).
|
||||
ToggleDynInput,
|
||||
/// Toggle object snap tracking (F11).
|
||||
@@ -1203,6 +1211,7 @@ impl OpenCADStudio {
|
||||
snap_popup_open: false,
|
||||
scale_popup_open: false,
|
||||
statusbar_menu_open: false,
|
||||
units_popup_open: false,
|
||||
statusbar_config: crate::ui::statusbar_config::StatusBarConfig::load(),
|
||||
clean_screen: false,
|
||||
pre_cmd_tangent: None,
|
||||
|
||||
@@ -3580,6 +3580,21 @@ impl OpenCADStudio {
|
||||
self.clean_screen ^= true;
|
||||
Task::none()
|
||||
}
|
||||
Message::ToggleUnitsPopup => {
|
||||
self.units_popup_open ^= true;
|
||||
Task::none()
|
||||
}
|
||||
Message::CloseUnitsPopup => {
|
||||
self.units_popup_open = false;
|
||||
Task::none()
|
||||
}
|
||||
Message::SetDrawingUnits(code) => {
|
||||
self.units_popup_open = false;
|
||||
let i = self.active_tab;
|
||||
self.tabs[i].scene.document.header.insertion_units = code;
|
||||
self.tabs[i].dirty = true;
|
||||
Task::none()
|
||||
}
|
||||
Message::ToggleSnap(t) => {
|
||||
self.snapper.toggle(t);
|
||||
Task::none()
|
||||
|
||||
@@ -1157,6 +1157,8 @@ impl OpenCADStudio {
|
||||
tab.scene.document.header.lineweight_display,
|
||||
cursor_coord,
|
||||
self.clean_screen,
|
||||
tab.scene.document.header.insertion_units,
|
||||
self.units_popup_open,
|
||||
&self.statusbar_config,
|
||||
)
|
||||
})
|
||||
@@ -1199,6 +1201,14 @@ impl OpenCADStudio {
|
||||
iced::widget::Space::new().width(0).height(0).into()
|
||||
};
|
||||
|
||||
let units_layer: Element<'_, Message> = if self.units_popup_open {
|
||||
crate::ui::units_popup::units_popup_overlay(
|
||||
tab.scene.document.header.insertion_units,
|
||||
)
|
||||
} else {
|
||||
iced::widget::Space::new().width(0).height(0).into()
|
||||
};
|
||||
|
||||
let dropdown_layer: Element<'_, Message> = self
|
||||
.ribbon
|
||||
.dropdown_overlay(
|
||||
@@ -1235,6 +1245,7 @@ impl OpenCADStudio {
|
||||
snap_layer,
|
||||
scale_layer,
|
||||
statusbar_menu_layer,
|
||||
units_layer,
|
||||
dropdown_layer,
|
||||
layout_ctx_layer,
|
||||
qselect_layer,
|
||||
|
||||
@@ -25,6 +25,7 @@ pub mod statusbar_config;
|
||||
pub mod statusbar_menu;
|
||||
pub mod tablestyle;
|
||||
pub mod textstyle;
|
||||
pub mod units_popup;
|
||||
|
||||
pub use app_menu::AppMenu;
|
||||
pub use command_line::CommandLine;
|
||||
|
||||
@@ -55,6 +55,10 @@ impl StatusBar {
|
||||
cursor_world: glam::Vec3,
|
||||
// True while clean-screen mode hides the ribbon and side panels.
|
||||
clean_screen: bool,
|
||||
// Drawing units (INSUNITS) for the units pill.
|
||||
insertion_units: i16,
|
||||
// True while the drawing-units picker is open.
|
||||
units_popup_open: bool,
|
||||
// Which pills the user has chosen to show on the bar.
|
||||
config: &'a StatusBarConfig,
|
||||
) -> Element<'a, Message> {
|
||||
@@ -160,6 +164,15 @@ impl StatusBar {
|
||||
if vis(StatusPill::Scale) {
|
||||
right_status = right_status.push(scale_element);
|
||||
}
|
||||
if vis(StatusPill::Units) {
|
||||
right_status = right_status.push(tip(
|
||||
units_btn(
|
||||
crate::ui::units_popup::unit_short(insertion_units),
|
||||
units_popup_open,
|
||||
),
|
||||
"Drawing Units (INSUNITS)\nClick to change",
|
||||
));
|
||||
}
|
||||
if vis(StatusPill::Vp) && !vp_label.is_empty() {
|
||||
right_status = right_status.push(tip(
|
||||
status_pill(vp_label).into(),
|
||||
@@ -749,6 +762,34 @@ const SNAP_OFF_HOVER: Color = Color {
|
||||
|
||||
// ── Scale popup button ────────────────────────────────────────────────────
|
||||
|
||||
fn units_btn(label: &str, open: bool) -> Element<'static, Message> {
|
||||
let label = label.to_string();
|
||||
button(
|
||||
text(label)
|
||||
.size(10)
|
||||
.color(if open { SNAP_BORDER_ON } else { OSNAP_OFF_TEXT }),
|
||||
)
|
||||
.on_press(Message::ToggleUnitsPopup)
|
||||
.style(move |_: &Theme, status| button::Style {
|
||||
background: Some(Background::Color(match (open, status) {
|
||||
(true, button::Status::Hovered) => SNAP_ON_HOVER,
|
||||
(true, _) => SNAP_ON_BG,
|
||||
(false, button::Status::Hovered) => SNAP_OFF_HOVER,
|
||||
(false, _) => SNAP_OFF_BG,
|
||||
})),
|
||||
border: Border {
|
||||
color: if open { SNAP_BORDER_ON } else { BORDER_COLOR },
|
||||
width: 1.0,
|
||||
radius: 2.0.into(),
|
||||
},
|
||||
text_color: if open { SNAP_BORDER_ON } else { OSNAP_OFF_TEXT },
|
||||
shadow: iced::Shadow::default(),
|
||||
snap: false,
|
||||
})
|
||||
.padding([2, 6])
|
||||
.into()
|
||||
}
|
||||
|
||||
fn scale_popup_btn(label: &str, open: bool) -> Element<'static, Message> {
|
||||
let label = label.to_string();
|
||||
button(
|
||||
|
||||
@@ -22,6 +22,7 @@ pub enum StatusPill {
|
||||
Osnap,
|
||||
Space,
|
||||
Scale,
|
||||
Units,
|
||||
Vp,
|
||||
CleanScreen,
|
||||
}
|
||||
@@ -41,6 +42,7 @@ impl StatusPill {
|
||||
StatusPill::Osnap,
|
||||
StatusPill::Space,
|
||||
StatusPill::Scale,
|
||||
StatusPill::Units,
|
||||
StatusPill::Vp,
|
||||
StatusPill::CleanScreen,
|
||||
];
|
||||
@@ -59,6 +61,7 @@ impl StatusPill {
|
||||
StatusPill::Osnap => "osnap",
|
||||
StatusPill::Space => "space",
|
||||
StatusPill::Scale => "scale",
|
||||
StatusPill::Units => "units",
|
||||
StatusPill::Vp => "vp",
|
||||
StatusPill::CleanScreen => "cleanscreen",
|
||||
}
|
||||
@@ -78,6 +81,7 @@ impl StatusPill {
|
||||
StatusPill::Osnap => "Object Snap",
|
||||
StatusPill::Space => "Model/Paper Space",
|
||||
StatusPill::Scale => "Annotation Scale",
|
||||
StatusPill::Units => "Drawing Units",
|
||||
StatusPill::Vp => "Viewport Count",
|
||||
StatusPill::CleanScreen => "Clean Screen",
|
||||
}
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
//! Drawing-units picker — sets the INSUNITS header value. Rendered as a
|
||||
//! floating overlay above the status bar, same pattern as the scale picker.
|
||||
|
||||
use iced::widget::{button, column, container, mouse_area, row, text};
|
||||
use iced::{Background, Border, Color, Element, Fill, Length, Padding, Theme};
|
||||
|
||||
use crate::app::Message;
|
||||
|
||||
/// Units offered in the picker: (INSUNITS code, menu label).
|
||||
const UNITS: &[(i16, &str)] = &[
|
||||
(0, "Unitless"),
|
||||
(4, "Millimeters"),
|
||||
(5, "Centimeters"),
|
||||
(6, "Meters"),
|
||||
(7, "Kilometers"),
|
||||
(1, "Inches"),
|
||||
(2, "Feet"),
|
||||
(3, "Miles"),
|
||||
(10, "Yards"),
|
||||
];
|
||||
|
||||
/// Short label shown on the status-bar pill for an INSUNITS code.
|
||||
pub fn unit_short(code: i16) -> &'static str {
|
||||
match code {
|
||||
1 => "in",
|
||||
2 => "ft",
|
||||
3 => "mi",
|
||||
4 => "mm",
|
||||
5 => "cm",
|
||||
6 => "m",
|
||||
7 => "km",
|
||||
10 => "yd",
|
||||
0 => "Unitless",
|
||||
_ => "Unit",
|
||||
}
|
||||
}
|
||||
|
||||
/// Full-screen overlay: transparent click-catcher + units list pinned
|
||||
/// bottom-right, above the status bar.
|
||||
pub fn units_popup_overlay(current: i16) -> Element<'static, Message> {
|
||||
let rows: Vec<Element<'static, Message>> = UNITS
|
||||
.iter()
|
||||
.map(|&(code, label)| unit_row(label, code == current, Message::SetDrawingUnits(code)))
|
||||
.collect();
|
||||
|
||||
let panel = container(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(140.0));
|
||||
|
||||
let positioned = container(panel)
|
||||
.align_right(Fill)
|
||||
.align_bottom(Fill)
|
||||
.padding(Padding {
|
||||
bottom: 27.0,
|
||||
right: 4.0,
|
||||
top: 0.0,
|
||||
left: 0.0,
|
||||
})
|
||||
.width(Fill)
|
||||
.height(Fill);
|
||||
|
||||
mouse_area(positioned)
|
||||
.on_press(Message::CloseUnitsPopup)
|
||||
.into()
|
||||
}
|
||||
|
||||
fn unit_row(label: &'static str, active: bool, msg: Message) -> Element<'static, Message> {
|
||||
let check = text(if active { "✓" } else { " " })
|
||||
.size(11)
|
||||
.color(if active { CHECK_COLOR } else { Color::TRANSPARENT })
|
||||
.width(Length::Fixed(14.0));
|
||||
|
||||
let lbl = text(label)
|
||||
.size(11)
|
||||
.color(if active { LABEL_ON } else { LABEL_OFF });
|
||||
|
||||
let content = row![check, lbl].spacing(6).align_y(iced::Center);
|
||||
|
||||
button(content)
|
||||
.on_press(msg)
|
||||
.style(|_: &Theme, status| button::Style {
|
||||
background: Some(Background::Color(match status {
|
||||
button::Status::Hovered => ROW_HOVER,
|
||||
_ => Color::TRANSPARENT,
|
||||
})),
|
||||
..Default::default()
|
||||
})
|
||||
.width(Fill)
|
||||
.padding([4, 10])
|
||||
.into()
|
||||
}
|
||||
|
||||
// ── Colours ───────────────────────────────────────────────────────────────
|
||||
|
||||
const PANEL_BG: Color = Color {
|
||||
r: 0.15,
|
||||
g: 0.15,
|
||||
b: 0.15,
|
||||
a: 1.0,
|
||||
};
|
||||
const PANEL_BORDER: Color = Color {
|
||||
r: 0.32,
|
||||
g: 0.32,
|
||||
b: 0.32,
|
||||
a: 1.0,
|
||||
};
|
||||
const ROW_HOVER: Color = Color {
|
||||
r: 0.22,
|
||||
g: 0.22,
|
||||
b: 0.22,
|
||||
a: 1.0,
|
||||
};
|
||||
const CHECK_COLOR: Color = Color {
|
||||
r: 0.35,
|
||||
g: 0.75,
|
||||
b: 1.00,
|
||||
a: 1.0,
|
||||
};
|
||||
const LABEL_ON: Color = Color {
|
||||
r: 0.92,
|
||||
g: 0.92,
|
||||
b: 0.92,
|
||||
a: 1.0,
|
||||
};
|
||||
const LABEL_OFF: Color = Color {
|
||||
r: 0.65,
|
||||
g: 0.65,
|
||||
b: 0.65,
|
||||
a: 1.0,
|
||||
};
|
||||
Reference in new issue
Block a user