From 871b7e0311c73358213aae6326973300f0b56faa Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 25 Feb 2023 21:28:21 +0100 Subject: Fix `Padding::fit` on irregular values for an axis --- core/src/padding.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/core/src/padding.rs b/core/src/padding.rs index 752b2b86..0b1bba13 100644 --- a/core/src/padding.rs +++ b/core/src/padding.rs @@ -77,12 +77,14 @@ impl Padding { /// Fits the [`Padding`] between the provided `inner` and `outer` [`Size`]. pub fn fit(self, inner: Size, outer: Size) -> Self { let available = (outer - inner).max(Size::ZERO); + let new_top = self.top.min(available.height); + let new_left = self.left.min(available.width); Padding { - top: self.top.min(available.height / 2.0), - right: self.right.min(available.width / 2.0), - bottom: self.bottom.min(available.height / 2.0), - left: self.left.min(available.width / 2.0), + top: new_top, + bottom: self.bottom.min(available.height - new_top), + left: new_left, + right: self.right.min(available.width - new_left), } } } -- cgit From 5f93437285c4451a8b5ffac1b3c9e1b91e8a5918 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 25 Feb 2023 21:43:53 +0100 Subject: Bump version of `iced_core` :tada: --- core/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/Cargo.toml b/core/Cargo.toml index 43865e4d..0d6310d3 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "iced_core" -version = "0.8.0" +version = "0.8.1" authors = ["Héctor Ramón Jiménez "] edition = "2021" description = "The essential concepts of Iced" -- cgit From 9e815cb749f1bf6bce0232e870be266aca0c0742 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Mon, 27 Feb 2023 16:49:25 +0100 Subject: Remove `Fill` variant for `Alignment` Implementing this generically in our `flex` logic has an exponential cost. Let's explore other options! --- core/src/alignment.rs | 3 -- examples/component/src/main.rs | 5 +-- examples/scrollable/src/main.rs | 1 - examples/websocket/src/main.rs | 4 ++- native/src/layout/flex.rs | 67 +++++------------------------------------ native/src/layout/node.rs | 6 ---- 6 files changed, 14 insertions(+), 72 deletions(-) diff --git a/core/src/alignment.rs b/core/src/alignment.rs index 73f41d3f..51b7fca9 100644 --- a/core/src/alignment.rs +++ b/core/src/alignment.rs @@ -11,9 +11,6 @@ pub enum Alignment { /// Align at the end of the axis. End, - - /// Fill the entire axis. - Fill, } impl From for Alignment { diff --git a/examples/component/src/main.rs b/examples/component/src/main.rs index c407bb06..bbf549e7 100644 --- a/examples/component/src/main.rs +++ b/examples/component/src/main.rs @@ -127,7 +127,8 @@ mod numeric_input { .horizontal_alignment(alignment::Horizontal::Center) .vertical_alignment(alignment::Vertical::Center), ) - .width(50) + .width(40) + .height(40) .on_press(on_press) }; @@ -145,7 +146,7 @@ mod numeric_input { .padding(10), button("+", Event::IncrementPressed), ] - .align_items(Alignment::Fill) + .align_items(Alignment::Center) .spacing(10) .into() } diff --git a/examples/scrollable/src/main.rs b/examples/scrollable/src/main.rs index 7c858961..a3ade54f 100644 --- a/examples/scrollable/src/main.rs +++ b/examples/scrollable/src/main.rs @@ -254,7 +254,6 @@ impl Application for ScrollableDemo { scroll_to_beginning_button(), vertical_space(40), ] - .align_items(Alignment::Fill) .spacing(40), horizontal_space(1200), text("Horizontal - End!"), diff --git a/examples/websocket/src/main.rs b/examples/websocket/src/main.rs index ccd9c815..e617b8ce 100644 --- a/examples/websocket/src/main.rs +++ b/examples/websocket/src/main.rs @@ -146,7 +146,9 @@ impl Application for WebSocket { } } - row![input, button].spacing(10).align_items(Alignment::Fill) + row![input, button] + .spacing(10) + .align_items(Alignment::Center) }; column![message_log, new_message_input] diff --git a/native/src/layout/flex.rs b/native/src/layout/flex.rs index 5d70c2fc..8b967849 100644 --- a/native/src/layout/flex.rs +++ b/native/src/layout/flex.rs @@ -81,32 +81,6 @@ where let mut nodes: Vec = Vec::with_capacity(items.len()); nodes.resize(items.len(), Node::default()); - if align_items == Alignment::Fill { - let mut fill_cross = axis.cross(limits.min()); - - items.iter().for_each(|child| { - let cross_fill_factor = match axis { - Axis::Horizontal => child.as_widget().height(), - Axis::Vertical => child.as_widget().width(), - } - .fill_factor(); - - if cross_fill_factor == 0 { - let (max_width, max_height) = axis.pack(available, max_cross); - - let child_limits = - Limits::new(Size::ZERO, Size::new(max_width, max_height)); - - let layout = child.as_widget().layout(renderer, &child_limits); - let size = layout.size(); - - fill_cross = fill_cross.max(axis.cross(size)); - } - }); - - cross = fill_cross; - } - for (i, child) in items.iter().enumerate() { let fill_factor = match axis { Axis::Horizontal => child.as_widget().width(), @@ -115,31 +89,16 @@ where .fill_factor(); if fill_factor == 0 { - let (min_width, min_height) = if align_items == Alignment::Fill { - axis.pack(0.0, cross) - } else { - axis.pack(0.0, 0.0) - }; + let (max_width, max_height) = axis.pack(available, max_cross); - let (max_width, max_height) = if align_items == Alignment::Fill { - axis.pack(available, cross) - } else { - axis.pack(available, max_cross) - }; - - let child_limits = Limits::new( - Size::new(min_width, min_height), - Size::new(max_width, max_height), - ); + let child_limits = + Limits::new(Size::ZERO, Size::new(max_width, max_height)); let layout = child.as_widget().layout(renderer, &child_limits); let size = layout.size(); available -= axis.main(size); - - if align_items != Alignment::Fill { - cross = cross.max(axis.cross(size)); - } + cross = cross.max(axis.cross(size)); nodes[i] = layout; } else { @@ -164,17 +123,10 @@ where max_main }; - let (min_width, min_height) = if align_items == Alignment::Fill { - axis.pack(min_main, cross) - } else { - axis.pack(min_main, axis.cross(limits.min())) - }; + let (min_width, min_height) = + axis.pack(min_main, axis.cross(limits.min())); - let (max_width, max_height) = if align_items == Alignment::Fill { - axis.pack(max_main, cross) - } else { - axis.pack(max_main, max_cross) - }; + let (max_width, max_height) = axis.pack(max_main, max_cross); let child_limits = Limits::new( Size::new(min_width, min_height), @@ -182,10 +134,7 @@ where ); let layout = child.as_widget().layout(renderer, &child_limits); - - if align_items != Alignment::Fill { - cross = cross.max(axis.cross(layout.size())); - } + cross = cross.max(axis.cross(layout.size())); nodes[i] = layout; } diff --git a/native/src/layout/node.rs b/native/src/layout/node.rs index e0c7dcb2..2b44a7d5 100644 --- a/native/src/layout/node.rs +++ b/native/src/layout/node.rs @@ -56,9 +56,6 @@ impl Node { Alignment::End => { self.bounds.x += space.width - self.bounds.width; } - Alignment::Fill => { - self.bounds.width = space.width; - } } match vertical_alignment { @@ -69,9 +66,6 @@ impl Node { Alignment::End => { self.bounds.y += space.height - self.bounds.height; } - Alignment::Fill => { - self.bounds.height = space.height; - } } } -- cgit From b2a9a1e73cb7b2026b2eeaa2be2c04a61c5efb21 Mon Sep 17 00:00:00 2001 From: Bingus Date: Thu, 2 Mar 2023 08:31:39 -0800 Subject: Fixed fullscreen only being possible on primary monitor. --- winit/src/application.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/winit/src/application.rs b/winit/src/application.rs index 9781a453..b13b7214 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -762,7 +762,7 @@ pub fn run_command( window::Action::ChangeMode(mode) => { window.set_visible(conversion::visible(mode)); window.set_fullscreen(conversion::fullscreen( - window.primary_monitor(), + window.current_monitor(), mode, )); } -- cgit From a9ca89ca55157d7e94dc6422b4842826139ca2db Mon Sep 17 00:00:00 2001 From: Bingus Date: Thu, 2 Mar 2023 08:43:58 -0800 Subject: Added example of toggling fullscreen to TODOs. --- examples/todos/src/main.rs | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/examples/todos/src/main.rs b/examples/todos/src/main.rs index 6408f09c..0f5bfe30 100644 --- a/examples/todos/src/main.rs +++ b/examples/todos/src/main.rs @@ -1,6 +1,6 @@ use iced::alignment::{self, Alignment}; use iced::event::{self, Event}; -use iced::keyboard; +use iced::keyboard::{self, KeyCode, Modifiers}; use iced::subscription; use iced::theme::{self, Theme}; use iced::widget::{ @@ -8,6 +8,8 @@ use iced::widget::{ text_input, Text, }; use iced::window; +#[cfg(not(target_arch = "wasm32"))] +use iced::window::Mode; use iced::{Application, Element}; use iced::{Color, Command, Font, Length, Settings, Subscription}; @@ -49,7 +51,11 @@ enum Message { CreateTask, FilterChanged(Filter), TaskMessage(usize, TaskMessage), - TabPressed { shift: bool }, + TabPressed { + shift: bool, + }, + #[cfg(not(target_arch = "wasm32"))] + ToggleFullscreen(Mode), } impl Application for Todos { @@ -156,6 +162,10 @@ impl Application for Todos { widget::focus_next() } } + #[cfg(not(target_arch = "wasm32"))] + Message::ToggleFullscreen(mode) => { + window::change_mode(mode) + } _ => Command::none(), }; @@ -266,6 +276,22 @@ impl Application for Todos { ) => Some(Message::TabPressed { shift: modifiers.shift(), }), + #[cfg(not(target_arch = "wasm32"))] + ( + Event::Keyboard(keyboard::Event::KeyPressed { + key_code, + modifiers: Modifiers::SHIFT, + }), + event::Status::Ignored, + ) => match key_code { + KeyCode::Up => { + Some(Message::ToggleFullscreen(Mode::Fullscreen)) + } + KeyCode::Down => { + Some(Message::ToggleFullscreen(Mode::Windowed)) + } + _ => None, + }, _ => None, }) } -- cgit From 12781c717a08bf0e7bfb2594e568f89af3676d52 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 3 Mar 2023 20:45:49 +0100 Subject: Expose `window` commands for Wasm builds --- examples/todos/src/main.rs | 15 ++++----------- src/window.rs | 1 - 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/examples/todos/src/main.rs b/examples/todos/src/main.rs index 0f5bfe30..6a87f58c 100644 --- a/examples/todos/src/main.rs +++ b/examples/todos/src/main.rs @@ -8,8 +8,6 @@ use iced::widget::{ text_input, Text, }; use iced::window; -#[cfg(not(target_arch = "wasm32"))] -use iced::window::Mode; use iced::{Application, Element}; use iced::{Color, Command, Font, Length, Settings, Subscription}; @@ -51,11 +49,8 @@ enum Message { CreateTask, FilterChanged(Filter), TaskMessage(usize, TaskMessage), - TabPressed { - shift: bool, - }, - #[cfg(not(target_arch = "wasm32"))] - ToggleFullscreen(Mode), + TabPressed { shift: bool }, + ToggleFullscreen(window::Mode), } impl Application for Todos { @@ -162,7 +157,6 @@ impl Application for Todos { widget::focus_next() } } - #[cfg(not(target_arch = "wasm32"))] Message::ToggleFullscreen(mode) => { window::change_mode(mode) } @@ -276,7 +270,6 @@ impl Application for Todos { ) => Some(Message::TabPressed { shift: modifiers.shift(), }), - #[cfg(not(target_arch = "wasm32"))] ( Event::Keyboard(keyboard::Event::KeyPressed { key_code, @@ -285,10 +278,10 @@ impl Application for Todos { event::Status::Ignored, ) => match key_code { KeyCode::Up => { - Some(Message::ToggleFullscreen(Mode::Fullscreen)) + Some(Message::ToggleFullscreen(window::Mode::Fullscreen)) } KeyCode::Down => { - Some(Message::ToggleFullscreen(Mode::Windowed)) + Some(Message::ToggleFullscreen(window::Mode::Windowed)) } _ => None, }, diff --git a/src/window.rs b/src/window.rs index 2018053f..5a199580 100644 --- a/src/window.rs +++ b/src/window.rs @@ -8,5 +8,4 @@ pub use icon::Icon; pub use position::Position; pub use settings::Settings; -#[cfg(not(target_arch = "wasm32"))] pub use crate::runtime::window::*; -- cgit From df68cca0c9dda051ae979ccc2f5ca8d37c3e3cb5 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 7 Mar 2023 07:22:48 +0100 Subject: Update `sysinfo` to `0.28` --- winit/Cargo.toml | 2 +- winit/src/system.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/winit/Cargo.toml b/winit/Cargo.toml index 60e464c6..dd5c12c2 100644 --- a/winit/Cargo.toml +++ b/winit/Cargo.toml @@ -65,5 +65,5 @@ version = "0.3" features = ["Document", "Window"] [dependencies.sysinfo] -version = "0.23" +version = "0.28" optional = true diff --git a/winit/src/system.rs b/winit/src/system.rs index 619086b8..8d8b018c 100644 --- a/winit/src/system.rs +++ b/winit/src/system.rs @@ -16,11 +16,11 @@ pub fn fetch_information( pub(crate) fn information( graphics_info: compositor::Information, ) -> Information { - use sysinfo::{ProcessExt, ProcessorExt, System, SystemExt}; + use sysinfo::{CpuExt, ProcessExt, System, SystemExt}; let mut system = System::new_all(); system.refresh_all(); - let cpu = system.global_processor_info(); + let cpu = system.global_cpu_info(); let memory_used = sysinfo::get_current_pid() .and_then(|pid| system.process(pid).ok_or("Process not found")) -- cgit