From c22269bff3085012d326a0df77bf27ad5bcb41b7 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 16 Mar 2024 05:33:47 +0100 Subject: Introduce `Program` API --- examples/vectorial_text/src/main.rs | 39 +++++++++++++------------------------ 1 file changed, 14 insertions(+), 25 deletions(-) (limited to 'examples/vectorial_text') diff --git a/examples/vectorial_text/src/main.rs b/examples/vectorial_text/src/main.rs index 0b9ea938..aa870716 100644 --- a/examples/vectorial_text/src/main.rs +++ b/examples/vectorial_text/src/main.rs @@ -3,18 +3,17 @@ use iced::mouse; use iced::widget::{ canvas, checkbox, column, horizontal_space, row, slider, text, }; -use iced::{ - Element, Length, Point, Rectangle, Renderer, Sandbox, Settings, Theme, - Vector, -}; +use iced::{Element, Length, Point, Rectangle, Renderer, Theme, Vector}; pub fn main() -> iced::Result { - VectorialText::run(Settings { - antialiasing: true, - ..Settings::default() - }) + iced::sandbox(VectorialText::update, VectorialText::view) + .theme(|_| Theme::Dark) + .title("Vectorial Text - Iced") + .antialiased() + .run() } +#[derive(Default)] struct VectorialText { state: State, } @@ -27,19 +26,7 @@ enum Message { ToggleJapanese(bool), } -impl Sandbox for VectorialText { - type Message = Message; - - fn new() -> Self { - Self { - state: State::new(), - } - } - - fn title(&self) -> String { - String::from("Vectorial Text - Iced") - } - +impl VectorialText { fn update(&mut self, message: Message) { match message { Message::SizeChanged(size) => { @@ -106,10 +93,6 @@ impl Sandbox for VectorialText { .padding(20) .into() } - - fn theme(&self) -> Theme { - Theme::Dark - } } struct State { @@ -170,3 +153,9 @@ impl canvas::Program for State { vec![geometry] } } + +impl Default for State { + fn default() -> Self { + State::new() + } +} -- cgit