#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub struct WindowId(pub u64);
impl WindowId {
pub const PRIMARY: WindowId = WindowId(0);
}
#[derive(Clone, Debug)]
pub struct WindowConfig {
pub title: String,
pub width: u32,
pub height: u32,
pub resizable: bool,
pub decorations: bool,
pub transparent: bool,
pub always_on_top: bool,
pub fullscreen: bool,
pub min_size: Option<(u32, u32)>,
pub max_size: Option<(u32, u32)>,
pub position: Option<(i32, i32)>,
pub center: bool,
pub modal: bool,
pub parent: Option<WindowId>,
}
impl Default for WindowConfig {
fn default() -> Self {
Self {
title: "Blinc App".to_string(),
width: 800,
height: 600,
resizable: true,
decorations: true,
transparent: false,
always_on_top: false,
fullscreen: false,
min_size: None,
max_size: None,
position: None,
center: false,
modal: false,
parent: None,
}
}
}
impl WindowConfig {
pub fn new(title: impl Into<String>) -> Self {
Self {
title: title.into(),
..Default::default()
}
}
pub fn title(mut self, title: impl Into<String>) -> Self {
self.title = title.into();
self
}
pub fn size(mut self, width: u32, height: u32) -> Self {
self.width = width;
self.height = height;
self
}
pub fn resizable(mut self, resizable: bool) -> Self {
self.resizable = resizable;
self
}
pub fn decorations(mut self, decorations: bool) -> Self {
self.decorations = decorations;
self
}
pub fn transparent(mut self, transparent: bool) -> Self {
self.transparent = transparent;
self
}
pub fn always_on_top(mut self, always_on_top: bool) -> Self {
self.always_on_top = always_on_top;
self
}
pub fn fullscreen(mut self, fullscreen: bool) -> Self {
self.fullscreen = fullscreen;
self
}
pub fn min_size(mut self, width: u32, height: u32) -> Self {
self.min_size = Some((width, height));
self
}
pub fn max_size(mut self, width: u32, height: u32) -> Self {
self.max_size = Some((width, height));
self
}
pub fn position(mut self, x: i32, y: i32) -> Self {
self.position = Some((x, y));
self
}
pub fn center(mut self) -> Self {
self.center = true;
self
}
pub fn modal(mut self) -> Self {
self.modal = true;
self
}
pub fn parent(mut self, parent_id: WindowId) -> Self {
self.parent = Some(parent_id);
self
}
}
pub trait Window: Send {
fn id(&self) -> WindowId;
fn size(&self) -> (u32, u32);
fn logical_size(&self) -> (f32, f32);
fn scale_factor(&self) -> f64;
fn set_title(&self, title: &str);
fn set_cursor(&self, cursor: Cursor);
fn request_redraw(&self);
fn is_focused(&self) -> bool;
fn is_visible(&self) -> bool;
fn set_position(&self, _x: i32, _y: i32) {}
fn center_on_screen(&self) {}
fn set_size(&self, _width: u32, _height: u32) {}
fn drag_window(&self) {}
fn minimize(&self) {}
fn maximize(&self) {}
fn close(&self) {}
fn safe_area_insets(&self) -> (f32, f32, f32, f32) {
(0.0, 0.0, 0.0, 0.0)
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub enum Cursor {
#[default]
Default,
Pointer,
Text,
Crosshair,
Move,
NotAllowed,
ResizeNS,
ResizeEW,
ResizeNESW,
ResizeNWSE,
Grab,
Grabbing,
Wait,
Progress,
None,
}