diff --git a/src/lib.rs b/src/lib.rs index 4a2485e..dd24d92 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,7 +9,7 @@ mod window; pub use winit; use raw_window_handle::HasRawWindowHandle; -pub use window::{RunningWindow, Window, WindowBehavior, WindowBuilder}; +pub use window::{RunningWindow, Window, WindowAttributes, WindowBehavior, WindowBuilder}; use winit::error::OsError; use winit::window::WindowId; @@ -20,7 +20,6 @@ use winit::event_loop::{ControlFlow, EventLoopBuilder, EventLoopProxy, EventLoop use winit::{event::Event, event_loop::EventLoop}; use crate::private::{EventLoopMessage, WindowEvent, WindowMessage}; -use crate::window::WindowAttributes; /// An application that is not yet running. pub struct PendingApp @@ -275,8 +274,8 @@ impl Windows { if let Some(max_inner_size) = attrs.max_inner_size { builder = builder.with_max_inner_size(max_inner_size); } - if let Some(position) = attrs.position { - builder = builder.with_position(position); + if let Some(location) = attrs.location { + builder = builder.with_position(location); } if let Some(resize_increments) = attrs.resize_increments { builder = builder.with_resize_increments(resize_increments); diff --git a/src/window.rs b/src/window.rs index 90be4f0..e59738c 100644 --- a/src/window.rs +++ b/src/window.rs @@ -89,26 +89,52 @@ where } } +/// Attributes of a desktop window. +/// +/// This structure is equivalent to [`winit::window::WindowAttributes`] except +/// that `parent_window` accepts a [`Window`] rather than relying on raw window +/// handle. #[allow(clippy::struct_excessive_bools)] pub struct WindowAttributes { + /// The inner size of the window. pub inner_size: Option, + /// The minimum inner size of the window. pub min_inner_size: Option, + /// The maximum inner size of the window. pub max_inner_size: Option, - pub position: Option, + /// The location of the top-left of the frame of the window. + pub location: Option, + /// If true, the window can be resized by the user. pub resizable: bool, + /// The collection of window buttons that are enabled. pub enabled_buttons: WindowButtons, + /// The title of the window. pub title: String, + /// The full screen configuration for the window. pub fullscreen: Option, + /// The maximized state of the window. pub maximized: bool, + /// The visibility state of the window. pub visible: bool, + /// If true, the window's chrome will be hidden and only areas that have + /// been drawn to will be opaque. pub transparent: bool, + /// Controls the visibility of the window decorations. pub decorations: bool, + /// The window's icon. pub window_icon: Option, + /// The window's preferred theme. pub preferred_theme: Option, + /// The increments in which the window will be allowed to resize by the user. pub resize_increments: Option, + /// If true, the contents of the window will be prevented from being + /// captured by other applications when supported. pub content_protected: bool, + /// The level of the window. pub window_level: WindowLevel, + /// The parent window of this window. pub parent_window: Option>, + /// Whether the window is active or not. pub active: bool, } @@ -119,7 +145,7 @@ impl Default for WindowAttributes { inner_size: defaults.inner_size, min_inner_size: defaults.min_inner_size, max_inner_size: defaults.max_inner_size, - position: defaults.position, + location: defaults.position, resizable: defaults.resizable, enabled_buttons: defaults.enabled_buttons, title: defaults.title, @@ -170,7 +196,7 @@ where // by always using try_send. let (sender, receiver) = mpsc::sync_channel(1024); let Some(winit) = self.owner.open(self.attributes, sender.clone())? else { - return Ok(None) + return Ok(None); }; let window = Window { id: winit.id(), @@ -283,18 +309,39 @@ where self.redraw_at(Instant::now() + duration); } + /// Returns the current title of the window. + #[must_use] + pub fn title(&self) -> String { + self.window.title() + } + + /// Sets the window's title to `new_title`. + pub fn set_title(&mut self, new_title: &str) { + self.window.set_title(new_title); + } + /// Returns the current size of the interior of the window, in pixels. #[must_use] pub const fn inner_size(&self) -> PhysicalSize { self.inner_size } + /// Sets the inner size of the window, in pixels. + pub fn set_inner_size(&self, new_size: PhysicalSize) { + self.window.set_inner_size(new_size); + } + /// Returns the current location of the window, in pixels. #[must_use] pub const fn location(&self) -> PhysicalPosition { self.location } + /// Sets the current location of the window, in pixels. + pub fn set_location(&self, new_location: PhysicalPosition) { + self.window.set_outer_position(new_location); + } + /// Returns the location of the cursor relative to the window's upper-left /// corner, in pixels. #[must_use]