From ff2519b1d43d481987351a83b6dd7237524c21f0 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 27 Jul 2022 06:49:20 +0200 Subject: Replace stateful widgets with new `iced_pure` API --- examples/clock/src/main.rs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'examples/clock') diff --git a/examples/clock/src/main.rs b/examples/clock/src/main.rs index 48b4cd7b..8818fb54 100644 --- a/examples/clock/src/main.rs +++ b/examples/clock/src/main.rs @@ -1,10 +1,9 @@ -use iced::canvas::{ - self, Cache, Canvas, Cursor, Geometry, LineCap, Path, Stroke, -}; use iced::executor; +use iced::widget::canvas::{Cache, Cursor, Geometry, LineCap, Path, Stroke}; +use iced::widget::{canvas, container}; use iced::{ - Application, Color, Command, Container, Element, Length, Point, Rectangle, - Settings, Subscription, Theme, Vector, + Application, Color, Command, Element, Length, Point, Rectangle, Settings, + Subscription, Theme, Vector, }; pub fn main() -> iced::Result { @@ -69,10 +68,12 @@ impl Application for Clock { }) } - fn view(&mut self) -> Element { - let canvas = Canvas::new(self).width(Length::Fill).height(Length::Fill); + fn view(&self) -> Element { + let canvas = canvas(self as &Self) + .width(Length::Fill) + .height(Length::Fill); - Container::new(canvas) + container(canvas) .width(Length::Fill) .height(Length::Fill) .padding(20) @@ -81,8 +82,11 @@ impl Application for Clock { } impl canvas::Program for Clock { + type State = (); + fn draw( &self, + _state: &Self::State, _theme: &Theme, bounds: Rectangle, _cursor: Cursor, -- cgit