feat: Interface to setting window size in app.rs
@@ -44,6 +44,7 @@ type WidgetBuilderFn<T> = dyn Fn() -> Box<dyn Widget<T>> + 'static;
pub struct WindowDesc<T> {
pub(crate) root_builder: Arc<WidgetBuilderFn<T>>,
pub(crate) title: Option<LocalizedString<T>>,
+ pub(crate) size: Option<(f32, f32)>,
pub(crate) menu: Option<MenuDesc<T>>,
//TODO: more things you can configure on a window, like size?
}
@@ -125,6 +126,7 @@ impl<T: Data + 'static> WindowDesc<T> {
WindowDesc {
root_builder,
title: None,
+ size: None,
menu: MenuDesc::platform_default(),
}
}
@@ -138,6 +140,12 @@ impl<T: Data + 'static> WindowDesc<T> {
self
}
+ /// Set the window size at creation
+ pub fn window_size(mut self, width: f32, height: f32) -> Self {
+ self.size = Some((width, height));
+ self
+ }
+
/// Attempt to create a platform window from this `WindowDesc`.
pub(crate) fn build_native(
&self,
@@ -158,6 +166,9 @@ impl<T: Data + 'static> WindowDesc<T> {
let mut builder = WindowBuilder::new();
builder.set_handler(Box::new(handler));
+ if let Some((width, height)) = self.size {
+ builder.set_size(width, height);
+ }
builder.set_title(title.localized_str());
if let Some(menu) = platform_menu {
builder.set_menu(menu);
