Merge branch 'master' into feature/software-renderer
This commit is contained in:
commit
aa4b5bb6b9
12 changed files with 45 additions and 82 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "iced_core"
|
name = "iced_core"
|
||||||
version = "0.8.0"
|
version = "0.8.1"
|
||||||
authors = ["Héctor Ramón Jiménez <hector0193@gmail.com>"]
|
authors = ["Héctor Ramón Jiménez <hector0193@gmail.com>"]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
description = "The essential concepts of Iced"
|
description = "The essential concepts of Iced"
|
||||||
|
|
|
||||||
|
|
@ -11,9 +11,6 @@ pub enum Alignment {
|
||||||
|
|
||||||
/// Align at the end of the axis.
|
/// Align at the end of the axis.
|
||||||
End,
|
End,
|
||||||
|
|
||||||
/// Fill the entire axis.
|
|
||||||
Fill,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Horizontal> for Alignment {
|
impl From<Horizontal> for Alignment {
|
||||||
|
|
|
||||||
|
|
@ -81,32 +81,6 @@ where
|
||||||
let mut nodes: Vec<Node> = Vec::with_capacity(items.len());
|
let mut nodes: Vec<Node> = Vec::with_capacity(items.len());
|
||||||
nodes.resize(items.len(), Node::default());
|
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() {
|
for (i, child) in items.iter().enumerate() {
|
||||||
let fill_factor = match axis {
|
let fill_factor = match axis {
|
||||||
Axis::Horizontal => child.as_widget().width(),
|
Axis::Horizontal => child.as_widget().width(),
|
||||||
|
|
@ -115,31 +89,16 @@ where
|
||||||
.fill_factor();
|
.fill_factor();
|
||||||
|
|
||||||
if fill_factor == 0 {
|
if fill_factor == 0 {
|
||||||
let (min_width, min_height) = if align_items == Alignment::Fill {
|
let (max_width, max_height) = axis.pack(available, max_cross);
|
||||||
axis.pack(0.0, cross)
|
|
||||||
} else {
|
|
||||||
axis.pack(0.0, 0.0)
|
|
||||||
};
|
|
||||||
|
|
||||||
let (max_width, max_height) = if align_items == Alignment::Fill {
|
let child_limits =
|
||||||
axis.pack(available, cross)
|
Limits::new(Size::ZERO, Size::new(max_width, max_height));
|
||||||
} else {
|
|
||||||
axis.pack(available, max_cross)
|
|
||||||
};
|
|
||||||
|
|
||||||
let child_limits = Limits::new(
|
|
||||||
Size::new(min_width, min_height),
|
|
||||||
Size::new(max_width, max_height),
|
|
||||||
);
|
|
||||||
|
|
||||||
let layout = child.as_widget().layout(renderer, &child_limits);
|
let layout = child.as_widget().layout(renderer, &child_limits);
|
||||||
let size = layout.size();
|
let size = layout.size();
|
||||||
|
|
||||||
available -= axis.main(size);
|
available -= axis.main(size);
|
||||||
|
cross = cross.max(axis.cross(size));
|
||||||
if align_items != Alignment::Fill {
|
|
||||||
cross = cross.max(axis.cross(size));
|
|
||||||
}
|
|
||||||
|
|
||||||
nodes[i] = layout;
|
nodes[i] = layout;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -164,17 +123,10 @@ where
|
||||||
max_main
|
max_main
|
||||||
};
|
};
|
||||||
|
|
||||||
let (min_width, min_height) = if align_items == Alignment::Fill {
|
let (min_width, min_height) =
|
||||||
axis.pack(min_main, cross)
|
axis.pack(min_main, axis.cross(limits.min()));
|
||||||
} else {
|
|
||||||
axis.pack(min_main, axis.cross(limits.min()))
|
|
||||||
};
|
|
||||||
|
|
||||||
let (max_width, max_height) = if align_items == Alignment::Fill {
|
let (max_width, max_height) = axis.pack(max_main, max_cross);
|
||||||
axis.pack(max_main, cross)
|
|
||||||
} else {
|
|
||||||
axis.pack(max_main, max_cross)
|
|
||||||
};
|
|
||||||
|
|
||||||
let child_limits = Limits::new(
|
let child_limits = Limits::new(
|
||||||
Size::new(min_width, min_height),
|
Size::new(min_width, min_height),
|
||||||
|
|
@ -182,10 +134,7 @@ where
|
||||||
);
|
);
|
||||||
|
|
||||||
let layout = child.as_widget().layout(renderer, &child_limits);
|
let layout = child.as_widget().layout(renderer, &child_limits);
|
||||||
|
cross = cross.max(axis.cross(layout.size()));
|
||||||
if align_items != Alignment::Fill {
|
|
||||||
cross = cross.max(axis.cross(layout.size()));
|
|
||||||
}
|
|
||||||
|
|
||||||
nodes[i] = layout;
|
nodes[i] = layout;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -56,9 +56,6 @@ impl Node {
|
||||||
Alignment::End => {
|
Alignment::End => {
|
||||||
self.bounds.x += space.width - self.bounds.width;
|
self.bounds.x += space.width - self.bounds.width;
|
||||||
}
|
}
|
||||||
Alignment::Fill => {
|
|
||||||
self.bounds.width = space.width;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
match vertical_alignment {
|
match vertical_alignment {
|
||||||
|
|
@ -69,9 +66,6 @@ impl Node {
|
||||||
Alignment::End => {
|
Alignment::End => {
|
||||||
self.bounds.y += space.height - self.bounds.height;
|
self.bounds.y += space.height - self.bounds.height;
|
||||||
}
|
}
|
||||||
Alignment::Fill => {
|
|
||||||
self.bounds.height = space.height;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -77,12 +77,14 @@ impl Padding {
|
||||||
/// Fits the [`Padding`] between the provided `inner` and `outer` [`Size`].
|
/// Fits the [`Padding`] between the provided `inner` and `outer` [`Size`].
|
||||||
pub fn fit(self, inner: Size, outer: Size) -> Self {
|
pub fn fit(self, inner: Size, outer: Size) -> Self {
|
||||||
let available = (outer - inner).max(Size::ZERO);
|
let available = (outer - inner).max(Size::ZERO);
|
||||||
|
let new_top = self.top.min(available.height);
|
||||||
|
let new_left = self.left.min(available.width);
|
||||||
|
|
||||||
Padding {
|
Padding {
|
||||||
top: self.top.min(available.height / 2.0),
|
top: new_top,
|
||||||
right: self.right.min(available.width / 2.0),
|
bottom: self.bottom.min(available.height - new_top),
|
||||||
bottom: self.bottom.min(available.height / 2.0),
|
left: new_left,
|
||||||
left: self.left.min(available.width / 2.0),
|
right: self.right.min(available.width - new_left),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -120,7 +120,8 @@ mod numeric_input {
|
||||||
.horizontal_alignment(alignment::Horizontal::Center)
|
.horizontal_alignment(alignment::Horizontal::Center)
|
||||||
.vertical_alignment(alignment::Vertical::Center),
|
.vertical_alignment(alignment::Vertical::Center),
|
||||||
)
|
)
|
||||||
.width(50)
|
.width(40)
|
||||||
|
.height(40)
|
||||||
.on_press(on_press)
|
.on_press(on_press)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -138,7 +139,7 @@ mod numeric_input {
|
||||||
.padding(10),
|
.padding(10),
|
||||||
button("+", Event::IncrementPressed),
|
button("+", Event::IncrementPressed),
|
||||||
]
|
]
|
||||||
.align_items(Alignment::Fill)
|
.align_items(Alignment::Center)
|
||||||
.spacing(10)
|
.spacing(10)
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -254,7 +254,6 @@ impl Application for ScrollableDemo {
|
||||||
scroll_to_beginning_button(),
|
scroll_to_beginning_button(),
|
||||||
vertical_space(40),
|
vertical_space(40),
|
||||||
]
|
]
|
||||||
.align_items(Alignment::Fill)
|
|
||||||
.spacing(40),
|
.spacing(40),
|
||||||
horizontal_space(1200),
|
horizontal_space(1200),
|
||||||
text("Horizontal - End!"),
|
text("Horizontal - End!"),
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
use iced::alignment::{self, Alignment};
|
use iced::alignment::{self, Alignment};
|
||||||
use iced::event::{self, Event};
|
use iced::event::{self, Event};
|
||||||
use iced::font::{self, Font};
|
use iced::font::{self, Font};
|
||||||
use iced::keyboard;
|
use iced::keyboard::{self, KeyCode, Modifiers};
|
||||||
use iced::subscription;
|
use iced::subscription;
|
||||||
use iced::theme::{self, Theme};
|
use iced::theme::{self, Theme};
|
||||||
use iced::widget::{
|
use iced::widget::{
|
||||||
|
|
@ -52,6 +52,7 @@ enum Message {
|
||||||
FilterChanged(Filter),
|
FilterChanged(Filter),
|
||||||
TaskMessage(usize, TaskMessage),
|
TaskMessage(usize, TaskMessage),
|
||||||
TabPressed { shift: bool },
|
TabPressed { shift: bool },
|
||||||
|
ToggleFullscreen(window::Mode),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Application for Todos {
|
impl Application for Todos {
|
||||||
|
|
@ -162,6 +163,9 @@ impl Application for Todos {
|
||||||
widget::focus_next()
|
widget::focus_next()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Message::ToggleFullscreen(mode) => {
|
||||||
|
window::change_mode(mode)
|
||||||
|
}
|
||||||
_ => Command::none(),
|
_ => Command::none(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -272,6 +276,21 @@ impl Application for Todos {
|
||||||
) => Some(Message::TabPressed {
|
) => Some(Message::TabPressed {
|
||||||
shift: modifiers.shift(),
|
shift: modifiers.shift(),
|
||||||
}),
|
}),
|
||||||
|
(
|
||||||
|
Event::Keyboard(keyboard::Event::KeyPressed {
|
||||||
|
key_code,
|
||||||
|
modifiers: Modifiers::SHIFT,
|
||||||
|
}),
|
||||||
|
event::Status::Ignored,
|
||||||
|
) => match key_code {
|
||||||
|
KeyCode::Up => {
|
||||||
|
Some(Message::ToggleFullscreen(window::Mode::Fullscreen))
|
||||||
|
}
|
||||||
|
KeyCode::Down => {
|
||||||
|
Some(Message::ToggleFullscreen(window::Mode::Windowed))
|
||||||
|
}
|
||||||
|
_ => None,
|
||||||
|
},
|
||||||
_ => None,
|
_ => None,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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]
|
column![message_log, new_message_input]
|
||||||
|
|
|
||||||
|
|
@ -65,5 +65,5 @@ version = "0.3"
|
||||||
features = ["Document", "Window"]
|
features = ["Document", "Window"]
|
||||||
|
|
||||||
[dependencies.sysinfo]
|
[dependencies.sysinfo]
|
||||||
version = "0.23"
|
version = "0.28"
|
||||||
optional = true
|
optional = true
|
||||||
|
|
|
||||||
|
|
@ -758,7 +758,7 @@ pub fn run_command<A, E>(
|
||||||
window::Action::ChangeMode(mode) => {
|
window::Action::ChangeMode(mode) => {
|
||||||
window.set_visible(conversion::visible(mode));
|
window.set_visible(conversion::visible(mode));
|
||||||
window.set_fullscreen(conversion::fullscreen(
|
window.set_fullscreen(conversion::fullscreen(
|
||||||
window.primary_monitor(),
|
window.current_monitor(),
|
||||||
mode,
|
mode,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,11 +15,11 @@ pub fn fetch_information<Message>(
|
||||||
pub(crate) fn information(
|
pub(crate) fn information(
|
||||||
graphics_info: compositor::Information,
|
graphics_info: compositor::Information,
|
||||||
) -> Information {
|
) -> Information {
|
||||||
use sysinfo::{ProcessExt, ProcessorExt, System, SystemExt};
|
use sysinfo::{CpuExt, ProcessExt, System, SystemExt};
|
||||||
let mut system = System::new_all();
|
let mut system = System::new_all();
|
||||||
system.refresh_all();
|
system.refresh_all();
|
||||||
|
|
||||||
let cpu = system.global_processor_info();
|
let cpu = system.global_cpu_info();
|
||||||
|
|
||||||
let memory_used = sysinfo::get_current_pid()
|
let memory_used = sysinfo::get_current_pid()
|
||||||
.and_then(|pid| system.process(pid).ok_or("Process not found"))
|
.and_then(|pid| system.process(pid).ok_or("Process not found"))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue