mirror of https://github.com/lapce/lapce.git
consolidate window desc creation
This commit is contained in:
parent
9808f2e32d
commit
d793594a62
|
@ -41,11 +41,44 @@ pub fn launch() {
|
||||||
let data = LapceData::load(launcher.get_external_handle());
|
let data = LapceData::load(launcher.get_external_handle());
|
||||||
for (_window_id, window_data) in data.windows.iter() {
|
for (_window_id, window_data) in data.windows.iter() {
|
||||||
let root = build_window(window_data);
|
let root = build_window(window_data);
|
||||||
let window = WindowDesc::new_with_id(window_data.window_id, root)
|
let window = new_window_desc(
|
||||||
|
window_data.window_id,
|
||||||
|
root,
|
||||||
|
window_data.size,
|
||||||
|
window_data.pos,
|
||||||
|
);
|
||||||
|
launcher = launcher.with_window(window);
|
||||||
|
}
|
||||||
|
|
||||||
|
let launcher = launcher.configure_env(|env, data| data.reload_env(env));
|
||||||
|
launcher.launch(data).expect("launch failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
fn new_window_desc<W, T: druid::Data>(
|
||||||
|
window_id: WindowId,
|
||||||
|
root: W,
|
||||||
|
size: Size,
|
||||||
|
pos: Point,
|
||||||
|
) -> WindowDesc<T>
|
||||||
|
where
|
||||||
|
W: Widget<T> + 'static,
|
||||||
|
{
|
||||||
|
let mut desc = WindowDesc::new_with_id(window_id, root)
|
||||||
.title(LocalizedString::new("Lapce").with_placeholder("Lapce"))
|
.title(LocalizedString::new("Lapce").with_placeholder("Lapce"))
|
||||||
.show_titlebar(false)
|
.window_size(size)
|
||||||
.window_size(window_data.size)
|
.set_position(pos);
|
||||||
.menu(|_, _, _| {
|
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
if true {
|
||||||
|
desc = macos_window_desc(desc);
|
||||||
|
}
|
||||||
|
|
||||||
|
desc
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
fn macos_window_desc<T: druid::Data>(desc: WindowDesc<T>) -> WindowDesc<T> {
|
||||||
|
desc.show_titlebar(false).menu(|_, _, _| {
|
||||||
Menu::new("Lapce").entry(
|
Menu::new("Lapce").entry(
|
||||||
Menu::new("")
|
Menu::new("")
|
||||||
.entry(MenuItem::new("About Lapce"))
|
.entry(MenuItem::new("About Lapce"))
|
||||||
|
@ -63,12 +96,6 @@ pub fn launch() {
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.set_position(window_data.pos);
|
|
||||||
launcher = launcher.with_window(window);
|
|
||||||
}
|
|
||||||
|
|
||||||
let launcher = launcher.configure_env(|env, data| data.reload_env(env));
|
|
||||||
launcher.launch(data).expect("launch failed");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct LapceAppDelegate {}
|
struct LapceAppDelegate {}
|
||||||
|
@ -149,11 +176,7 @@ fn command(
|
||||||
let root = build_window(&window_data);
|
let root = build_window(&window_data);
|
||||||
let window_id = window_data.window_id;
|
let window_id = window_data.window_id;
|
||||||
data.windows.insert(window_id, window_data);
|
data.windows.insert(window_id, window_data);
|
||||||
let desc = WindowDesc::new_with_id(window_id, root)
|
let desc = new_window_desc(window_id, root, info.size, info.pos);
|
||||||
.title(LocalizedString::new("Lapce").with_placeholder("Lapce"))
|
|
||||||
.show_titlebar(false)
|
|
||||||
.window_size(info.size)
|
|
||||||
.set_position(info.pos);
|
|
||||||
ctx.new_window(desc);
|
ctx.new_window(desc);
|
||||||
return druid::Handled::Yes;
|
return druid::Handled::Yes;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue