use crate::{
Command, ROOT_ID,
desktop::{DesktopCommand, TitleBarStyle},
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 close(cx: &mut ModuleCx) {
desktop(cx, DesktopCommand::Close);
}
}