diff options
author | 2023-10-27 03:58:45 +0200 | |
---|---|---|
committer | 2023-10-27 03:58:45 +0200 | |
commit | 65823875791ecebf24d049cc0782e7475a37899b (patch) | |
tree | 1088c656ef7ad9782374952045022d2c104931b2 /examples | |
parent | 8cc19de254c37d3123d5ea1b6513f1f34d35c7c8 (diff) | |
parent | f1b1344d59fa7354615f560bd25ed01ad0c9f865 (diff) | |
download | iced-65823875791ecebf24d049cc0782e7475a37899b.tar.gz iced-65823875791ecebf24d049cc0782e7475a37899b.tar.bz2 iced-65823875791ecebf24d049cc0782e7475a37899b.zip |
Merge branch 'master' into text-editor
Diffstat (limited to 'examples')
-rw-r--r-- | examples/arc/src/main.rs | 2 | ||||
-rw-r--r-- | examples/bezier_tool/src/main.rs | 11 | ||||
-rw-r--r-- | examples/clock/src/main.rs | 4 | ||||
-rw-r--r-- | examples/download_progress/src/main.rs | 2 | ||||
-rw-r--r-- | examples/game_of_life/src/main.rs | 18 | ||||
-rw-r--r-- | examples/integration/src/controls.rs | 2 | ||||
-rw-r--r-- | examples/integration/src/main.rs | 2 | ||||
-rw-r--r-- | examples/integration/src/scene.rs | 1 | ||||
-rw-r--r-- | examples/lazy/src/main.rs | 4 | ||||
-rw-r--r-- | examples/modal/src/main.rs | 6 | ||||
-rw-r--r-- | examples/pane_grid/src/main.rs | 29 | ||||
-rw-r--r-- | examples/screenshot/Cargo.toml | 8 | ||||
-rw-r--r-- | examples/screenshot/src/main.rs | 36 | ||||
-rw-r--r-- | examples/scrollable/src/main.rs | 8 | ||||
-rw-r--r-- | examples/sierpinski_triangle/src/main.rs | 5 | ||||
-rw-r--r-- | examples/solar_system/src/main.rs | 4 | ||||
-rw-r--r-- | examples/system_information/src/main.rs | 4 | ||||
-rw-r--r-- | examples/toast/src/main.rs | 2 | ||||
-rw-r--r-- | examples/todos/src/main.rs | 5 | ||||
-rw-r--r-- | examples/tooltip/src/main.rs | 2 | ||||
-rw-r--r-- | examples/tour/src/main.rs | 4 | ||||
-rw-r--r-- | examples/visible_bounds/src/main.rs | 2 | ||||
-rw-r--r-- | examples/websocket/src/echo/server.rs | 5 |
23 files changed, 76 insertions, 90 deletions
diff --git a/examples/arc/src/main.rs b/examples/arc/src/main.rs index df565859..6a68cca1 100644 --- a/examples/arc/src/main.rs +++ b/examples/arc/src/main.rs @@ -37,7 +37,7 @@ impl Application for Arc { ( Arc { start: Instant::now(), - cache: Default::default(), + cache: Cache::default(), }, Command::none(), ) diff --git a/examples/bezier_tool/src/main.rs b/examples/bezier_tool/src/main.rs index 310be28f..56cb23ba 100644 --- a/examples/bezier_tool/src/main.rs +++ b/examples/bezier_tool/src/main.rs @@ -81,7 +81,7 @@ mod bezier { } pub fn request_redraw(&mut self) { - self.cache.clear() + self.cache.clear(); } } @@ -100,12 +100,9 @@ mod bezier { bounds: Rectangle, cursor: mouse::Cursor, ) -> (event::Status, Option<Curve>) { - let cursor_position = - if let Some(position) = cursor.position_in(bounds) { - position - } else { - return (event::Status::Ignored, None); - }; + let Some(cursor_position) = cursor.position_in(bounds) else { + return (event::Status::Ignored, None); + }; match event { Event::Mouse(mouse_event) => { diff --git a/examples/clock/src/main.rs b/examples/clock/src/main.rs index fae77bc0..920aa0c5 100644 --- a/examples/clock/src/main.rs +++ b/examples/clock/src/main.rs @@ -35,7 +35,7 @@ impl Application for Clock { Clock { now: time::OffsetDateTime::now_local() .unwrap_or_else(|_| time::OffsetDateTime::now_utc()), - clock: Default::default(), + clock: Cache::default(), }, Command::none(), ) @@ -141,7 +141,7 @@ impl<Message> canvas::Program<Message, Renderer> for Clock { frame.with_save(|frame| { frame.rotate(hand_rotation(self.now.second(), 60)); frame.stroke(&long_hand, thin_stroke()); - }) + }); }); vec![clock] diff --git a/examples/download_progress/src/main.rs b/examples/download_progress/src/main.rs index 001a1f8f..a2fcb275 100644 --- a/examples/download_progress/src/main.rs +++ b/examples/download_progress/src/main.rs @@ -123,7 +123,7 @@ impl Download { | State::Errored { .. } => { self.state = State::Downloading { progress: 0.0 }; } - _ => {} + State::Downloading { .. } => {} } } diff --git a/examples/game_of_life/src/main.rs b/examples/game_of_life/src/main.rs index e451cb06..96840143 100644 --- a/examples/game_of_life/src/main.rs +++ b/examples/game_of_life/src/main.rs @@ -406,12 +406,9 @@ mod grid { *interaction = Interaction::None; } - let cursor_position = - if let Some(position) = cursor.position_in(bounds) { - position - } else { - return (event::Status::Ignored, None); - }; + let Some(cursor_position) = cursor.position_in(bounds) else { + return (event::Status::Ignored, None); + }; let cell = Cell::at(self.project(cursor_position, bounds.size())); let is_populated = self.state.contains(&cell); @@ -472,7 +469,7 @@ mod grid { * (1.0 / self.scaling), )) } - _ => None, + Interaction::None => None, }; let event_status = match interaction { @@ -610,8 +607,7 @@ mod grid { frame.fill_text(Text { content: format!( - "{} cell{} @ {:?} ({})", - cell_count, + "{cell_count} cell{} @ {:?} ({})", if cell_count == 1 { "" } else { "s" }, self.last_tick_duration, self.last_queued_ticks @@ -677,7 +673,7 @@ mod grid { Interaction::None if cursor.is_over(bounds) => { mouse::Interaction::Crosshair } - _ => mouse::Interaction::default(), + Interaction::None => mouse::Interaction::default(), } } } @@ -793,7 +789,7 @@ mod grid { } } - for (cell, amount) in adjacent_life.iter() { + for (cell, amount) in &adjacent_life { match amount { 2 => {} 3 => { diff --git a/examples/integration/src/controls.rs b/examples/integration/src/controls.rs index 14e53ede..4714c397 100644 --- a/examples/integration/src/controls.rs +++ b/examples/integration/src/controls.rs @@ -19,7 +19,7 @@ impl Controls { pub fn new() -> Controls { Controls { background_color: Color::BLACK, - text: Default::default(), + text: String::default(), } } diff --git a/examples/integration/src/main.rs b/examples/integration/src/main.rs index 7945bd20..c26d52fe 100644 --- a/examples/integration/src/main.rs +++ b/examples/integration/src/main.rs @@ -254,7 +254,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> { { // We clear the frame - let mut render_pass = scene.clear( + let mut render_pass = Scene::clear( &view, &mut encoder, program.background_color(), diff --git a/examples/integration/src/scene.rs b/examples/integration/src/scene.rs index 90c7efbf..01808f40 100644 --- a/examples/integration/src/scene.rs +++ b/examples/integration/src/scene.rs @@ -16,7 +16,6 @@ impl Scene { } pub fn clear<'a>( - &self, target: &'a wgpu::TextureView, encoder: &'a mut wgpu::CommandEncoder, background_color: Color, diff --git a/examples/lazy/src/main.rs b/examples/lazy/src/main.rs index c6baa6a1..9bf17c56 100644 --- a/examples/lazy/src/main.rs +++ b/examples/lazy/src/main.rs @@ -27,7 +27,7 @@ impl Default for App { .into_iter() .map(From::from) .collect(), - input: Default::default(), + input: String::default(), order: Order::Ascending, } } @@ -107,7 +107,7 @@ impl From<&str> for Item { fn from(s: &str) -> Self { Self { name: s.to_owned(), - color: Default::default(), + color: Color::default(), } } } diff --git a/examples/modal/src/main.rs b/examples/modal/src/main.rs index c050d3cc..b0e2c81b 100644 --- a/examples/modal/src/main.rs +++ b/examples/modal/src/main.rs @@ -228,7 +228,9 @@ mod modal { use iced::alignment::Alignment; use iced::event; use iced::mouse; - use iced::{Color, Element, Event, Length, Point, Rectangle, Size}; + use iced::{ + BorderRadius, Color, Element, Event, Length, Point, Rectangle, Size, + }; /// A widget that centers a modal element over some base element pub struct Modal<'a, Message, Renderer> { @@ -474,7 +476,7 @@ mod modal { renderer.fill_quad( renderer::Quad { bounds: layout.bounds(), - border_radius: Default::default(), + border_radius: BorderRadius::default(), border_width: 0.0, border_color: Color::TRANSPARENT, }, diff --git a/examples/pane_grid/src/main.rs b/examples/pane_grid/src/main.rs index af87e2c0..aa3149bb 100644 --- a/examples/pane_grid/src/main.rs +++ b/examples/pane_grid/src/main.rs @@ -61,11 +61,8 @@ impl Application for Example { fn update(&mut self, message: Message) -> Command<Message> { match message { Message::Split(axis, pane) => { - let result = self.panes.split( - axis, - &pane, - Pane::new(self.panes_created), - ); + let result = + self.panes.split(axis, pane, Pane::new(self.panes_created)); if let Some((pane, _)) = result { self.focus = Some(pane); @@ -77,7 +74,7 @@ impl Application for Example { if let Some(pane) = self.focus { let result = self.panes.split( axis, - &pane, + pane, Pane::new(self.panes_created), ); @@ -90,8 +87,7 @@ impl Application for Example { } Message::FocusAdjacent(direction) => { if let Some(pane) = self.focus { - if let Some(adjacent) = - self.panes.adjacent(&pane, direction) + if let Some(adjacent) = self.panes.adjacent(pane, direction) { self.focus = Some(adjacent); } @@ -101,37 +97,34 @@ impl Application for Example { self.focus = Some(pane); } Message::Resized(pane_grid::ResizeEvent { split, ratio }) => { - self.panes.resize(&split, ratio); + self.panes.resize(split, ratio); } Message::Dragged(pane_grid::DragEvent::Dropped { pane, target, }) => { - self.panes.drop(&pane, target); + self.panes.drop(pane, target); } Message::Dragged(_) => {} Message::TogglePin(pane) => { - if let Some(Pane { is_pinned, .. }) = self.panes.get_mut(&pane) - { + if let Some(Pane { is_pinned, .. }) = self.panes.get_mut(pane) { *is_pinned = !*is_pinned; } } - Message::Maximize(pane) => self.panes.maximize(&pane), + Message::Maximize(pane) => self.panes.maximize(pane), Message::Restore => { self.panes.restore(); } Message::Close(pane) => { - if let Some((_, sibling)) = self.panes.close(&pane) { + if let Some((_, sibling)) = self.panes.close(pane) { self.focus = Some(sibling); } } Message::CloseFocused => { if let Some(pane) = self.focus { - if let Some(Pane { is_pinned, .. }) = self.panes.get(&pane) - { + if let Some(Pane { is_pinned, .. }) = self.panes.get(pane) { if !is_pinned { - if let Some((_, sibling)) = self.panes.close(&pane) - { + if let Some((_, sibling)) = self.panes.close(pane) { self.focus = Some(sibling); } } diff --git a/examples/screenshot/Cargo.toml b/examples/screenshot/Cargo.toml index dcd77439..77b108bd 100644 --- a/examples/screenshot/Cargo.toml +++ b/examples/screenshot/Cargo.toml @@ -7,7 +7,11 @@ publish = false [dependencies] iced.workspace = true -iced.features = ["debug", "image", "advanced"] +iced.features = ["debug", "image", "advanced", "tokio"] + +image.workspace = true +image.features = ["png"] + +tokio.workspace = true -image = { workspace = true, features = ["png"]} tracing-subscriber = "0.3"
\ No newline at end of file diff --git a/examples/screenshot/src/main.rs b/examples/screenshot/src/main.rs index 68c9d031..f781a401 100644 --- a/examples/screenshot/src/main.rs +++ b/examples/screenshot/src/main.rs @@ -184,8 +184,8 @@ impl Application for Example { .align_items(Alignment::Center); if let Some(crop_error) = &self.crop_error { - crop_controls = crop_controls - .push(text(format!("Crop error! \n{}", crop_error))); + crop_controls = + crop_controls.push(text(format!("Crop error! \n{crop_error}"))); } let mut controls = column![ @@ -221,9 +221,9 @@ impl Application for Example { if let Some(png_result) = &self.saved_png_path { let msg = match png_result { - Ok(path) => format!("Png saved as: {:?}!", path), + Ok(path) => format!("Png saved as: {path:?}!"), Err(msg) => { - format!("Png could not be saved due to:\n{:?}", msg) + format!("Png could not be saved due to:\n{msg:?}") } }; @@ -273,15 +273,20 @@ impl Application for Example { async fn save_to_png(screenshot: Screenshot) -> Result<String, PngError> { let path = "screenshot.png".to_string(); - img::save_buffer( - &path, - &screenshot.bytes, - screenshot.size.width, - screenshot.size.height, - ColorType::Rgba8, - ) - .map(|_| path) - .map_err(|err| PngError(format!("{:?}", err))) + + tokio::task::spawn_blocking(move || { + img::save_buffer( + &path, + &screenshot.bytes, + screenshot.size.width, + screenshot.size.height, + ColorType::Rgba8, + ) + .map(|_| path) + .map_err(|err| PngError(format!("{err:?}"))) + }) + .await + .expect("Blocking task to finish") } #[derive(Clone, Debug)] @@ -293,10 +298,7 @@ fn numeric_input( ) -> Element<'_, Option<u32>> { text_input( placeholder, - &value - .as_ref() - .map(ToString::to_string) - .unwrap_or_else(String::new), + &value.as_ref().map(ToString::to_string).unwrap_or_default(), ) .on_input(move |text| { if text.is_empty() { diff --git a/examples/scrollable/src/main.rs b/examples/scrollable/src/main.rs index 8c08d993..d82ea841 100644 --- a/examples/scrollable/src/main.rs +++ b/examples/scrollable/src/main.rs @@ -389,14 +389,14 @@ impl scrollable::StyleSheet for ScrollbarCustomStyle { background: style .active(&theme::Scrollable::default()) .background, - border_radius: 0.0.into(), + border_radius: 2.0.into(), border_width: 0.0, - border_color: Default::default(), + border_color: Color::default(), scroller: Scroller { color: Color::from_rgb8(250, 85, 134), - border_radius: 0.0.into(), + border_radius: 2.0.into(), border_width: 0.0, - border_color: Default::default(), + border_color: Color::default(), }, } } else { diff --git a/examples/sierpinski_triangle/src/main.rs b/examples/sierpinski_triangle/src/main.rs index 885d3c63..ef935c33 100644 --- a/examples/sierpinski_triangle/src/main.rs +++ b/examples/sierpinski_triangle/src/main.rs @@ -108,10 +108,7 @@ impl canvas::Program<Message> for SierpinskiGraph { bounds: Rectangle, cursor: mouse::Cursor, ) -> (event::Status, Option<Message>) { - let cursor_position = if let Some(position) = cursor.position_in(bounds) - { - position - } else { + let Some(cursor_position) = cursor.position_in(bounds) else { return (event::Status::Ignored, None); }; diff --git a/examples/solar_system/src/main.rs b/examples/solar_system/src/main.rs index 8fa8946e..8295dded 100644 --- a/examples/solar_system/src/main.rs +++ b/examples/solar_system/src/main.rs @@ -117,8 +117,8 @@ impl State { let (width, height) = window::Settings::default().size; State { - space_cache: Default::default(), - system_cache: Default::default(), + space_cache: canvas::Cache::default(), + system_cache: canvas::Cache::default(), start: now, now, stars: Self::generate_stars(width, height), diff --git a/examples/system_information/src/main.rs b/examples/system_information/src/main.rs index 633b6e2b..507431ee 100644 --- a/examples/system_information/src/main.rs +++ b/examples/system_information/src/main.rs @@ -105,8 +105,8 @@ impl Application for Example { ByteSize::kb(information.memory_total).to_string(); let memory_total = text(format!( - "Memory (total): {} kb ({})", - information.memory_total, memory_readable + "Memory (total): {} kb ({memory_readable})", + information.memory_total, )); let memory_text = if let Some(memory_used) = diff --git a/examples/toast/src/main.rs b/examples/toast/src/main.rs index 8570a38e..20c3dd42 100644 --- a/examples/toast/src/main.rs +++ b/examples/toast/src/main.rs @@ -639,7 +639,7 @@ mod toast { child .as_widget() .operate(state, layout, renderer, operation); - }) + }); }); } diff --git a/examples/todos/src/main.rs b/examples/todos/src/main.rs index 501bf67e..1ad3aba7 100644 --- a/examples/todos/src/main.rs +++ b/examples/todos/src/main.rs @@ -415,8 +415,7 @@ fn view_controls(tasks: &[Task], current_filter: Filter) -> Element<Message> { row![ text(format!( - "{} {} left", - tasks_left, + "{tasks_left} {} left", if tasks_left == 1 { "task" } else { "tasks" } )) .width(Length::Fill), @@ -444,7 +443,7 @@ pub enum Filter { } impl Filter { - fn matches(&self, task: &Task) -> bool { + fn matches(self, task: &Task) -> bool { match self { Filter::All => true, Filter::Active => !task.completed, diff --git a/examples/tooltip/src/main.rs b/examples/tooltip/src/main.rs index 35b862a8..a904cce0 100644 --- a/examples/tooltip/src/main.rs +++ b/examples/tooltip/src/main.rs @@ -40,7 +40,7 @@ impl Sandbox for Example { Position::Right => Position::FollowCursor, }; - self.position = position + self.position = position; } } } diff --git a/examples/tour/src/main.rs b/examples/tour/src/main.rs index 3e3a8ad7..d46e40d1 100644 --- a/examples/tour/src/main.rs +++ b/examples/tour/src/main.rs @@ -285,7 +285,7 @@ impl<'a> Step { is_showing_icon, .. } = self { - *is_showing_icon = toggle + *is_showing_icon = toggle; } } }; @@ -482,7 +482,7 @@ impl<'a> Step { column( Language::all() .iter() - .cloned() + .copied() .map(|language| { radio( language, diff --git a/examples/visible_bounds/src/main.rs b/examples/visible_bounds/src/main.rs index 42dfc24c..697badb4 100644 --- a/examples/visible_bounds/src/main.rs +++ b/examples/visible_bounds/src/main.rs @@ -94,7 +94,7 @@ impl Application for Example { data_row( label, match bounds { - Some(bounds) => format!("{:?}", bounds), + Some(bounds) => format!("{bounds:?}"), None => "not visible".to_string(), }, if bounds diff --git a/examples/websocket/src/echo/server.rs b/examples/websocket/src/echo/server.rs index 168a635e..a696a7a4 100644 --- a/examples/websocket/src/echo/server.rs +++ b/examples/websocket/src/echo/server.rs @@ -47,10 +47,7 @@ async fn user_connected(ws: WebSocket) { }); while let Some(result) = user_ws_rx.next().await { - let msg = match result { - Ok(msg) => msg, - Err(_) => break, - }; + let Ok(msg) = result else { break }; let _ = tx.send(msg).await; } |