forked from 1b-agent/opencadstudio-upstream
Pin Iced 0.15 so dialogs can measure content before distributing the resolved frame across child panels. Keep the web plugin notice compact and non-resizable.\n\nCloses #582
101 lines
3.4 KiB
Rust
101 lines
3.4 KiB
Rust
//! Annotation Object Scale dialog — add / remove the annotation scales a single
|
|
//! selected object carries a per-object representation for.
|
|
//!
|
|
//! Each drawing scale is a row; a checkmark marks the scales the object is a
|
|
//! member of. Clicking a row toggles membership: adding synthesizes a per-scale
|
|
//! context (`AcDb*ObjectContextData`) at that scale, removing drops it. Shares
|
|
//! the style / scale managers' frame so it looks consistent.
|
|
|
|
use crate::app::Message;
|
|
use crate::ui::style::style_manager::{hdivider, muted_text_style, tb_button};
|
|
use iced::widget::{column, container, mouse_area, row, scrollable, text, Space};
|
|
use iced::{Background, Border, Element, Theme};
|
|
|
|
/// `scales` is `(name, "paper:drawing" ratio, is_member)`. Every label is cloned
|
|
/// into the widget tree, so the returned element borrows nothing from the args.
|
|
pub fn view_window(
|
|
object_label: &str,
|
|
scales: &[(String, String, bool)],
|
|
sizing: crate::ui::modal::ModalSizing,
|
|
) -> Element<'static, Message> {
|
|
let toolbar = container(
|
|
row![
|
|
text(format!("Object: {object_label}")).size(11),
|
|
Space::new().width(sizing.width),
|
|
tb_button("Close", Message::CloseModal, true),
|
|
]
|
|
.spacing(4)
|
|
.align_y(iced::Center),
|
|
)
|
|
.style(|theme: &Theme| container::Style {
|
|
background: Some(Background::Color(
|
|
theme.palette().background.weak.color
|
|
)),
|
|
..Default::default()
|
|
})
|
|
.width(sizing.width)
|
|
.padding([5, 8]);
|
|
|
|
let rows: Vec<Element<'_, Message>> = scales
|
|
.iter()
|
|
.map(|(name, ratio, member)| {
|
|
let check = crate::ui::icons::themed_check_cell(*member);
|
|
let label = row![
|
|
check,
|
|
text(name.clone()).size(11).width(sizing.width),
|
|
text(ratio.clone()).size(10).style(muted_text_style),
|
|
]
|
|
.spacing(4)
|
|
.align_y(iced::Center);
|
|
let cell = container(label)
|
|
.padding([4, 8])
|
|
.width(sizing.width);
|
|
mouse_area(cell)
|
|
.on_press(Message::AnnoObjectScaleToggle(name.clone()))
|
|
.into()
|
|
})
|
|
.collect();
|
|
|
|
let list = container(scrollable(column(rows).spacing(1)).height(sizing.height))
|
|
.style(|theme: &Theme| {
|
|
let palette = theme.palette();
|
|
container::Style {
|
|
background: Some(Background::Color(palette.background.weak.color)),
|
|
border: Border {
|
|
color: palette.background.neutral.color,
|
|
width: 1.0,
|
|
radius: 3.0.into(),
|
|
},
|
|
..Default::default()
|
|
}
|
|
})
|
|
.width(sizing.width)
|
|
.height(sizing.height)
|
|
.padding(2);
|
|
|
|
let body = container(
|
|
column![
|
|
text("Click a scale to add or remove the object's representation for it.")
|
|
.size(10)
|
|
.style(muted_text_style),
|
|
list,
|
|
]
|
|
.spacing(6)
|
|
.height(sizing.height),
|
|
)
|
|
.width(sizing.width)
|
|
.height(sizing.height)
|
|
.padding(12);
|
|
|
|
container(column![toolbar, hdivider(sizing.width), body])
|
|
.style(|theme: &Theme| container::Style {
|
|
background: Some(Background::Color(
|
|
theme.palette().background.base.color
|
|
)),
|
|
..Default::default()
|
|
})
|
|
.width(sizing.width)
|
|
.height(sizing.height)
|
|
.into()
|
|
}
|