forked from 1b-agent/opencadstudio-upstream
fix(units): make the units selector reach what it names
The status-bar units button wrote INSUNITS, which nothing on screen reads. INSUNITS only tells the drawing how to scale content arriving from elsewhere, so picking a unit relabelled the drawing and changed nothing visible — the selector looked broken because the variable it moved was invisible. Point the button at LUNITS instead, the setting that decides how every coordinate and distance is written, and give the three questions the word "units" runs together a place each: - The button offers the five length formats, each shown beside a sample of itself, so Engineering and Architectural are told apart by sight. - UNITS / DDUNITS opens a real dialog: length and angle format and precision, the direction angle zero points, whether positive angles run clockwise, and the insertion unit. Its sample comes from the same formatters the drawing uses, so it cannot drift from the readout. - DWGUNITS converts. Model geometry, viewport framing, the header's length defaults and each dimension style's scale all move together in one undo step; paper space is left alone, since the sheet is still the same sheet. Locked layers are converted too — a half-converted drawing would be at two scales at once. The coordinate readout formatted at four decimal places whatever the drawing asked for; it now goes through the same format_length the properties panel uses. That made the angle formats reachable in turn, so degrees-minutes-seconds now carries the d/'/" marks that say which convention it is, and surveyor's units are written at all. Typed input is still plain decimal: a length the readout writes as 5'-6 1/2" cannot yet be typed back. ANGBASE and ANGDIR are stored but not yet applied to displayed directions. Closes #668 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
cfc7c06c6c
commit
523b85f42b
14 files changed
+937
-69
No files matched your search
+69
-42
@@ -1,60 +1,87 @@
|
||||
//! Drawing-units status menu.
|
||||
//! Linear-format status menu — the button that decides how every coordinate
|
||||
//! and distance in the drawing is written.
|
||||
//!
|
||||
//! It offers LUNITS, not INSUNITS. Picking "Architectural" changes what the
|
||||
//! readout, the properties panel and every dimension say; picking a *unit*
|
||||
//! changes nothing anybody can see, which is why that choice lives in the UNITS
|
||||
//! dialog next to the insertion scale it belongs to. (#668)
|
||||
|
||||
use iced::widget::{button, row, text};
|
||||
use iced::{Element, Fill};
|
||||
use iced::widget::{button, container, row, text, Space};
|
||||
use iced::{Background, Element, Fill, Theme};
|
||||
|
||||
use crate::app::Message;
|
||||
use crate::ui::statusbar::status_menu::Entry;
|
||||
use crate::t;
|
||||
use crate::ui::statusbar::status_menu::Entry;
|
||||
|
||||
/// 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",
|
||||
}
|
||||
}
|
||||
use crate::modules::draw::units;
|
||||
|
||||
pub fn menu_entries(current: i16) -> Vec<Entry<'static>> {
|
||||
UNITS
|
||||
.iter()
|
||||
.map(|&(code, label)| {
|
||||
Entry::close(unit_row(
|
||||
let mut entries: Vec<Entry<'static>> = units::linear_formats()
|
||||
.map(|(code, label, sample)| {
|
||||
Entry::close(format_row(
|
||||
label,
|
||||
sample,
|
||||
code == current,
|
||||
Message::SetDrawingUnits(code),
|
||||
Message::SetLinearFormat(code),
|
||||
))
|
||||
})
|
||||
.collect()
|
||||
.collect();
|
||||
|
||||
// Precision, angles and the insertion unit are all part of the same
|
||||
// decision and all live one dialog away, so the way there is offered here
|
||||
// rather than left to be found.
|
||||
entries.push(Entry::stay(divider()));
|
||||
entries.push(Entry::close(link(
|
||||
t!("Units\u{2026}").into_owned(),
|
||||
"UNITS",
|
||||
)));
|
||||
entries.push(Entry::close(link(
|
||||
t!("Convert drawing\u{2026}").into_owned(),
|
||||
"DWGUNITS",
|
||||
)));
|
||||
entries
|
||||
}
|
||||
|
||||
fn unit_row(label: &'static str, active: bool, msg: Message) -> Element<'static, Message> {
|
||||
let check = crate::ui::icons::themed_check_cell(active);
|
||||
fn divider() -> Element<'static, Message> {
|
||||
container(Space::new().height(1))
|
||||
.style(|theme: &Theme| container::Style {
|
||||
background: Some(Background::Color(theme.palette().background.weak.color)),
|
||||
..Default::default()
|
||||
})
|
||||
.width(Fill)
|
||||
.padding([0, 4])
|
||||
.into()
|
||||
}
|
||||
|
||||
let lbl = text(t!(label)).size(11);
|
||||
fn link(label: String, command: &'static str) -> Element<'static, Message> {
|
||||
button(text(label).size(11))
|
||||
.on_press(Message::Command(command.into()))
|
||||
.style(button::subtle)
|
||||
.width(Fill)
|
||||
.padding([4, 10])
|
||||
.into()
|
||||
}
|
||||
|
||||
let content = row![check, lbl].spacing(6).align_y(iced::Center);
|
||||
/// One format, shown with a sample of itself so the difference between
|
||||
/// Engineering and Architectural is visible rather than recalled.
|
||||
fn format_row(
|
||||
label: &'static str,
|
||||
sample: &'static str,
|
||||
active: bool,
|
||||
msg: Message,
|
||||
) -> Element<'static, Message> {
|
||||
let content = row![
|
||||
crate::ui::icons::themed_check_cell(active),
|
||||
text(t!(label)).size(11),
|
||||
Space::new().width(Fill),
|
||||
text(sample).size(10).style(|theme: &Theme| {
|
||||
iced::widget::text::Style {
|
||||
color: Some(theme.palette().background.base.text.scale_alpha(0.55)),
|
||||
}
|
||||
}),
|
||||
]
|
||||
.spacing(6)
|
||||
.align_y(iced::Center);
|
||||
|
||||
button(content)
|
||||
.on_press(msg)
|
||||
|
||||
Reference in new issue
Block a user