fix(ui): auto-size modal dialogs
Measure dialog content before fill layout so fields stay visible.\nKeep the MText preview width tied to its toolbar width.\n\nRefs #608
This commit is contained in:
parent
54124dc252
commit
796d7d91d0
11 changed files with 352 additions and 220 deletions
|
|
@ -1330,9 +1330,9 @@ impl OpenCADStudio {
|
|||
viewport_stack = viewport_stack.push(mtext_editor_overlay(
|
||||
ed,
|
||||
styles,
|
||||
canvas,
|
||||
self.modal_offset,
|
||||
self.modal_resize,
|
||||
self.modal_content_size,
|
||||
));
|
||||
}
|
||||
if let Some(ed) = &self.text_inline {
|
||||
|
|
@ -1548,7 +1548,13 @@ impl OpenCADStudio {
|
|||
let qselect_layer: Element<'_, Message> = if let Some(state) = &self.qselect {
|
||||
let types = tab.scene.entity_type_names_in_layout();
|
||||
let properties = tab.scene.qselect_properties(state.type_filter.as_deref());
|
||||
qselect_overlay(state, &types, &properties)
|
||||
qselect_overlay(
|
||||
state,
|
||||
&types,
|
||||
&properties,
|
||||
self.modal_offset,
|
||||
self.modal_resize,
|
||||
)
|
||||
} else {
|
||||
iced::widget::Space::new().width(0).height(0).into()
|
||||
};
|
||||
|
|
@ -1613,67 +1619,12 @@ impl OpenCADStudio {
|
|||
}
|
||||
}
|
||||
|
||||
/// Conservative outer pixel bounds for the active modal, used to clamp drag
|
||||
/// so it cannot be pushed off-screen. Mirrors the maximum dimensions in
|
||||
/// [`Self::modal_content`]; content-sized dialogs may render smaller.
|
||||
/// `None` has no active modal. About uses a safe estimate.
|
||||
/// Measured outer pixel bounds for whichever shared modal is visible, used
|
||||
/// to keep its frame on-screen while dragging.
|
||||
pub(crate) fn modal_outer_size(&self) -> Option<(f32, f32)> {
|
||||
use super::ModalKind::*;
|
||||
// Title bar (~26) + spacing (6) + frame padding (10·2) → ~52 vertical;
|
||||
// frame padding → ~20 horizontal.
|
||||
const EXTRA_W: f32 = 20.0;
|
||||
const EXTRA_H: f32 = 52.0;
|
||||
let (w, h) = match self.active_modal? {
|
||||
About => (440, 360),
|
||||
Shortcuts => (720, 520),
|
||||
Options => (520, 500),
|
||||
FindReplace => (560, 190),
|
||||
PluginManager => {
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
{
|
||||
(self.web_plugin_notice_width(), 230)
|
||||
}
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
{
|
||||
(940, 600)
|
||||
}
|
||||
}
|
||||
UpdateNotice => (560, 460),
|
||||
Layers => (900, 360),
|
||||
LayerStateManager => (720, 420),
|
||||
LayerStateEditor => (1180, 560),
|
||||
Plot => (760, 540),
|
||||
LayoutManager => (640, 320),
|
||||
Plotstyle => (780, 540),
|
||||
TextStyle => (860, 480),
|
||||
MlStyle => (620, 420),
|
||||
TableStyle => (620, 420),
|
||||
MLeaderStyle => (560, 560),
|
||||
DimStyle => (720, 560),
|
||||
AssocPrompt => (440, 210),
|
||||
Unsaved => (420, 160),
|
||||
AecDropWarning => (480, 230),
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
FileInUse => (560, 250),
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
ExternalChange => (620, 250),
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
SaveDialog => (420, 200),
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
SaveDialog => (420, 150),
|
||||
PointStyle => (360, 470),
|
||||
AttributeEditor => (640, 500),
|
||||
LayerDeleteWarning => (440, 200),
|
||||
Aliases => (480, 520),
|
||||
ScaleManager => (520, 360),
|
||||
AnnoObjectScale => (360, 420),
|
||||
};
|
||||
// Include the user's corner-resize growth so the drag clamp tracks the
|
||||
// dialog's actual footprint.
|
||||
Some((
|
||||
w as f32 + EXTRA_W + self.modal_resize.x,
|
||||
h as f32 + EXTRA_H + self.modal_resize.y,
|
||||
))
|
||||
let size = self.modal_content_size?;
|
||||
// Frame padding is 10 px per side; title + body spacing is 30 px.
|
||||
Some((size.width + 20.0, size.height + 50.0))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,13 +1,8 @@
|
|||
use super::super::{Message, OpenCADStudio};
|
||||
use iced::widget::{button, column, container, row, text, Space};
|
||||
use iced::{Background, Element, Fit, Theme};
|
||||
use iced::{Background, Element, Fill, Fit, Theme};
|
||||
|
||||
impl OpenCADStudio {
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
pub(super) fn web_plugin_notice_width(&self) -> u16 {
|
||||
(self.win_size.0 - 48.0).clamp(280.0, 460.0) as u16
|
||||
}
|
||||
|
||||
/// Title shown in the active modal's title bar. Keep in sync with the
|
||||
/// [`Self::modal_content`] dispatch.
|
||||
pub(super) fn modal_title(&self) -> &'static str {
|
||||
|
|
@ -49,21 +44,17 @@ impl OpenCADStudio {
|
|||
}
|
||||
|
||||
/// Build the currently-open modal dialog's content (Plan B), or `None`.
|
||||
/// Each former pop-up window is constructed here and given a maximum size.
|
||||
/// Iced 0.15 measures the content first, so smaller dialogs stop at their
|
||||
/// intrinsic size while overflowing regions become scrollable at the cap.
|
||||
/// Iced 0.15 measures the content first, so dialogs start at their natural
|
||||
/// size and overflowing regions become scrollable where a cap is supplied.
|
||||
pub(super) fn modal_content<'s>(&'s self) -> Option<Element<'s, Message>> {
|
||||
let ex = self.modal_resize;
|
||||
let sized = |e: Element<'s, Message>, w: u16, h: u16| -> Element<'s, Message> {
|
||||
container(e)
|
||||
.width(Fit.max(w as f32 + ex.x))
|
||||
.height(Fit.max(h as f32 + ex.y))
|
||||
.into()
|
||||
};
|
||||
Some(match self.active_modal? {
|
||||
super::super::ModalKind::About => {
|
||||
sized(crate::ui::window::about::view_window(), 440, 360)
|
||||
}
|
||||
super::super::ModalKind::About => automatic_flow(ex, |flow| {
|
||||
container(crate::ui::window::about::view_window())
|
||||
.width(flow.width)
|
||||
.height(flow.height)
|
||||
.into()
|
||||
}),
|
||||
super::super::ModalKind::Shortcuts => {
|
||||
sized_flow(
|
||||
ex,
|
||||
|
|
@ -103,15 +94,14 @@ impl OpenCADStudio {
|
|||
)
|
||||
},
|
||||
),
|
||||
super::super::ModalKind::FindReplace => sized(
|
||||
super::super::ModalKind::FindReplace => automatic_flow(ex, |flow| {
|
||||
crate::ui::window::find_replace::view_window(
|
||||
&self.find_replace.search,
|
||||
&self.find_replace.replacement,
|
||||
&self.find_replace.status,
|
||||
),
|
||||
560,
|
||||
190,
|
||||
),
|
||||
flow,
|
||||
)
|
||||
}),
|
||||
super::super::ModalKind::PluginManager => {
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
{
|
||||
|
|
@ -149,11 +139,12 @@ impl OpenCADStudio {
|
|||
}
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
{
|
||||
sized(
|
||||
crate::ui::window::plugin_manager::view_web_notice(),
|
||||
self.web_plugin_notice_width(),
|
||||
230,
|
||||
)
|
||||
automatic_flow(ex, |flow| {
|
||||
container(crate::ui::window::plugin_manager::view_web_notice())
|
||||
.width(flow.width)
|
||||
.height(flow.height)
|
||||
.into()
|
||||
})
|
||||
}
|
||||
}
|
||||
super::super::ModalKind::UpdateNotice => {
|
||||
|
|
@ -228,13 +219,13 @@ impl OpenCADStudio {
|
|||
},
|
||||
)
|
||||
} else {
|
||||
sized(
|
||||
automatic_flow(ex, |flow| {
|
||||
container(text("The selected layer state is no longer available."))
|
||||
.padding(16)
|
||||
.into(),
|
||||
520,
|
||||
180,
|
||||
)
|
||||
.width(flow.width)
|
||||
.height(flow.height)
|
||||
.into()
|
||||
})
|
||||
}
|
||||
}
|
||||
super::super::ModalKind::Plot => {
|
||||
|
|
@ -764,7 +755,9 @@ impl OpenCADStudio {
|
|||
)
|
||||
})
|
||||
}
|
||||
super::super::ModalKind::AssocPrompt => sized(default_assoc_dialog_window(), 440, 210),
|
||||
super::super::ModalKind::AssocPrompt => {
|
||||
automatic_flow(ex, default_assoc_dialog_window)
|
||||
}
|
||||
super::super::ModalKind::AecDropWarning => {
|
||||
let src_label = self
|
||||
.tabs
|
||||
|
|
@ -788,15 +781,14 @@ impl OpenCADStudio {
|
|||
crate::io::format_for_version(version, is_dxf)
|
||||
})
|
||||
.unwrap_or_else(|| "DWG".to_string());
|
||||
sized(
|
||||
automatic_flow(ex, |flow| {
|
||||
aec_drop_dialog_window(
|
||||
self.aec_drop_count,
|
||||
&self.save_dialog_format,
|
||||
&src_label,
|
||||
),
|
||||
480,
|
||||
230,
|
||||
)
|
||||
flow,
|
||||
)
|
||||
})
|
||||
}
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
super::super::ModalKind::FileInUse => {
|
||||
|
|
@ -810,7 +802,7 @@ impl OpenCADStudio {
|
|||
)
|
||||
})
|
||||
.unwrap_or_default();
|
||||
sized(file_in_use_dialog_window(&path, &error), 560, 250)
|
||||
automatic_flow(ex, |flow| file_in_use_dialog_window(&path, &error, flow))
|
||||
}
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
super::super::ModalKind::ExternalChange => {
|
||||
|
|
@ -819,14 +811,14 @@ impl OpenCADStudio {
|
|||
.as_ref()
|
||||
.map(|conflict| conflict.path.display().to_string())
|
||||
.unwrap_or_default();
|
||||
sized(external_change_dialog_window(&path), 620, 250)
|
||||
automatic_flow(ex, |flow| external_change_dialog_window(&path, flow))
|
||||
}
|
||||
super::super::ModalKind::LayerDeleteWarning => {
|
||||
let (names, count) = self
|
||||
.layer_delete_pending
|
||||
.clone()
|
||||
.unwrap_or_else(|| (Vec::new(), 0));
|
||||
sized(layer_delete_warning_window(&names, count), 440, 200)
|
||||
automatic_flow(ex, |flow| layer_delete_warning_window(&names, count, flow))
|
||||
}
|
||||
super::super::ModalKind::Unsaved => {
|
||||
let tab_name = match &self.pending_close {
|
||||
|
|
@ -843,7 +835,7 @@ impl OpenCADStudio {
|
|||
.unwrap_or_default(),
|
||||
None => String::new(),
|
||||
};
|
||||
sized(unsaved_changes_dialog_window(&tab_name), 420, 160)
|
||||
automatic_flow(ex, |flow| unsaved_changes_dialog_window(&tab_name, flow))
|
||||
}
|
||||
super::super::ModalKind::PointStyle => sized_flow(
|
||||
ex,
|
||||
|
|
@ -897,17 +889,13 @@ impl OpenCADStudio {
|
|||
)
|
||||
}
|
||||
super::super::ModalKind::SaveDialog => {
|
||||
// Native omits the file-name field (the OS dialog collects it),
|
||||
// so it stands shorter than the web build.
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
let h = 200;
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
let h = 150;
|
||||
sized(
|
||||
save_as_dialog_window(&self.save_dialog_filename, &self.save_dialog_format),
|
||||
420,
|
||||
h,
|
||||
)
|
||||
automatic_flow(ex, |flow| {
|
||||
save_as_dialog_window(
|
||||
&self.save_dialog_filename,
|
||||
&self.save_dialog_format,
|
||||
flow,
|
||||
)
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
@ -927,6 +915,18 @@ fn sized_flow<'a>(
|
|||
)
|
||||
}
|
||||
|
||||
fn automatic_flow<'a>(
|
||||
extra: iced::Vector,
|
||||
mut build: impl FnMut(crate::ui::modal::ModalSizing) -> Element<'a, Message>,
|
||||
) -> Element<'a, Message> {
|
||||
crate::ui::modal::intrinsic(
|
||||
build(crate::ui::modal::ModalSizing::INTRINSIC),
|
||||
build(crate::ui::modal::ModalSizing::FILL),
|
||||
iced::Size::new(f32::INFINITY, f32::INFINITY),
|
||||
extra,
|
||||
)
|
||||
}
|
||||
|
||||
fn dialog_button(
|
||||
label: &'static str,
|
||||
message: Message,
|
||||
|
|
@ -957,12 +957,21 @@ fn dialog_muted_text_style(theme: &Theme) -> iced::widget::text::Style {
|
|||
/// Compact Save-As options dialog: pick the format/version and a default file
|
||||
/// name. The destination folder and overwrite confirmation come from the
|
||||
/// native OS save dialog (native) or the browser download (web) that follows.
|
||||
fn save_as_dialog_window<'a>(filename: &'a str, format: &'a str) -> Element<'a, Message> {
|
||||
fn save_as_dialog_window<'a>(
|
||||
filename: &'a str,
|
||||
format: &'a str,
|
||||
sizing: crate::ui::modal::ModalSizing,
|
||||
) -> Element<'a, Message> {
|
||||
let sel_fmt = crate::io::SAVE_FORMAT_OPTIONS
|
||||
.iter()
|
||||
.copied()
|
||||
.find(|&s| s == format);
|
||||
let label = |s: &'static str| text(s).size(11).style(dialog_muted_text_style);
|
||||
let field_width = if matches!(sizing.width, iced::Length::Fill) {
|
||||
Fill
|
||||
} else {
|
||||
iced::Length::Shrink
|
||||
};
|
||||
|
||||
let mut items: Vec<Element<'a, Message>> = Vec::new();
|
||||
items.push(text("Save Drawing As").size(14).into());
|
||||
|
|
@ -979,10 +988,11 @@ fn save_as_dialog_window<'a>(filename: &'a str, format: &'a str) -> Element<'a,
|
|||
.on_input(Message::SaveDialogFilenameChanged)
|
||||
.size(13)
|
||||
.padding([5, 8])
|
||||
.width(Fit),
|
||||
.width(field_width),
|
||||
]
|
||||
.align_y(iced::Alignment::Center)
|
||||
.spacing(6)
|
||||
.width(sizing.width)
|
||||
.into(),
|
||||
);
|
||||
items.push(Space::new().height(8).into());
|
||||
|
|
@ -999,10 +1009,11 @@ fn save_as_dialog_window<'a>(filename: &'a str, format: &'a str) -> Element<'a,
|
|||
|value| value.to_string(),
|
||||
)
|
||||
.on_select(|s: &str| Message::SaveDialogFormatChanged(s.to_string()))
|
||||
.width(Fit),
|
||||
.width(field_width),
|
||||
]
|
||||
.align_y(iced::Alignment::Center)
|
||||
.spacing(6)
|
||||
.width(sizing.width)
|
||||
.into(),
|
||||
);
|
||||
items.push(Space::new().height(16).into());
|
||||
|
|
@ -1016,17 +1027,23 @@ fn save_as_dialog_window<'a>(filename: &'a str, format: &'a str) -> Element<'a,
|
|||
.into(),
|
||||
);
|
||||
|
||||
let body = column(items).spacing(0);
|
||||
let body = column(items)
|
||||
.spacing(0)
|
||||
.width(sizing.width)
|
||||
.height(sizing.height);
|
||||
|
||||
container(body)
|
||||
.style(dialog_body_style)
|
||||
.padding([14, 16])
|
||||
.width(Fit)
|
||||
.height(Fit)
|
||||
.width(sizing.width)
|
||||
.height(sizing.height)
|
||||
.into()
|
||||
}
|
||||
|
||||
fn unsaved_changes_dialog_window(name: &str) -> Element<'static, Message> {
|
||||
fn unsaved_changes_dialog_window(
|
||||
name: &str,
|
||||
sizing: crate::ui::modal::ModalSizing,
|
||||
) -> Element<'static, Message> {
|
||||
let body_text = format!("Do you want to save changes to \"{}\"?", name);
|
||||
|
||||
container(
|
||||
|
|
@ -1044,13 +1061,18 @@ fn unsaved_changes_dialog_window(name: &str) -> Element<'static, Message> {
|
|||
.spacing(0),
|
||||
)
|
||||
.style(dialog_body_style)
|
||||
.center(Fit)
|
||||
.center_x(sizing.width)
|
||||
.center_y(sizing.height)
|
||||
.padding([24, 28])
|
||||
.into()
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn file_in_use_dialog_window(path: &str, error: &str) -> Element<'static, Message> {
|
||||
fn file_in_use_dialog_window(
|
||||
path: &str,
|
||||
error: &str,
|
||||
sizing: crate::ui::modal::ModalSizing,
|
||||
) -> Element<'static, Message> {
|
||||
let file_name = std::path::Path::new(path)
|
||||
.file_name()
|
||||
.map(|name| name.to_string_lossy().into_owned())
|
||||
|
|
@ -1098,13 +1120,16 @@ fn file_in_use_dialog_window(path: &str, error: &str) -> Element<'static, Messag
|
|||
)
|
||||
.style(dialog_body_style)
|
||||
.padding([18, 20])
|
||||
.width(Fit)
|
||||
.height(Fit)
|
||||
.width(sizing.width)
|
||||
.height(sizing.height)
|
||||
.into()
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn external_change_dialog_window(path: &str) -> Element<'static, Message> {
|
||||
fn external_change_dialog_window(
|
||||
path: &str,
|
||||
sizing: crate::ui::modal::ModalSizing,
|
||||
) -> Element<'static, Message> {
|
||||
let file_name = std::path::Path::new(path)
|
||||
.file_name()
|
||||
.map(|name| name.to_string_lossy().into_owned())
|
||||
|
|
@ -1155,8 +1180,8 @@ fn external_change_dialog_window(path: &str) -> Element<'static, Message> {
|
|||
)
|
||||
.style(dialog_body_style)
|
||||
.padding([18, 20])
|
||||
.width(Fit)
|
||||
.height(Fit)
|
||||
.width(sizing.width)
|
||||
.height(sizing.height)
|
||||
.into()
|
||||
}
|
||||
|
||||
|
|
@ -1164,7 +1189,12 @@ fn external_change_dialog_window(path: &str) -> Element<'static, Message> {
|
|||
/// (AEC / application) objects that survive only as verbatim source-version
|
||||
/// bytes, so saving to a different version or to DXF would drop them. Offers to
|
||||
/// save in the source version (keep them) or proceed (drop them).
|
||||
fn aec_drop_dialog_window(count: usize, target: &str, src_version: &str) -> Element<'static, Message> {
|
||||
fn aec_drop_dialog_window(
|
||||
count: usize,
|
||||
target: &str,
|
||||
src_version: &str,
|
||||
sizing: crate::ui::modal::ModalSizing,
|
||||
) -> Element<'static, Message> {
|
||||
let body_text = format!(
|
||||
"This drawing contains {count} AEC/Civil objects that \"{target}\" \
|
||||
cannot store, so they will not be saved.\n\n\
|
||||
|
|
@ -1190,7 +1220,8 @@ fn aec_drop_dialog_window(count: usize, target: &str, src_version: &str) -> Elem
|
|||
.spacing(0),
|
||||
)
|
||||
.style(dialog_body_style)
|
||||
.center(Fit)
|
||||
.center_x(sizing.width)
|
||||
.center_y(sizing.height)
|
||||
.padding([24, 28])
|
||||
.into()
|
||||
}
|
||||
|
|
@ -1199,7 +1230,11 @@ fn aec_drop_dialog_window(count: usize, target: &str, src_version: &str) -> Elem
|
|||
/// target folder. "Replace" overwrites; "Cancel" returns to the Save dialog.
|
||||
/// Confirm deleting layer(s) that still have objects on them. "Delete Objects"
|
||||
/// erases them and removes the layers; "Cancel" leaves everything.
|
||||
fn layer_delete_warning_window(names: &[String], count: usize) -> Element<'static, Message> {
|
||||
fn layer_delete_warning_window(
|
||||
names: &[String],
|
||||
count: usize,
|
||||
sizing: crate::ui::modal::ModalSizing,
|
||||
) -> Element<'static, Message> {
|
||||
let obj = if count == 1 { "object" } else { "objects" };
|
||||
let subject = if names.len() == 1 {
|
||||
format!("Layer \"{}\"", names[0])
|
||||
|
|
@ -1229,7 +1264,8 @@ fn layer_delete_warning_window(names: &[String], count: usize) -> Element<'stati
|
|||
.spacing(0),
|
||||
)
|
||||
.style(dialog_body_style)
|
||||
.center(Fit)
|
||||
.center_x(sizing.width)
|
||||
.center_y(sizing.height)
|
||||
.padding([24, 28])
|
||||
.into()
|
||||
}
|
||||
|
|
@ -1238,7 +1274,9 @@ fn layer_delete_warning_window(names: &[String], count: usize) -> Element<'stati
|
|||
/// handler for .dwg / .dxf. "Yes" runs the platform association call; "Not now"
|
||||
/// just dismisses. Either answer flips the persisted `default_assoc_prompted`
|
||||
/// flag so the dialog never reappears.
|
||||
fn default_assoc_dialog_window() -> Element<'static, Message> {
|
||||
fn default_assoc_dialog_window(
|
||||
sizing: crate::ui::modal::ModalSizing,
|
||||
) -> Element<'static, Message> {
|
||||
container(
|
||||
column![
|
||||
text("Make Open CAD Studio your default CAD app?")
|
||||
|
|
@ -1263,7 +1301,8 @@ fn default_assoc_dialog_window() -> Element<'static, Message> {
|
|||
.spacing(0),
|
||||
)
|
||||
.style(dialog_body_style)
|
||||
.center(Fit)
|
||||
.center_x(sizing.width)
|
||||
.center_y(sizing.height)
|
||||
.padding([24, 28])
|
||||
.into()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -81,9 +81,10 @@ const MTEXT_FONTS: [&str; 10] = [
|
|||
/// world XY plane; the program fits + vertically flips them into the box.
|
||||
pub(in crate::app) const MTEXT_PREVIEW_PAD: f32 = 12.0;
|
||||
pub(in crate::app) const MTEXT_PREVIEW_EM_PX: f32 = 15.0;
|
||||
pub(in crate::app) const MTEXT_EDITOR_BASE_WIDTH: f32 = 660.0;
|
||||
// Used only until the shared modal sensor reports the first real layout width.
|
||||
const MTEXT_EDITOR_FALLBACK_WIDTH: f32 = 660.0;
|
||||
pub(in crate::app) const MTEXT_EDITOR_WRITING_WIDTH: f32 =
|
||||
MTEXT_EDITOR_BASE_WIDTH - 2.0 * MTEXT_PREVIEW_PAD;
|
||||
MTEXT_EDITOR_FALLBACK_WIDTH - 2.0 * MTEXT_PREVIEW_PAD;
|
||||
|
||||
struct MTextPreview {
|
||||
/// Disconnected polylines as (x, y) world points + colour (NaN-split done).
|
||||
|
|
@ -334,13 +335,59 @@ fn mtext_preview_segments(
|
|||
pub(super) fn mtext_editor_overlay<'a>(
|
||||
ed: &'a super::super::mtext_editor::MTextEditorState,
|
||||
styles: Vec<String>,
|
||||
canvas_size: (f32, f32),
|
||||
modal_offset: iced::Vector,
|
||||
modal_resize: iced::Vector,
|
||||
modal_content_size: Option<iced::Size>,
|
||||
) -> Element<'a, Message> {
|
||||
let writing_area_px = modal_content_size
|
||||
.map(|size| size.width - 2.0 * MTEXT_PREVIEW_PAD)
|
||||
.unwrap_or(MTEXT_EDITOR_WRITING_WIDTH)
|
||||
.max(80.0);
|
||||
let measurement = mtext_editor_content(
|
||||
ed,
|
||||
&styles,
|
||||
crate::ui::modal::ModalSizing::INTRINSIC,
|
||||
writing_area_px,
|
||||
(writing_area_px * 0.5).max(1.0),
|
||||
);
|
||||
let content = mtext_editor_content(
|
||||
ed,
|
||||
&styles,
|
||||
crate::ui::modal::ModalSizing::FILL,
|
||||
writing_area_px,
|
||||
(writing_area_px * 0.5).max(1.0),
|
||||
);
|
||||
let content = crate::ui::modal::intrinsic(
|
||||
measurement,
|
||||
content,
|
||||
iced::Size::INFINITE,
|
||||
modal_resize,
|
||||
);
|
||||
|
||||
crate::ui::modal::modal(
|
||||
iced::widget::Space::new().width(Fill).height(Fill),
|
||||
"Text Editor",
|
||||
content,
|
||||
Message::MTextCancel,
|
||||
modal_offset,
|
||||
crate::ui::modal::ModalOptions::STANDARD,
|
||||
)
|
||||
}
|
||||
|
||||
fn mtext_editor_content<'a>(
|
||||
ed: &'a super::super::mtext_editor::MTextEditorState,
|
||||
styles: &[String],
|
||||
sizing: crate::ui::modal::ModalSizing,
|
||||
writing_area_px: f32,
|
||||
intrinsic_preview_height: f32,
|
||||
) -> Element<'a, Message> {
|
||||
let sizing = crate::ui::modal::ModalSizing::from_resize(modal_resize);
|
||||
let width = sizing.width;
|
||||
let height = sizing.height;
|
||||
let preview_height = if matches!(height, iced::Length::Fill) {
|
||||
iced::Length::Fill
|
||||
} else {
|
||||
iced::Length::Fixed(intrinsic_preview_height)
|
||||
};
|
||||
use super::super::mtext_editor::{JustifyChoice, MTextFmt, ParaAlign};
|
||||
use iced::widget::canvas;
|
||||
|
||||
|
|
@ -387,7 +434,7 @@ pub(super) fn mtext_editor_overlay<'a>(
|
|||
let style_opts: Vec<String> = if styles.is_empty() {
|
||||
vec!["Standard".to_string()]
|
||||
} else {
|
||||
styles
|
||||
styles.to_vec()
|
||||
};
|
||||
let style_pl = iced::widget::pick_list(
|
||||
Some(ed.style.clone()),
|
||||
|
|
@ -524,8 +571,6 @@ pub(super) fn mtext_editor_overlay<'a>(
|
|||
.align_y(iced::Alignment::Center)
|
||||
.width(width);
|
||||
|
||||
let writing_area_px =
|
||||
(MTEXT_EDITOR_BASE_WIDTH + modal_resize.x - 2.0 * MTEXT_PREVIEW_PAD).max(80.0);
|
||||
let preview_scale = ed.preview_scale();
|
||||
let slider_min = 1e-6_f64;
|
||||
let slider_max =
|
||||
|
|
@ -533,10 +578,10 @@ pub(super) fn mtext_editor_overlay<'a>(
|
|||
let width_slider = column![
|
||||
row![
|
||||
text(format!("Width: {:.3}", ed.rect_width)).size(11),
|
||||
Space::new().width(Fill),
|
||||
Space::new().width(width),
|
||||
text(format!("{:.0}%", ed.rect_width / slider_max * 100.0)).size(11),
|
||||
]
|
||||
.width(Fill),
|
||||
.width(width),
|
||||
container(
|
||||
iced::widget::slider(
|
||||
slider_min..=slider_max,
|
||||
|
|
@ -544,10 +589,10 @@ pub(super) fn mtext_editor_overlay<'a>(
|
|||
Message::MTextRectWidth,
|
||||
)
|
||||
.step((slider_max * 0.01).max(1e-6))
|
||||
.width(Fill),
|
||||
.width(width),
|
||||
)
|
||||
.padding([0.0, MTEXT_PREVIEW_PAD])
|
||||
.width(Fill),
|
||||
.width(width),
|
||||
]
|
||||
.spacing(2)
|
||||
.width(width);
|
||||
|
|
@ -555,7 +600,29 @@ pub(super) fn mtext_editor_overlay<'a>(
|
|||
// ── Body: the rendered preview (the editor is preview-only). It fills the
|
||||
// space left by the toolbars, so the resizable modal's extra height flows
|
||||
// into the text area. ─────────────────────────────────────────────────
|
||||
let body: Element<'a, Message> = {
|
||||
let body: Element<'a, Message> = if !matches!(height, iced::Length::Fill) {
|
||||
// The preview is a flexible scroll viewport. Measuring its real canvas
|
||||
// would make long/wide MText dictate the dialog size, so the intrinsic
|
||||
// pass uses an empty viewport proxy. The toolbars alone determine its
|
||||
// width; the preview height follows that measured writing width.
|
||||
container(Space::new())
|
||||
.style(move |theme: &Theme| {
|
||||
let palette = theme.palette();
|
||||
container::Style {
|
||||
background: Some(Background::Color(palette.background.base.color)),
|
||||
border: Border {
|
||||
color: palette.background.neutral.color,
|
||||
width: 1.0,
|
||||
radius: 3.0.into(),
|
||||
},
|
||||
..Default::default()
|
||||
}
|
||||
})
|
||||
.padding(2)
|
||||
.width(width)
|
||||
.height(preview_height)
|
||||
.into()
|
||||
} else {
|
||||
let segments = mtext_preview_segments(ed);
|
||||
let (mut minx, mut miny, mut maxx, mut maxy) = (f32::MAX, f32::MAX, f32::MIN, f32::MIN);
|
||||
for (seg, _, _) in &segments {
|
||||
|
|
@ -616,7 +683,7 @@ pub(super) fn mtext_editor_overlay<'a>(
|
|||
horizontal: Scrollbar::default(),
|
||||
})
|
||||
.width(width)
|
||||
.height(height),
|
||||
.height(preview_height),
|
||||
)
|
||||
.style(move |theme: &Theme| {
|
||||
let palette = theme.palette();
|
||||
|
|
@ -632,7 +699,7 @@ pub(super) fn mtext_editor_overlay<'a>(
|
|||
})
|
||||
.padding(2)
|
||||
.width(width)
|
||||
.height(height)
|
||||
.height(preview_height)
|
||||
.into()
|
||||
};
|
||||
|
||||
|
|
@ -655,30 +722,15 @@ pub(super) fn mtext_editor_overlay<'a>(
|
|||
.width(width)
|
||||
.padding([5, 8]);
|
||||
|
||||
// The shared modal frame supplies the panel background, drag title bar,
|
||||
// ✕ (which also cancels) and the resize grip. Iced 0.15 measures this
|
||||
// content first and clamps it to the user-growable maximum.
|
||||
let content = container(
|
||||
container(
|
||||
column![action_bar, row1, row2, width_slider, body]
|
||||
.spacing(6)
|
||||
.width(width)
|
||||
.height(height),
|
||||
)
|
||||
.width(iced::Length::Fit.max(MTEXT_EDITOR_BASE_WIDTH + modal_resize.x))
|
||||
.height(iced::Length::Fit.max(480.0 + modal_resize.y));
|
||||
|
||||
let _ = canvas_size; // positioned & sized by the modal frame now
|
||||
// `modal` sizes its stack from the base layer, so the base must fill the
|
||||
// area (a zero-size base collapses the whole overlay to nothing). The
|
||||
// transparent fill lets the dimmed viewport show through beneath.
|
||||
crate::ui::modal::modal(
|
||||
iced::widget::Space::new().width(Fill).height(Fill),
|
||||
"Text Editor",
|
||||
content,
|
||||
Message::MTextCancel,
|
||||
modal_offset,
|
||||
crate::ui::modal::ModalOptions::STANDARD,
|
||||
)
|
||||
.width(width)
|
||||
.height(height)
|
||||
.into()
|
||||
}
|
||||
|
||||
// ── Viewport right-click context menu ──────────────────────────────────────
|
||||
|
|
@ -944,6 +996,43 @@ pub(super) fn qselect_overlay<'a>(
|
|||
state: &'a crate::app::QSelectState,
|
||||
types: &[String],
|
||||
properties: &[(String, String)],
|
||||
modal_offset: iced::Vector,
|
||||
modal_resize: iced::Vector,
|
||||
) -> Element<'a, Message> {
|
||||
let measurement = qselect_content(
|
||||
state,
|
||||
types,
|
||||
properties,
|
||||
crate::ui::modal::ModalSizing::INTRINSIC,
|
||||
);
|
||||
let content = qselect_content(
|
||||
state,
|
||||
types,
|
||||
properties,
|
||||
crate::ui::modal::ModalSizing::FILL,
|
||||
);
|
||||
let content = crate::ui::modal::intrinsic(
|
||||
measurement,
|
||||
content,
|
||||
iced::Size::INFINITE,
|
||||
modal_resize,
|
||||
);
|
||||
|
||||
crate::ui::modal::modal(
|
||||
Space::new().width(Fill).height(Fill),
|
||||
"Quick Select",
|
||||
content,
|
||||
Message::QSelectClose,
|
||||
modal_offset,
|
||||
crate::ui::modal::ModalOptions::STANDARD,
|
||||
)
|
||||
}
|
||||
|
||||
fn qselect_content<'a>(
|
||||
state: &'a crate::app::QSelectState,
|
||||
types: &[String],
|
||||
properties: &[(String, String)],
|
||||
sizing: crate::ui::modal::ModalSizing,
|
||||
) -> Element<'a, Message> {
|
||||
use iced::widget::{checkbox};
|
||||
let mut type_options: Vec<String> = vec![QSELECT_ANY_TYPE.to_string()];
|
||||
|
|
@ -986,6 +1075,11 @@ pub(super) fn qselect_overlay<'a>(
|
|||
// operator is "*Any value" — both of those skip the value test.
|
||||
let value_enabled =
|
||||
state.property.is_some() && !matches!(state.operator, crate::app::QSelectOp::Any);
|
||||
let field_width = if matches!(sizing.width, iced::Length::Fill) {
|
||||
Fill
|
||||
} else {
|
||||
iced::Length::Shrink
|
||||
};
|
||||
|
||||
let label = |s: &'static str| {
|
||||
text(s)
|
||||
|
|
@ -1021,14 +1115,14 @@ pub(super) fn qselect_overlay<'a>(
|
|||
.padding([4, 14])
|
||||
};
|
||||
|
||||
let mut value_input = text_input("", &state.value).size(12);
|
||||
let mut value_input = text_input("", &state.value)
|
||||
.size(12)
|
||||
.width(field_width);
|
||||
if value_enabled {
|
||||
value_input = value_input.on_input(Message::QSelectSetValue);
|
||||
}
|
||||
|
||||
let panel_body = column![
|
||||
text("Quick Select").size(14),
|
||||
Space::new().height(10),
|
||||
row![
|
||||
label("Object type:"),
|
||||
iced::widget::pick_list(
|
||||
|
|
@ -1043,10 +1137,11 @@ pub(super) fn qselect_overlay<'a>(
|
|||
Message::QSelectSetType(Some(s))
|
||||
}
|
||||
})
|
||||
.width(Fill),
|
||||
.width(field_width),
|
||||
]
|
||||
.align_y(iced::Alignment::Center)
|
||||
.spacing(8),
|
||||
.spacing(8)
|
||||
.width(sizing.width),
|
||||
Space::new().height(6),
|
||||
row![
|
||||
label("Property:"),
|
||||
|
|
@ -1062,10 +1157,11 @@ pub(super) fn qselect_overlay<'a>(
|
|||
Message::QSelectSetProperty(Some(p))
|
||||
}
|
||||
})
|
||||
.width(Fill),
|
||||
.width(field_width),
|
||||
]
|
||||
.align_y(iced::Alignment::Center)
|
||||
.spacing(8),
|
||||
.spacing(8)
|
||||
.width(sizing.width),
|
||||
Space::new().height(6),
|
||||
row![
|
||||
label("Operator:"),
|
||||
|
|
@ -1075,14 +1171,16 @@ pub(super) fn qselect_overlay<'a>(
|
|||
|value| value.to_string(),
|
||||
)
|
||||
.on_select(Message::QSelectSetOperator)
|
||||
.width(Fill),
|
||||
.width(field_width),
|
||||
]
|
||||
.align_y(iced::Alignment::Center)
|
||||
.spacing(8),
|
||||
.spacing(8)
|
||||
.width(sizing.width),
|
||||
Space::new().height(6),
|
||||
row![label("Value:"), value_input,]
|
||||
.align_y(iced::Alignment::Center)
|
||||
.spacing(8),
|
||||
.spacing(8)
|
||||
.width(sizing.width),
|
||||
Space::new().height(10),
|
||||
row![
|
||||
checkbox(state.append)
|
||||
|
|
@ -1094,18 +1192,21 @@ pub(super) fn qselect_overlay<'a>(
|
|||
.align_y(iced::Alignment::Center),
|
||||
Space::new().height(14),
|
||||
row![
|
||||
Space::new().width(Fill),
|
||||
Space::new().width(field_width),
|
||||
btn("Cancel", Message::QSelectClose, false),
|
||||
Space::new().width(8),
|
||||
btn("Apply", Message::QSelectApply, true),
|
||||
]
|
||||
.align_y(iced::Alignment::Center),
|
||||
]
|
||||
.spacing(0);
|
||||
.spacing(0)
|
||||
.width(sizing.width)
|
||||
.height(sizing.height);
|
||||
|
||||
let panel = container(panel_body)
|
||||
.padding(16)
|
||||
.width(iced::Length::Fixed(400.0))
|
||||
.width(sizing.width)
|
||||
.height(sizing.height)
|
||||
.style(|theme: &Theme| {
|
||||
let palette = theme.palette();
|
||||
container::Style {
|
||||
|
|
@ -1119,18 +1220,5 @@ pub(super) fn qselect_overlay<'a>(
|
|||
}
|
||||
});
|
||||
|
||||
// Outside-click catcher — fills the whole screen, sits below the
|
||||
// panel. The panel itself is rendered above and absorbs its own
|
||||
// clicks via standard widget event handling.
|
||||
let catcher = mouse_area(
|
||||
container(iced::widget::Space::new().width(Fill).height(Fill))
|
||||
.width(Fill)
|
||||
.height(Fill),
|
||||
)
|
||||
.on_press(Message::QSelectClose)
|
||||
.on_right_press(Message::QSelectClose);
|
||||
|
||||
let centered = container(iced::widget::opaque(panel)).center(Fill);
|
||||
|
||||
stack![catcher, centered].into()
|
||||
panel.into()
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue