Skip to content

Commit

Permalink
Merge branch 'iced-rs:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
MichelleGranat authored Oct 7, 2024
2 parents f0a2170 + c217500 commit 8c4cc0b
Show file tree
Hide file tree
Showing 25 changed files with 211 additions and 127 deletions.
6 changes: 6 additions & 0 deletions core/src/keyboard/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ pub enum Event {
/// The key released.
key: Key,

/// The key released with all keyboard modifiers applied, except Ctrl.
modified_key: Key,

/// The physical key released.
physical_key: key::Physical,

/// The location of the key.
location: Location,

Expand Down
2 changes: 1 addition & 1 deletion core/src/keyboard/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ pub enum Named {
Standby,
/// The WakeUp key. (`KEYCODE_WAKEUP`)
WakeUp,
/// Initate the multi-candidate mode.
/// Initiate the multi-candidate mode.
AllCandidates,
Alphanumeric,
/// Initiate the Code Input mode to allow characters to be entered by
Expand Down
2 changes: 1 addition & 1 deletion core/src/keyboard/modifiers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl Modifiers {
/// This is normally the main modifier to be used for hotkeys.
///
/// On macOS, this is equivalent to `Self::LOGO`.
/// Ohterwise, this is equivalent to `Self::CTRL`.
/// Otherwise, this is equivalent to `Self::CTRL`.
pub const COMMAND: Self = if cfg!(target_os = "macos") {
Self::LOGO
} else {
Expand Down
4 changes: 2 additions & 2 deletions core/src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,13 +411,13 @@ impl<'a, Link, Font> Span<'a, Link, Font> {
self
}

/// Sets whether the [`Span`] shoud be underlined or not.
/// Sets whether the [`Span`] should be underlined or not.
pub fn underline(mut self, underline: bool) -> Self {
self.underline = underline;
self
}

/// Sets whether the [`Span`] shoud be struck through or not.
/// Sets whether the [`Span`] should be struck through or not.
pub fn strikethrough(mut self, strikethrough: bool) -> Self {
self.strikethrough = strikethrough;
self
Expand Down
12 changes: 12 additions & 0 deletions core/src/window/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,29 @@ pub enum Event {
///
/// When the user hovers multiple files at once, this event will be emitted
/// for each file separately.
///
/// ## Platform-specific
///
/// - **Wayland:** Not implemented.
FileHovered(PathBuf),

/// A file has been dropped into the window.
///
/// When the user drops multiple files at once, this event will be emitted
/// for each file separately.
///
/// ## Platform-specific
///
/// - **Wayland:** Not implemented.
FileDropped(PathBuf),

/// A file was hovered, but has exited the window.
///
/// There will be a single `FilesHoveredLeft` event triggered even if
/// multiple files were hovered.
///
/// ## Platform-specific
///
/// - **Wayland:** Not implemented.
FilesHoveredLeft,
}
4 changes: 2 additions & 2 deletions examples/loading_spinners/src/circular.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ impl Animation {
progress: 0.0,
rotation: rotation.wrapping_add(
BASE_ROTATION_SPEED.wrapping_add(
(f64::from(WRAP_ANGLE / (2.0 * Radians::PI)) * f64::MAX)
as u32,
(f64::from(WRAP_ANGLE / (2.0 * Radians::PI))
* u32::MAX as f64) as u32,
),
),
last: now,
Expand Down
54 changes: 44 additions & 10 deletions examples/qr_code/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
use iced::widget::{center, column, pick_list, qr_code, row, text, text_input};
use iced::widget::{
center, column, pick_list, qr_code, row, slider, text, text_input, toggler,
};
use iced::{Center, Element, Theme};

use std::ops::RangeInclusive;

pub fn main() -> iced::Result {
iced::application(
"QR Code Generator - Iced",
Expand All @@ -15,16 +19,21 @@ pub fn main() -> iced::Result {
struct QRGenerator {
data: String,
qr_code: Option<qr_code::Data>,
total_size: Option<f32>,
theme: Theme,
}

#[derive(Debug, Clone)]
enum Message {
DataChanged(String),
ToggleTotalSize(bool),
TotalSizeChanged(f32),
ThemeChanged(Theme),
}

impl QRGenerator {
const SIZE_RANGE: RangeInclusive<f32> = 200.0..=400.0;

fn update(&mut self, message: Message) {
match message {
Message::DataChanged(mut data) => {
Expand All @@ -38,6 +47,16 @@ impl QRGenerator {

self.data = data;
}
Message::ToggleTotalSize(enabled) => {
self.total_size = enabled.then_some(
Self::SIZE_RANGE.start()
+ (Self::SIZE_RANGE.end() - Self::SIZE_RANGE.start())
/ 2.0,
);
}
Message::TotalSizeChanged(total_size) => {
self.total_size = Some(total_size);
}
Message::ThemeChanged(theme) => {
self.theme = theme;
}
Expand All @@ -53,22 +72,37 @@ impl QRGenerator {
.size(30)
.padding(15);

let toggle_total_size = toggler(self.total_size.is_some())
.on_toggle(Message::ToggleTotalSize)
.label("Limit Total Size");

let choose_theme = row![
text("Theme:"),
pick_list(Theme::ALL, Some(&self.theme), Message::ThemeChanged,)
]
.spacing(10)
.align_y(Center);

let content = column![title, input, choose_theme]
.push_maybe(
self.qr_code
.as_ref()
.map(|data| qr_code(data).cell_size(10)),
)
.width(700)
.spacing(20)
.align_x(Center);
let content = column![
title,
input,
row![toggle_total_size, choose_theme]
.spacing(20)
.align_y(Center)
]
.push_maybe(self.total_size.map(|total_size| {
slider(Self::SIZE_RANGE, total_size, Message::TotalSizeChanged)
}))
.push_maybe(self.qr_code.as_ref().map(|data| {
if let Some(total_size) = self.total_size {
qr_code(data).total_size(total_size)
} else {
qr_code(data).cell_size(10.0)
}
}))
.width(700)
.spacing(20)
.align_x(Center);

center(content).padding(20).into()
}
Expand Down
2 changes: 1 addition & 1 deletion graphics/src/compositor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ impl Compositor for () {
async fn with_backend<W: Window + Clone>(
_settings: Settings,
_compatible_window: W,
_preffered_backend: Option<&str>,
_preferred_backend: Option<&str>,
) -> Result<Self, Error> {
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub enum Action {
QueryInformation(oneshot::Sender<Information>),
}

/// Contains informations about the system (e.g. system name, processor, memory, graphics adapter).
/// Contains information about the system (e.g. system name, processor, memory, graphics adapter).
#[derive(Clone, Debug)]
pub struct Information {
/// The operating system name
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl<T> Task<T> {
match self.0 {
None => task,
Some(first) => match task.0 {
None => Task::none(),
None => Task(Some(first)),
Some(second) => Task(Some(boxed_stream(first.chain(second)))),
},
}
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ pub fn resize_events() -> Subscription<(Id, Size)> {
})
}

/// Subscribes to all [`Event::CloseRequested`] occurences in the running application.
/// Subscribes to all [`Event::CloseRequested`] occurrences in the running application.
pub fn close_requests() -> Subscription<Id> {
event::listen_with(|event, _status, id| {
if let crate::core::Event::Window(Event::CloseRequested) = event {
Expand Down
2 changes: 1 addition & 1 deletion wgpu/src/geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub enum Geometry {
Cached(Cache),
}

#[derive(Debug, Clone)]
#[derive(Debug, Clone, Default)]
pub struct Cache {
pub meshes: Option<triangle::Cache>,
pub images: Option<Arc<[Image]>>,
Expand Down
4 changes: 2 additions & 2 deletions widget/src/button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,9 +480,9 @@ pub struct Style {
pub background: Option<Background>,
/// The text [`Color`] of the button.
pub text_color: Color,
/// The [`Border`] of the buton.
/// The [`Border`] of the button.
pub border: Border,
/// The [`Shadow`] of the butoon.
/// The [`Shadow`] of the button.
pub shadow: Shadow,
}

Expand Down
4 changes: 2 additions & 2 deletions widget/src/checkbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ pub struct Style {
pub background: Background,
/// The icon [`Color`] of the checkbox.
pub icon_color: Color,
/// The [`Border`] of hte checkbox.
/// The [`Border`] of the checkbox.
pub border: Border,
/// The text [`Color`] of the checkbox.
pub text_color: Option<Color>,
Expand Down Expand Up @@ -600,7 +600,7 @@ pub fn success(theme: &Theme, status: Status) -> Style {
}
}

/// A danger checkbox; denoting a negaive toggle.
/// A danger checkbox; denoting a negative toggle.
pub fn danger(theme: &Theme, status: Status) -> Style {
let palette = theme.extended_palette();

Expand Down
19 changes: 8 additions & 11 deletions widget/src/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,24 +320,21 @@ where
viewport: &Rectangle,
) {
if let Some(clipped_viewport) = layout.bounds().intersection(viewport) {
let viewport = if self.clip {
&clipped_viewport
} else {
viewport
};

for ((child, state), layout) in self
.children
.iter()
.zip(&tree.children)
.zip(layout.children())
.filter(|(_, layout)| layout.bounds().intersects(viewport))
{
child.as_widget().draw(
state,
renderer,
theme,
style,
layout,
cursor,
if self.clip {
&clipped_viewport
} else {
viewport
},
state, renderer, theme, style, layout, cursor, viewport,
);
}
}
Expand Down
4 changes: 2 additions & 2 deletions widget/src/combo_box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -608,8 +608,8 @@ where
..
}) = event
{
let shift_modifer = modifiers.shift();
match (named_key, shift_modifer) {
let shift_modifier = modifiers.shift();
match (named_key, shift_modifier) {
(key::Named::Enter, _) => {
if let Some(index) = &menu.hovered_option {
if let Some(option) =
Expand Down
57 changes: 34 additions & 23 deletions widget/src/lazy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,29 +270,40 @@ where
renderer: &Renderer,
translation: Vector,
) -> Option<overlay::Element<'_, Message, Theme, Renderer>> {
let overlay = Overlay(Some(
InnerBuilder {
cell: self.element.borrow().as_ref().unwrap().clone(),
element: self
.element
.borrow()
.as_ref()
.unwrap()
.borrow_mut()
.take()
.unwrap(),
tree: &mut tree.children[0],
overlay_builder: |element, tree| {
element
.as_widget_mut()
.overlay(tree, layout, renderer, translation)
.map(|overlay| RefCell::new(Nested::new(overlay)))
},
}
.build(),
));

Some(overlay::Element::new(Box::new(overlay)))
let overlay = InnerBuilder {
cell: self.element.borrow().as_ref().unwrap().clone(),
element: self
.element
.borrow()
.as_ref()
.unwrap()
.borrow_mut()
.take()
.unwrap(),
tree: &mut tree.children[0],
overlay_builder: |element, tree| {
element
.as_widget_mut()
.overlay(tree, layout, renderer, translation)
.map(|overlay| RefCell::new(Nested::new(overlay)))
},
}
.build();

#[allow(clippy::redundant_closure_for_method_calls)]
if overlay.with_overlay(|overlay| overlay.is_some()) {
Some(overlay::Element::new(Box::new(Overlay(Some(overlay)))))
} else {
let heads = overlay.into_heads();

// - You may not like it, but this is what peak performance looks like
// - TODO: Get rid of ouroboros, for good
// - What?!
*self.element.borrow().as_ref().unwrap().borrow_mut() =
Some(heads.element);

None
}
}
}

Expand Down
Loading

0 comments on commit 8c4cc0b

Please sign in to comment.