diff options
author | 2023-11-30 23:40:33 +0100 | |
---|---|---|
committer | 2023-11-30 23:40:33 +0100 | |
commit | 67408311f45d341509538f8cc185978da66b6ace (patch) | |
tree | 27b020da7eda4c77f07000e49335f5e0d482feba /examples | |
parent | 9f29aec128ccf51c620a8b69a9fbd64186ab8c65 (diff) | |
download | iced-67408311f45d341509538f8cc185978da66b6ace.tar.gz iced-67408311f45d341509538f8cc185978da66b6ace.tar.bz2 iced-67408311f45d341509538f8cc185978da66b6ace.zip |
Use actual floats for logical coordinates
Diffstat (limited to 'examples')
-rw-r--r-- | examples/multi_window/src/main.rs | 15 | ||||
-rw-r--r-- | examples/solar_system/src/main.rs | 14 | ||||
-rw-r--r-- | examples/todos/src/main.rs | 4 |
3 files changed, 16 insertions, 17 deletions
diff --git a/examples/multi_window/src/main.rs b/examples/multi_window/src/main.rs index 7d1f1e91..16beb46e 100644 --- a/examples/multi_window/src/main.rs +++ b/examples/multi_window/src/main.rs @@ -4,8 +4,10 @@ use iced::multi_window::{self, Application}; use iced::widget::{button, column, container, scrollable, text, text_input}; use iced::window; use iced::{ - Alignment, Command, Element, Length, Settings, Subscription, Theme, + Alignment, Command, Element, Length, Point, Settings, Subscription, Theme, + Vector, }; + use std::collections::HashMap; fn main() -> iced::Result { @@ -33,8 +35,8 @@ enum Message { ScaleChanged(window::Id, String), TitleChanged(window::Id, String), CloseWindow(window::Id), + WindowCreated(window::Id, Option<Point>), WindowDestroyed(window::Id), - WindowCreated(window::Id, (i32, i32)), NewWindow, } @@ -90,10 +92,11 @@ impl multi_window::Application for Example { self.windows.remove(&id); } Message::WindowCreated(id, position) => { - self.next_window_pos = window::Position::Specific( - position.0 + 20, - position.1 + 20, - ); + if let Some(position) = position { + self.next_window_pos = window::Position::Specific( + position + Vector::new(20.0, 20.0), + ); + } if let Some(window) = self.windows.get(&id) { return text_input::focus(window.input_id.clone()); diff --git a/examples/solar_system/src/main.rs b/examples/solar_system/src/main.rs index 8295dded..82421a86 100644 --- a/examples/solar_system/src/main.rs +++ b/examples/solar_system/src/main.rs @@ -114,14 +114,14 @@ impl State { pub fn new() -> State { let now = Instant::now(); - let (width, height) = window::Settings::default().size; + let size = window::Settings::default().size; State { space_cache: canvas::Cache::default(), system_cache: canvas::Cache::default(), start: now, now, - stars: Self::generate_stars(width, height), + stars: Self::generate_stars(size.width, size.height), } } @@ -130,7 +130,7 @@ impl State { self.system_cache.clear(); } - fn generate_stars(width: u32, height: u32) -> Vec<(Point, f32)> { + fn generate_stars(width: f32, height: f32) -> Vec<(Point, f32)> { use rand::Rng; let mut rng = rand::thread_rng(); @@ -139,12 +139,8 @@ impl State { .map(|_| { ( Point::new( - rng.gen_range( - (-(width as f32) / 2.0)..(width as f32 / 2.0), - ), - rng.gen_range( - (-(height as f32) / 2.0)..(height as f32 / 2.0), - ), + rng.gen_range((-width / 2.0)..(width / 2.0)), + rng.gen_range((-height / 2.0)..(height / 2.0)), ), rng.gen_range(0.5..1.0), ) diff --git a/examples/todos/src/main.rs b/examples/todos/src/main.rs index a7ba69b9..4dac032c 100644 --- a/examples/todos/src/main.rs +++ b/examples/todos/src/main.rs @@ -8,7 +8,7 @@ use iced::widget::{ }; use iced::window; use iced::{Application, Element}; -use iced::{Color, Command, Length, Settings, Subscription}; +use iced::{Color, Command, Length, Settings, Size, Subscription}; use once_cell::sync::Lazy; use serde::{Deserialize, Serialize}; @@ -22,7 +22,7 @@ pub fn main() -> iced::Result { Todos::run(Settings { window: window::Settings { - size: (500, 800), + size: Size::new(500.0, 800.0), ..window::Settings::default() }, ..Settings::default() |