move window settings to iced_native

This commit is contained in:
Richard 2022-10-19 22:56:00 -03:00 committed by bungoboingo
parent a386788b67
commit 1bc0c480f9
11 changed files with 62 additions and 69 deletions

View file

@ -31,7 +31,8 @@ pub fn main() {
.unwrap();
unsafe {
let windowed_context = windowed_context.make_current(todo!("derezzedex")).unwrap();
let windowed_context =
windowed_context.make_current(todo!("derezzedex")).unwrap();
let gl = glow::Context::from_loader_function(|s| {
windowed_context.get_proc_address(s) as *const _

View file

@ -120,7 +120,9 @@ where
#[allow(unsafe_code)]
unsafe {
context.make_current(todo!()).expect("Make OpenGL context current")
context
.make_current(todo!())
.expect("Make OpenGL context current")
}
};

View file

@ -1,12 +1,16 @@
//! Build window-based GUI applications.
mod action;
mod event;
mod icon;
mod id;
mod mode;
mod user_attention;
pub use action::Action;
pub use event::Event;
pub use icon::Icon;
pub use id::Id;
pub use mode::Mode;
pub use user_attention::UserAttention;
pub use position::Position;
pub use settings::Settings;

12
native/src/window/icon.rs Normal file
View file

@ -0,0 +1,12 @@
//! Attach an icon to the window of your application.
/// The icon of a window.
#[derive(Debug, Clone)]
pub struct Icon {
/// TODO(derezzedex)
pub rgba: Vec<u8>,
/// TODO(derezzedex)
pub width: u32,
/// TODO(derezzedex)
pub height: u32,
}

View file

@ -50,21 +50,3 @@ impl Default for Settings {
}
}
}
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,
visible: settings.visible,
resizable: settings.resizable,
decorations: settings.decorations,
transparent: settings.transparent,
always_on_top: settings.always_on_top,
icon: settings.icon.map(Icon::into),
platform_specific: Default::default(),
}
}
}

View file

@ -1,12 +1,7 @@
//! Configure the window of your application in native platforms.
mod position;
mod settings;
pub mod icon;
pub use icon::Icon;
pub use position::Position;
pub use settings::Settings;
pub use iced_native::window::Icon;
pub use iced_native::window::Position;
pub use iced_native::window::Settings;
#[cfg(not(target_arch = "wasm32"))]
pub use crate::runtime::window::*;

View file

@ -1,32 +0,0 @@
/// 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
}
}
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),
}
}
}

View file

@ -7,7 +7,7 @@ use std::path::Path;
/// The icon of a window.
#[derive(Debug, Clone)]
pub struct Icon(iced_winit::winit::window::Icon);
pub struct Icon(winit::window::Icon);
impl Icon {
/// Creates an icon from 32bpp RGBA data.
@ -16,8 +16,7 @@ impl Icon {
width: u32,
height: u32,
) -> Result<Self, Error> {
let raw =
iced_winit::winit::window::Icon::from_rgba(rgba, width, height)?;
let raw = winit::window::Icon::from_rgba(rgba, width, height)?;
Ok(Icon(raw))
}
@ -91,9 +90,9 @@ impl From<std::io::Error> for Error {
}
}
impl From<iced_winit::winit::window::BadIcon> for Error {
fn from(error: iced_winit::winit::window::BadIcon) -> Self {
use iced_winit::winit::window::BadIcon;
impl From<winit::window::BadIcon> for Error {
fn from(error: winit::window::BadIcon) -> Self {
use winit::window::BadIcon;
match error {
BadIcon::ByteCountNotDivisibleBy4 { byte_count } => {
@ -114,7 +113,7 @@ impl From<iced_winit::winit::window::BadIcon> for Error {
}
}
impl From<Icon> for iced_winit::winit::window::Icon {
impl From<Icon> for winit::window::Icon {
fn from(icon: Icon) -> Self {
icon.0
}
@ -170,3 +169,11 @@ impl std::error::Error for Error {
Some(self)
}
}
impl TryFrom<iced_native::window::Icon> for Icon {
type Error = Error;
fn try_from(icon: iced_native::window::Icon) -> Result<Self, Self::Error> {
Icon::from_rgba(icon.rgba, icon.width, icon.height)
}
}

View file

@ -49,7 +49,7 @@ pub mod window;
pub mod system;
mod error;
mod position;
mod icon;
mod proxy;
#[cfg(feature = "application")]
@ -58,8 +58,9 @@ pub use application::Application;
pub use application::Profiler;
pub use clipboard::Clipboard;
pub use error::Error;
pub use position::Position;
pub use icon::Icon;
pub use proxy::Proxy;
pub use settings::Settings;
pub use iced_graphics::Viewport;
pub use iced_native::window::Position;

View file

@ -22,6 +22,7 @@ mod platform;
pub use platform::PlatformSpecific;
use crate::conversion;
use crate::Icon;
use crate::Position;
use winit::monitor::MonitorHandle;
use winit::window::WindowBuilder;
@ -201,3 +202,23 @@ impl Default for Window {
}
}
}
impl From<iced_native::window::Settings> for Window {
fn from(settings: iced_native::window::Settings) -> Self {
Self {
size: settings.size,
position: Position::from(settings.position),
min_size: settings.min_size,
max_size: settings.max_size,
visible: settings.visible,
resizable: settings.resizable,
decorations: settings.decorations,
transparent: settings.transparent,
always_on_top: settings.always_on_top,
icon: settings.icon.and_then(|icon| {
Icon::try_from(icon).map(winit::window::Icon::from).ok()
}),
platform_specific: Default::default(),
}
}
}