From 7259609c7817ba322d81903a9e6a55d00e377f63 Mon Sep 17 00:00:00 2001 From: Ricky Kresslein Date: Wed, 10 Dec 2025 19:01:55 +0100 Subject: [PATCH 1/3] Upgrade for compatibility with Iced 0.14 --- Cargo.toml | 6 +++--- src/backend/mod.rs | 27 +++++++++++++-------------- src/widget.rs | 17 +++++++---------- 3 files changed, 23 insertions(+), 27 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5d46360..2738fba 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,8 +19,8 @@ members = [".", "examples/split-chart"] [dependencies] plotters = { version = "0.3", default-features = false } plotters-backend = "0.3" -iced_widget = { version = "0.13", features = ["canvas"] } -iced_graphics = "0.13" +iced_widget = { version = "0.14.0", features = ["canvas"] } +iced_graphics = "0.14.0" once_cell = "1" [dev-dependencies] @@ -30,7 +30,7 @@ plotters = { version = "0.3", default-features = false, features = [ "line_series", "point_series", ] } -iced = { version = "0.13", features = ["canvas", "tokio"] } +iced = { version = "0.14.0", features = ["canvas", "tokio"] } chrono = { version = "0.4", default-features = false } rand = "0.8" tokio = { version = "1", features = ["rt"], default-features = false } diff --git a/src/backend/mod.rs b/src/backend/mod.rs index 9ff2828..fd712a0 100644 --- a/src/backend/mod.rs +++ b/src/backend/mod.rs @@ -6,13 +6,11 @@ use std::collections::HashSet; +use iced_graphics::core::text::Alignment; use iced_graphics::core::text::Paragraph; use iced_widget::{ canvas, - core::{ - alignment::{Horizontal, Vertical}, - font, text, Font, Size, - }, + core::{alignment::Vertical, font, text, Font, Size}, text::Shaping, }; use once_cell::unsync::Lazy; @@ -208,9 +206,9 @@ where return Ok(()); } let horizontal_alignment = match style.anchor().h_pos { - text_anchor::HPos::Left => Horizontal::Left, - text_anchor::HPos::Right => Horizontal::Right, - text_anchor::HPos::Center => Horizontal::Center, + text_anchor::HPos::Left => Alignment::Left, + text_anchor::HPos::Right => Alignment::Right, + text_anchor::HPos::Center => Alignment::Center, }; let vertical_alignment = match style.anchor().v_pos { text_anchor::VPos::Top => Vertical::Top, @@ -224,12 +222,13 @@ where let text = canvas::Text { content: text.to_owned(), position: pos, + max_width: f32::INFINITY, color: cvt_color(&style.color()), size: (style.size() as f32).into(), line_height: Default::default(), font, - horizontal_alignment, - vertical_alignment, + align_x: horizontal_alignment, + align_y: vertical_alignment, shaping: self.shaping, }; //TODO: fix rotation until text rotation is supported by Iced @@ -265,9 +264,9 @@ where let font = style_to_font(style); let bounds = self.frame.size(); let horizontal_alignment = match style.anchor().h_pos { - text_anchor::HPos::Left => Horizontal::Left, - text_anchor::HPos::Right => Horizontal::Right, - text_anchor::HPos::Center => Horizontal::Center, + text_anchor::HPos::Left => Alignment::Left, + text_anchor::HPos::Right => Alignment::Right, + text_anchor::HPos::Center => Alignment::Center, }; let vertical_alignment = match style.anchor().v_pos { text_anchor::VPos::Top => Vertical::Top, @@ -281,8 +280,8 @@ where size: self.backend.default_size(), line_height: Default::default(), font, - horizontal_alignment, - vertical_alignment, + align_x: horizontal_alignment, + align_y: vertical_alignment, shaping: self.shaping, wrapping: iced_widget::core::text::Wrapping::Word, }); diff --git a/src/widget.rs b/src/widget.rs index 1c2d4d6..20246d3 100644 --- a/src/widget.rs +++ b/src/widget.rs @@ -9,7 +9,6 @@ use core::marker::PhantomData; use iced_widget::{ canvas::Event, core::{ - event, mouse::Cursor, renderer::Style, widget::{tree, Tree}, @@ -89,7 +88,7 @@ where #[inline] fn layout( - &self, + &mut self, _tree: &mut Tree, _renderer: &Renderer, limits: &iced_widget::core::layout::Limits, @@ -114,36 +113,34 @@ where } #[inline] - fn on_event( + fn update( &mut self, tree: &mut Tree, - event: iced_widget::core::Event, + event: &iced_widget::core::Event, layout: Layout<'_>, cursor: Cursor, _renderer: &Renderer, _clipboard: &mut dyn iced_widget::core::Clipboard, shell: &mut Shell<'_, Message>, _rectangle: &Rectangle, - ) -> event::Status { + ) { let bounds = layout.bounds(); let canvas_event = match event { - iced_widget::core::Event::Mouse(mouse_event) => Some(Event::Mouse(mouse_event)), + iced_widget::core::Event::Mouse(mouse_event) => Some(Event::Mouse(*mouse_event)), iced_widget::core::Event::Keyboard(keyboard_event) => { - Some(Event::Keyboard(keyboard_event)) + Some(Event::Keyboard(keyboard_event.clone())) } _ => None, }; if let Some(canvas_event) = canvas_event { let state = tree.state.downcast_mut::(); - let (event_status, message) = self.chart.update(state, canvas_event, bounds, cursor); + let (_, message) = self.chart.update(state, canvas_event, bounds, cursor); if let Some(message) = message { shell.publish(message); } - return event_status; } - event::Status::Ignored } fn mouse_interaction( From 0cf6a4fc5a7ebf69b15677536957865685413408 Mon Sep 17 00:00:00 2001 From: Ricky Kresslein Date: Thu, 11 Dec 2025 10:44:52 +0100 Subject: [PATCH 2/3] Update examples to use Iced 0.14 --- examples/cpu-monitor.rs | 13 +++++++------ examples/large-data.rs | 9 +++++---- examples/mouse_events.rs | 24 +++++++++++++++++++++--- examples/split-chart/Cargo.toml | 2 +- examples/split-chart/src/main.rs | 11 ++++++++--- 5 files changed, 42 insertions(+), 17 deletions(-) diff --git a/examples/cpu-monitor.rs b/examples/cpu-monitor.rs index aa87306..3033410 100644 --- a/examples/cpu-monitor.rs +++ b/examples/cpu-monitor.rs @@ -28,7 +28,7 @@ use std::{ use sysinfo::{CpuRefreshKind, RefreshKind, System}; const PLOT_SECONDS: usize = 60; //1 min -const TITLE_FONT_SIZE: u16 = 22; +const TITLE_FONT_SIZE: u32 = 22; const SAMPLE_EVERY: Duration = Duration::from_millis(1000); const FONT_BOLD: Font = Font { @@ -38,14 +38,15 @@ const FONT_BOLD: Font = Font { }; fn main() { - iced::application("CPU Monitor Example", State::update, State::view) + iced::application(State::new, State::update, State::view) + .title("CPU Monitor Example") .antialiasing(true) .default_font(Font::with_name("Noto Sans")) .subscription(|_| { const FPS: u64 = 50; iced::time::every(Duration::from_millis(1000 / FPS)).map(|_| Message::Tick) }) - .run_with(State::new) + .run() .unwrap(); } @@ -165,7 +166,7 @@ impl SystemChart { } } - fn view(&self) -> Element { + fn view(&self) -> Element<'_, Message> { if !self.is_initialized() { Text::new("Loading...") .align_x(Horizontal::Center) @@ -191,7 +192,7 @@ impl SystemChart { idx += 1; } while idx % self.items_per_row != 0 { - row = row.push(Space::new(Length::Fill, Length::Fixed(50.0))); + row = row.push(Space::new().width(Length::Fill).height(Length::Fixed(50.0))); idx += 1; } col = col.push(row); @@ -234,7 +235,7 @@ impl CpuUsageChart { self.cache.clear(); } - fn view(&self, idx: usize, chart_height: f32) -> Element { + fn view(&self, idx: usize, chart_height: f32) -> Element<'_, Message> { Column::new() .width(Length::Fill) .height(Length::Shrink) diff --git a/examples/large-data.rs b/examples/large-data.rs index 1032b36..3e978de 100644 --- a/examples/large-data.rs +++ b/examples/large-data.rs @@ -28,7 +28,7 @@ use rand::Rng; use std::time::Duration; use std::{collections::VecDeque, time::Instant}; -const TITLE_FONT_SIZE: u16 = 22; +const TITLE_FONT_SIZE: u32 = 22; const FONT_BOLD: Font = Font { family: font::Family::Name("Noto Sans"), @@ -37,10 +37,11 @@ const FONT_BOLD: Font = Font { }; fn main() { - iced::application("Large Data Example", State::update, State::view) + iced::application(State::new, State::update, State::view) + .title("Large Data Example") .antialiasing(true) .default_font(Font::with_name("Noto Sans")) - .run_with(State::new) + .run() .unwrap(); } @@ -145,7 +146,7 @@ impl ExampleChart { } } - fn view(&self) -> Element { + fn view(&self) -> Element<'_, Message> { let chart = ChartWidget::new(self) .width(Length::Fill) .height(Length::Fill); diff --git a/examples/mouse_events.rs b/examples/mouse_events.rs index 003d36e..bfd9dcd 100644 --- a/examples/mouse_events.rs +++ b/examples/mouse_events.rs @@ -26,6 +26,11 @@ struct State { } impl State { + fn new() -> Self { + Self { + chart: ArtChart::new(), + } + } fn update(&mut self, message: Message) { match message { Message::MouseEvent(event, point) => { @@ -45,7 +50,7 @@ impl State { } } - fn view(&self) -> Element { + fn view(&self) -> Element<'_, Message> { let content = Column::new() .spacing(20) .width(Length::Fill) @@ -75,7 +80,19 @@ struct ArtChart { } impl ArtChart { - fn view(&self) -> Element { + fn new() -> Self { + Self { + cache: Cache::new(), + points: Vec::new(), + lines: Vec::new(), + is_down: false, + current_position: None, + initial_down_position: None, + spec: RefCell::new(None), + } + } + + fn view(&self) -> Element<'_, Message> { let chart = ChartWidget::new(self) .width(Length::Fill) .height(Length::Fill); @@ -239,7 +256,8 @@ enum Message { } fn main() -> iced::Result { - iced::application("Art", State::update, State::view) + iced::application(State::new, State::update, State::view) + .title("Art") .antialiasing(true) .run() } diff --git a/examples/split-chart/Cargo.toml b/examples/split-chart/Cargo.toml index cf0f0bb..78bd00f 100644 --- a/examples/split-chart/Cargo.toml +++ b/examples/split-chart/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" publish = false [dependencies] -iced = { version = "0.13", features = ["canvas"] } +iced = { version = "0.14", features = ["canvas"] } plotters-iced = { path = "../../" } plotters = { version = "0.3", default-features = false, features = [ "chrono", diff --git a/examples/split-chart/src/main.rs b/examples/split-chart/src/main.rs index 33da546..9220965 100644 --- a/examples/split-chart/src/main.rs +++ b/examples/split-chart/src/main.rs @@ -31,7 +31,7 @@ use plotters::{coord::Shift, prelude::*}; use plotters_backend::DrawingBackend; use plotters_iced::{plotters_backend, Chart, ChartWidget, DrawingArea}; -const TITLE_FONT_SIZE: u16 = 22; +const TITLE_FONT_SIZE: u32 = 22; // antialiasing issue: https://github.com/iced-rs/iced/issues/1159 @@ -41,7 +41,8 @@ fn main() { console_log::init().expect("Initialize logger"); std::panic::set_hook(Box::new(console_error_panic_hook::hook)); } - let app = iced::application("Split Chart Example", State::update, State::view) + let app = iced::application(State::new, State::update, State::view) + .title("Split Chart Example") .antialiasing(cfg!(not(target_arch = "wasm32"))) .subscription(|_| window::frames().map(|_| Message::Tick)); app.run().unwrap(); @@ -59,6 +60,10 @@ struct State { } impl State { + fn new() -> Self { + Self { chart: MyChart } + } + fn update(&mut self, _message: Message) {} fn view(&self) -> Element<'_, Message> { @@ -83,7 +88,7 @@ impl State { struct MyChart; impl MyChart { - fn view(&self) -> Element { + fn view(&self) -> Element<'_, Message> { let chart = ChartWidget::new(self) .width(Length::Fill) .height(Length::Fill); From 872bd5a2036b12f09aa5485677306c82c298a1f0 Mon Sep 17 00:00:00 2001 From: Ricky Kresslein Date: Thu, 11 Dec 2025 10:52:27 +0100 Subject: [PATCH 3/3] Update wasm32 iced version --- examples/split-chart/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/split-chart/Cargo.toml b/examples/split-chart/Cargo.toml index 78bd00f..0d135cf 100644 --- a/examples/split-chart/Cargo.toml +++ b/examples/split-chart/Cargo.toml @@ -16,7 +16,7 @@ plotters = { version = "0.3", default-features = false, features = [ ] } [target.'cfg(target_arch = "wasm32")'.dependencies] -iced.version = "0.13" +iced.version = "0.14" iced.features = ["canvas", "debug", "webgl"] console_error_panic_hook = "0.1"