feat(annotation): integrate object contexts

This commit is contained in:
Hakan Seven committed 2026-08-02 12:00:15 +03:00
1 parent f39481ac49
commit e03e091b3c
37 files changed
+2823 -584

No files matched your search

+12 -8
View File
@@ -14,24 +14,28 @@ use crate::ui::statusbar::status_menu::Entry;
/// scales of its own.
pub fn menu_entries(
is_model: bool,
current_anno_scale: f32,
current_scale_name: &str,
viewport_scale: Option<f64>,
file_scales: Vec<(String, f32, f64)>,
) -> Vec<Entry<'static>> {
let mut entries: Vec<Entry<'static>> = file_scales
.into_iter()
.map(|(label, anno_scale, vp_scale)| {
.map(|(label, _anno_scale, vp_scale)| {
let active = if is_model {
(current_anno_scale - anno_scale).abs() < 0.001 * current_anno_scale.max(0.001)
label.eq_ignore_ascii_case(current_scale_name)
} else {
viewport_scale
.map(|vs| (vs - vp_scale).abs() < 0.001 * vp_scale.max(0.001))
.unwrap_or(false)
label.eq_ignore_ascii_case(current_scale_name)
|| (current_scale_name.is_empty()
&& viewport_scale
.map(|vs| {
(vs - vp_scale).abs() < 0.001 * vp_scale.max(0.001)
})
.unwrap_or(false))
};
let msg = if is_model {
Message::SetAnnotationScale(anno_scale)
Message::SetAnnotationScale(label.clone())
} else {
Message::SetViewportScale(vp_scale)
Message::SetViewportScale(label.clone())
};
Entry::close(scale_row(label, active, msg))
})
+68 -14
View File
@@ -27,10 +27,15 @@ use crate::ui::statusbar::statusbar_config::{StatusBarConfig, StatusPill};
use crate::ui::statusbar::status_menu::Entry as StatusMenuEntry;
use crate::ui::wrap_bar::WrapBar;
const ST_ANNO_VISIBILITY: &[u8] = include_bytes!("../../../assets/icons/scale_list.svg");
const ST_ANNO_AUTO_ADD: &[u8] = include_bytes!("../../../assets/icons/add_scale.svg");
const ST_VP_SCALE_SYNC: &[u8] = include_bytes!("../../../assets/icons/sync.svg");
pub struct StatusMenuData<'a> {
pub layout_names: Vec<String>,
pub polar_custom_input: &'a str,
pub scale_is_model: bool,
pub current_scale_name: String,
pub scale_list: Vec<(String, f32, f64)>,
pub has_selection: bool,
pub selection_types: Vec<String>,
@@ -80,6 +85,9 @@ impl StatusBar {
annotation_scale: f32,
// True when the scale pill is interactive (always model space; paper space only when a viewport is active/selected).
scale_pill_enabled: bool,
annotation_all_visible: bool,
annotation_auto_add: bool,
viewport_scale_synced: Option<bool>,
// LWDISPLAY header flag — controls lineweight visibility in the viewport.
lineweight_display: bool,
// Live cursor position in model coordinates, for the coordinate readout.
@@ -113,6 +121,7 @@ impl StatusBar {
layout_names,
polar_custom_input,
scale_is_model,
current_scale_name,
scale_list,
has_selection,
selection_types,
@@ -175,19 +184,23 @@ impl StatusBar {
// Keep its text identical to the active drawing-defined scale. Rebuilding
// the label from the numeric factor turns an architectural
// `1/2" = 1'-0"` scale into `1:24`, mixing formats in the same control.
let scale_label = active_scale_label(
scale_is_model,
annotation_scale,
viewport_scale,
&scale_list,
)
.unwrap_or_else(|| {
if scale_is_model {
format_scale(Some(1.0 / annotation_scale as f64))
} else {
format_scale(viewport_scale)
}
});
let scale_label = if current_scale_name.is_empty() {
active_scale_label(
scale_is_model,
annotation_scale,
viewport_scale,
&scale_list,
)
.unwrap_or_else(|| {
if scale_is_model {
format_scale(Some(1.0 / annotation_scale as f64))
} else {
format_scale(viewport_scale)
}
})
} else {
current_scale_name.clone()
};
let scale_element: Element<'_, Message> = if scale_pill_enabled {
status_menu::menu_bar(
menu_tip(
@@ -197,7 +210,7 @@ impl StatusBar {
),
crate::ui::popup::scale_popup::menu_entries(
scale_is_model,
annotation_scale,
&current_scale_name,
viewport_scale,
scale_list,
),
@@ -294,6 +307,47 @@ impl StatusBar {
if vis(StatusPill::Scale) {
pills.push(scale_element);
}
if vis(StatusPill::AnnoVisibility) {
pills.push(
tip(
toggle_pill(
ST_ANNO_VISIBILITY,
annotation_all_visible,
Message::ToggleAnnotationVisibility,
),
"Show Annotation Objects",
)
.into(),
);
}
if vis(StatusPill::AnnoAutoAdd) {
pills.push(
tip(
toggle_pill(
ST_ANNO_AUTO_ADD,
annotation_auto_add,
Message::ToggleAnnotationAutoAdd,
),
"Automatically Add Scales",
)
.into(),
);
}
if vis(StatusPill::VpScaleSync) {
if let Some(synced) = viewport_scale_synced {
pills.push(
tip(
toggle_pill(
ST_VP_SCALE_SYNC,
synced,
Message::SyncViewportAnnotationScale,
),
"Viewport / Annotation Scale Sync",
)
.into(),
);
}
}
if vis(StatusPill::Units) {
pills.push(
status_menu::menu_bar(
+12
View File
@@ -20,6 +20,9 @@ pub enum StatusPill {
Osnap,
Space,
Scale,
AnnoVisibility,
AnnoAutoAdd,
VpScaleSync,
Units,
Transparency,
Isolate,
@@ -43,6 +46,9 @@ impl StatusPill {
StatusPill::Osnap,
StatusPill::Space,
StatusPill::Scale,
StatusPill::AnnoVisibility,
StatusPill::AnnoAutoAdd,
StatusPill::VpScaleSync,
StatusPill::Units,
StatusPill::Transparency,
StatusPill::Isolate,
@@ -65,6 +71,9 @@ impl StatusPill {
StatusPill::Osnap => "osnap",
StatusPill::Space => "space",
StatusPill::Scale => "scale",
StatusPill::AnnoVisibility => "anno_visibility",
StatusPill::AnnoAutoAdd => "anno_auto_add",
StatusPill::VpScaleSync => "vp_scale_sync",
StatusPill::Units => "units",
StatusPill::Transparency => "transparency",
StatusPill::Isolate => "isolate",
@@ -88,6 +97,9 @@ impl StatusPill {
StatusPill::Osnap => "Object Snap",
StatusPill::Space => "Model/Paper Space",
StatusPill::Scale => "Annotation Scale",
StatusPill::AnnoVisibility => "Show Annotation Objects",
StatusPill::AnnoAutoAdd => "Automatically Add Scales",
StatusPill::VpScaleSync => "Viewport / Annotation Scale Sync",
StatusPill::Units => "Drawing Units",
StatusPill::Transparency => "Show Transparency",
StatusPill::Isolate => "Isolate Objects",
+9 -1
View File
@@ -537,7 +537,15 @@ pub fn view_window<'a>(
chk("Annotative", vals.annotative, DsField::Annotative),
row![
lbl("Overall scale (DIMSCALE)"),
mk_field(DsField::Dimscale, vals.dimscale)
if vals.annotative {
text_input("", "0")
.style(field_style)
.size(11)
.width(100)
.into()
} else {
mk_field(DsField::Dimscale, vals.dimscale)
}
]
.spacing(8)
.align_y(iced::Center),
+15 -1
View File
@@ -105,6 +105,16 @@ fn num_row<'a>(
.into()
}
fn readonly_num_row<'a>(label: &'static str, value: &'a str) -> Element<'a, Message> {
row![
text(label).size(11).style(muted_style).width(150),
text(value).size(11).style(muted_style),
]
.spacing(8)
.align_y(iced::Center)
.into()
}
/// Shared colour selector row. Reuses MLeaderStyleEdit by sending the chosen
/// colour as an ACI string; `open` shows the expanded palette.
fn color_row<'a>(
@@ -288,7 +298,11 @@ pub fn view_window<'a>(
v.second_seg_angle,
"second_seg_angle"
),
num_row("Scale factor:", "1.0", v.scale_factor, "scale_factor"),
if s.is_annotative {
readonly_num_row("Scale factor:", "By annotation scale")
} else {
num_row("Scale factor:", "1.0", v.scale_factor, "scale_factor")
},
num_row("Align space:", "4.0", v.align_space, "align_space"),
enum_row(
"Leader draw order:",
-5
View File
@@ -293,11 +293,6 @@ pub fn view_window<'a>(
]
.spacing(8)
.align_y(iced::Center),
checkbox(s.annotative)
.label("Annotative")
.on_toggle(|_| Message::TableStyleToggleAnnotative)
.size(14)
.text_size(11),
row![
text("H Margin:").size(11).style(muted_style).width(160),
text_input("1.5", hmargin_buf)
+10 -1
View File
@@ -298,7 +298,16 @@ pub fn view_window<'a>(
text("Properties").size(11).style(primary_style),
frow("Big Font:", "big-font file…", bigfont_buf, "bigfont"),
frow("TrueType Font:", "e.g. Arial", ttf_buf, "ttf"),
frow("Fixed Height:", "0 = variable", height_buf, "height"),
frow(
if annotative {
"Paper Text Height:"
} else {
"Fixed Height:"
},
"0 = variable",
height_buf,
"height",
),
frow("Width Factor:", "1.0", width_buf, "width"),
frow("Oblique (°):", "0.0", oblique_buf, "oblique"),
row![