mirror of
https://github.com/danbulant/appit
synced 2026-06-19 22:31:23 +00:00
Exposed WindowAttributes + mutability
WindowAttributes was previously used but not exposed. Additionally, a few new methods for setting the window title/position/size have been added.
This commit is contained in:
parent
1b5da400f3
commit
da03d41656
2 changed files with 53 additions and 7 deletions
|
|
@ -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<AppMessage>
|
||||
|
|
@ -275,8 +274,8 @@ impl<Message> Windows<Message> {
|
|||
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);
|
||||
|
|
|
|||
|
|
@ -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<ParentWindowEvent> {
|
||||
/// The inner size of the window.
|
||||
pub inner_size: Option<Size>,
|
||||
/// The minimum inner size of the window.
|
||||
pub min_inner_size: Option<Size>,
|
||||
/// The maximum inner size of the window.
|
||||
pub max_inner_size: Option<Size>,
|
||||
pub position: Option<Position>,
|
||||
/// The location of the top-left of the frame of the window.
|
||||
pub location: Option<Position>,
|
||||
/// 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<Fullscreen>,
|
||||
/// 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<Icon>,
|
||||
/// The window's preferred theme.
|
||||
pub preferred_theme: Option<Theme>,
|
||||
/// The increments in which the window will be allowed to resize by the user.
|
||||
pub resize_increments: Option<Size>,
|
||||
/// 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<Window<ParentWindowEvent>>,
|
||||
/// Whether the window is active or not.
|
||||
pub active: bool,
|
||||
}
|
||||
|
||||
|
|
@ -119,7 +145,7 @@ impl<User> Default for WindowAttributes<User> {
|
|||
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<u32> {
|
||||
self.inner_size
|
||||
}
|
||||
|
||||
/// Sets the inner size of the window, in pixels.
|
||||
pub fn set_inner_size(&self, new_size: PhysicalSize<u32>) {
|
||||
self.window.set_inner_size(new_size);
|
||||
}
|
||||
|
||||
/// Returns the current location of the window, in pixels.
|
||||
#[must_use]
|
||||
pub const fn location(&self) -> PhysicalPosition<i32> {
|
||||
self.location
|
||||
}
|
||||
|
||||
/// Sets the current location of the window, in pixels.
|
||||
pub fn set_location(&self, new_location: PhysicalPosition<i32>) {
|
||||
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]
|
||||
|
|
|
|||
Loading…
Reference in a new issue