From cd3769a48efcc3fdd2dc1304b1babfe6d26f788d Mon Sep 17 00:00:00 2001 From: Ben Bridle Date: Sun, 5 Nov 2023 14:17:49 +1300 Subject: Implement window scaling A window now can declare a scale factor to be used when rendering logical pixels to a physical window. Each logical pixel will be drawn as an NxN block of physical pixels, where N is the scale factor. --- src/window_controller.rs | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'src/window_controller.rs') diff --git a/src/window_controller.rs b/src/window_controller.rs index 34f9fd4..78af0e1 100644 --- a/src/window_controller.rs +++ b/src/window_controller.rs @@ -1,17 +1,22 @@ use crate::*; +use std::num::NonZeroU32; +use std::path::Path; + +const NON_ZERO_ONE: NonZeroU32 = unsafe { NonZeroU32::new_unchecked(1) }; pub trait WindowController { fn title(&self) -> String { String::from("Phosphor") } - fn cursor_icon(&self) -> Option { None } - fn initial_size(&self) -> Dimensions { Dimensions::new(800,600) } + fn initial_size(&self) -> Option { None } fn minimum_size(&self) -> Option { None } fn maximum_size(&self) -> Option { None } - fn pixel_scale(&self) -> u32 { 1 } - fn render_request(&self) -> RenderRequest { RenderRequest::None } + fn exact_size(&self) -> Option { None } + fn pixel_scale(&self) -> NonZeroU32 { NON_ZERO_ONE } + + fn cursor_icon(&mut self) -> Option { None } + fn render_request(&mut self) -> RenderRequest { RenderRequest::None } fn is_visible(&self) -> bool { true } fn is_cursor_visible(&self) -> bool { true } - fn is_resizable(&self) -> bool { true } fn on_init(&mut self) {} fn on_resize(&mut self, _size: Dimensions) {} @@ -37,8 +42,8 @@ pub trait WindowController { fn on_keyboard_input(&mut self, _input: KeyboardInput) {} fn on_keyboard_modifier_change(&mut self, _modifiers: ModifiersState) {} - fn on_character_input(&mut self, _character: char) {} - fn on_file_hover(&mut self, _path: std::path::PathBuf) {} + fn on_character_input(&mut self, _input: char) {} + fn on_file_hover(&mut self, _path: &Path) {} fn on_file_hover_cancel(&mut self) {} - fn on_file_drop(&mut self, _path: std::path::PathBuf) {} + fn on_file_drop(&mut self, _path: &Path) {} } -- cgit v1.2.3-70-g09d2