Files
hcie-rust-v3.05/hcie-iced-app/crates/hcie-iced-gui/src/dialogs/confirm.rs
T

79 lines
2.4 KiB
Rust
Raw Normal View History

//! Confirm dialog — save/discard/cancel confirmation and selection operation parameter dialog.
use crate::app::Message;
use crate::theme::ThemeColors;
use crate::widgets::plain_slider::plain_slider;
use iced::widget::{column, horizontal_rule, row, text};
use iced::Element;
/// Build a confirmation dialog with save/discard/cancel.
pub fn close_confirm_view(doc_name: &str, colors: ThemeColors) -> Element<'static, Message> {
let msg = format!("\"{}\" has unsaved changes.", doc_name);
let save_btn = super::primary_btn("Save", Message::DialogCloseSave, colors);
let discard_btn = super::secondary_btn("Discard", Message::DialogCloseDiscard, colors);
let cancel_btn = super::secondary_btn("Cancel", Message::DialogClose, colors);
let dialog = column![
text("Unsaved Changes").size(16).font(iced::Font::MONOSPACE),
horizontal_rule(1),
text(msg).size(12),
horizontal_rule(1),
row![save_btn, discard_btn, cancel_btn].spacing(12),
]
.spacing(8)
.padding(16)
.width(400);
super::modal(dialog, colors)
}
/// Return the slider range and unit suffix for a selection operation.
fn selection_op_range(op: &str) -> (f32, f32, &'static str) {
match op {
"Erode" => (1.0, 50.0, "px"),
"Fade" => (0.0, 100.0, "radius"),
"Feather" => (0.0, 250.0, "px"),
"Border" => (1.0, 200.0, "px"),
_ => (1.0, 100.0, "px"),
}
}
/// Build a selection operation dialog (grow/shrink/feather/erode/fade).
pub fn selection_op_view(
op_name: &str,
value: f32,
_min: f32,
_max: f32,
colors: ThemeColors,
) -> Element<'static, Message> {
let op_owned = op_name.to_string();
let (range_min, range_max, unit) = selection_op_range(op_name);
let step = if unit == "radius" { 0.5 } else { 1.0 };
let value_slider = plain_slider(
&format!("Value ({})", unit),
value,
range_min..=range_max,
step,
"",
0,
|v| Message::SelectionOpValue(v),
);
let apply_btn = super::primary_btn("Apply", Message::SelectionOpApply, colors);
let cancel_btn = super::secondary_btn("Cancel", Message::DialogClose, colors);
let dialog = column![
text(op_owned).size(14).font(iced::Font::MONOSPACE),
horizontal_rule(1),
value_slider,
horizontal_rule(1),
row![apply_btn, cancel_btn].spacing(12),
]
.spacing(8)
.padding(16)
.width(350);
super::modal(dialog, colors)
}