Merge pull request #929 from TimUntersberger/winit-improv
feat: add position to window settings
This commit is contained in:
commit
9cf5f3e1ef
8 changed files with 130 additions and 4 deletions
|
|
@ -1,9 +1,11 @@
|
|||
//! Configure the window of your application in native platforms.
|
||||
mod mode;
|
||||
mod position;
|
||||
mod settings;
|
||||
|
||||
pub mod icon;
|
||||
|
||||
pub use icon::Icon;
|
||||
pub use mode::Mode;
|
||||
pub use position::Position;
|
||||
pub use settings::Settings;
|
||||
|
|
|
|||
33
src/window/position.rs
Normal file
33
src/window/position.rs
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
/// The position of a window in a given screen.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum Position {
|
||||
/// The platform-specific default position for a new window.
|
||||
Default,
|
||||
/// The window is completely centered on the screen.
|
||||
Centered,
|
||||
/// The window is positioned with specific coordinates: `(X, Y)`.
|
||||
///
|
||||
/// When the decorations of the window are enabled, Windows 10 will add some
|
||||
/// invisible padding to the window. This padding gets included in the
|
||||
/// position. So if you have decorations enabled and want the window to be
|
||||
/// at (0, 0) you would have to set the position to
|
||||
/// `(PADDING_X, PADDING_Y)`.
|
||||
Specific(i32, i32),
|
||||
}
|
||||
|
||||
impl Default for Position {
|
||||
fn default() -> Self {
|
||||
Self::Default
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
impl From<Position> for iced_winit::Position {
|
||||
fn from(position: Position) -> Self {
|
||||
match position {
|
||||
Position::Default => Self::Default,
|
||||
Position::Centered => Self::Centered,
|
||||
Position::Specific(x, y) => Self::Specific(x, y),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
use crate::window::Icon;
|
||||
use crate::window::{Icon, Position};
|
||||
|
||||
/// The window settings of an application.
|
||||
#[derive(Debug, Clone)]
|
||||
|
|
@ -6,6 +6,9 @@ pub struct Settings {
|
|||
/// The initial size of the window.
|
||||
pub size: (u32, u32),
|
||||
|
||||
/// The initial position of the window.
|
||||
pub position: Position,
|
||||
|
||||
/// The minimum size of the window.
|
||||
pub min_size: Option<(u32, u32)>,
|
||||
|
||||
|
|
@ -32,6 +35,7 @@ impl Default for Settings {
|
|||
fn default() -> Settings {
|
||||
Settings {
|
||||
size: (1024, 768),
|
||||
position: Position::default(),
|
||||
min_size: None,
|
||||
max_size: None,
|
||||
resizable: true,
|
||||
|
|
@ -48,6 +52,7 @@ impl From<Settings> for iced_winit::settings::Window {
|
|||
fn from(settings: Settings) -> Self {
|
||||
Self {
|
||||
size: settings.size,
|
||||
position: iced_winit::Position::from(settings.position),
|
||||
min_size: settings.min_size,
|
||||
max_size: settings.max_size,
|
||||
resizable: settings.resizable,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue