forked from 1b-agent/opencadstudio-upstream
Merge pull request #1353 from HakanSeven12/ui/options-ok-apply-close
feat(options): OK / Apply / Close with a discard guard # Conflicts: # src/app/view/modal.rs # src/ui/window/options.rs
This commit is contained in:
commit
1c0ef9d7a0
8 files changed
+365
-55
No files matched your search
@@ -2,7 +2,7 @@ use crate::app::settings::IsoPlane;
|
||||
use crate::app::Message;
|
||||
use crate::snap::{SnapType, ALL_3D_SNAP_MODES, ALL_SNAP_MODES};
|
||||
use iced::widget::{button, checkbox, column, container, row, scrollable, text, text_input, Space};
|
||||
use iced::{Background, Border, Element, Fill, Length, Theme};
|
||||
use iced::{Background, Border, Element, Fill, Theme};
|
||||
use std::borrow::Cow;
|
||||
|
||||
/// Active tab in the Drafting Settings dialog.
|
||||
@@ -717,51 +717,10 @@ pub fn view_window<'a>(
|
||||
if !close_confirm {
|
||||
return main_content.into();
|
||||
}
|
||||
|
||||
let shield = iced::widget::mouse_area(
|
||||
container(Space::new())
|
||||
.width(Length::Fill)
|
||||
.height(Length::Fill)
|
||||
.style(|theme: &Theme| container::Style {
|
||||
background: Some(Background::Color(
|
||||
theme
|
||||
.palette()
|
||||
.background
|
||||
.strongest
|
||||
.color
|
||||
.scale_alpha(0.55),
|
||||
)),
|
||||
..Default::default()
|
||||
}),
|
||||
)
|
||||
.on_press(Message::DraftingSettingsCloseKeep);
|
||||
|
||||
let warning_panel = container(
|
||||
column![
|
||||
text(crate::t!("Unsaved changes will be discarded.")).size(13.5),
|
||||
Space::new().height(12),
|
||||
row![
|
||||
button(text(crate::t!("Discard && close")).size(12))
|
||||
.on_press(Message::DraftingSettingsCloseDiscard)
|
||||
.padding([5, 14])
|
||||
.style(button::danger),
|
||||
button(text(crate::t!("Keep editing")).size(12))
|
||||
.on_press(Message::DraftingSettingsCloseKeep)
|
||||
.padding([5, 14])
|
||||
.style(button::secondary),
|
||||
]
|
||||
.spacing(10),
|
||||
]
|
||||
.spacing(0),
|
||||
)
|
||||
.padding([18, 22])
|
||||
.style(container::rounded_box);
|
||||
|
||||
iced::widget::stack![
|
||||
crate::ui::modal::discard_guard(
|
||||
main_content,
|
||||
shield,
|
||||
container(warning_panel).center_x(Fill).center_y(Fill)
|
||||
]
|
||||
.into()
|
||||
Message::DraftingSettingsCloseDiscard,
|
||||
Message::DraftingSettingsCloseKeep,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -212,6 +212,8 @@ pub fn view_window<'a>(
|
||||
paper_bg_input: &'a str,
|
||||
desk_bg_input: &'a str,
|
||||
bg_picker: Option<crate::app::BgTarget>,
|
||||
dirty: bool,
|
||||
close_confirm: bool,
|
||||
sizing: crate::ui::modal::ModalSizing,
|
||||
) -> Element<'a, Message> {
|
||||
let selected_format = crate::io::SAVE_FORMAT_OPTIONS
|
||||
@@ -311,8 +313,18 @@ pub fn view_window<'a>(
|
||||
);
|
||||
}
|
||||
|
||||
// Changes show at once but are committed by OK / Apply; Close puts them
|
||||
// back (asking first when there is something to lose).
|
||||
let ok = button(text(crate::t!("OK")).size(12))
|
||||
.on_press(Message::OptionsOk)
|
||||
.padding([6, 18])
|
||||
.style(button::primary);
|
||||
let apply = button(text(crate::t!("Apply")).size(12))
|
||||
.on_press_maybe(dirty.then_some(Message::OptionsApply))
|
||||
.padding([6, 18])
|
||||
.style(if dirty { button::secondary } else { button::text });
|
||||
let close = button(text(crate::tr!("action", "close")).size(12))
|
||||
.on_press(Message::CloseModal)
|
||||
.on_press(Message::OptionsClose)
|
||||
.padding([6, 18])
|
||||
.style(button::secondary);
|
||||
|
||||
@@ -1668,7 +1680,7 @@ pub fn view_window<'a>(
|
||||
// controls at the trailing edge of the Options content.
|
||||
scrollable(content).spacing(8).height(Fill),
|
||||
Space::new().height(12),
|
||||
row![Space::new().width(Fill), close],
|
||||
row![Space::new().width(Fill), ok, apply, close].spacing(8),
|
||||
]
|
||||
.width(Fill)
|
||||
.height(sizing.height);
|
||||
@@ -1678,10 +1690,13 @@ pub fn view_window<'a>(
|
||||
.height(sizing.height);
|
||||
|
||||
let intrinsic = sizing.width == crate::ui::modal::ModalSizing::INTRINSIC.width;
|
||||
container(body)
|
||||
let main = container(body)
|
||||
.style(container::rounded_box)
|
||||
.padding([16, 18])
|
||||
.width(if intrinsic { iced::Length::Fixed(DIALOG_WIDTH) } else { sizing.width })
|
||||
.height(if intrinsic { iced::Length::Fixed(DIALOG_HEIGHT) } else { sizing.height })
|
||||
.into()
|
||||
.height(if intrinsic { iced::Length::Fixed(DIALOG_HEIGHT) } else { sizing.height });
|
||||
if !close_confirm {
|
||||
return main.into();
|
||||
}
|
||||
crate::ui::modal::discard_guard(main, Message::OptionsCloseDiscard, Message::OptionsCloseKeep)
|
||||
}
|
||||
Reference in new issue
Block a user