use crate::{
Command, ROOT_ID,
desktop::{DesktopCommand, TitleBarStyle, WindowFrame, WindowLevel},
ui::{ModuleCx, module, task::Action},
};
fn desktop(cx: &mut ModuleCx, command: DesktopCommand) {
cx.act(Action::Command(
ROOT_ID,
Command::Desktop(Box::new(command)),
));
}
pub(crate) struct Window;
#[module]
impl Window {
pub(crate) fn set_title(title: String, cx: &mut ModuleCx) {
desktop(cx, DesktopCommand::SetTitle(title));
}
pub(crate) fn set_title_bar(style: TitleBarStyle, height: Option<f32>, cx: &mut ModuleCx) {
let height = height
.filter(|h| h.is_finite() && *h > 0.0)
.map(|h| h.min(200.0));
desktop(cx, DesktopCommand::SetTitleBar { style, height });
}
pub(crate) fn minimize(cx: &mut ModuleCx) {
desktop(cx, DesktopCommand::Minimize);
}
pub(crate) fn toggle_maximize(cx: &mut ModuleCx) {
desktop(cx, DesktopCommand::ToggleMaximize);
}
pub(crate) fn toggle_full_screen(cx: &mut ModuleCx) {
desktop(cx, DesktopCommand::ToggleFullScreen);
}
pub(crate) fn set_frame(frame: WindowFrame, cx: &mut ModuleCx) {
let frame = WindowFrame {
x: frame.x.filter(|v| v.is_finite()),
y: frame.y.filter(|v| v.is_finite()),
width: frame.width.filter(|v| v.is_finite() && *v > 0.0),
height: frame.height.filter(|v| v.is_finite() && *v > 0.0),
animated: frame.animated,
};
desktop(cx, DesktopCommand::SetFrame(frame));
}
pub(crate) fn set_level(level: WindowLevel, cx: &mut ModuleCx) {
desktop(cx, DesktopCommand::SetLevel(level));
}
pub(crate) fn close(cx: &mut ModuleCx) {
desktop(cx, DesktopCommand::Close);
}
}