diff options
| author | 2024-03-19 22:09:36 +0900 | |
|---|---|---|
| committer | 2024-03-19 22:09:36 +0900 | |
| commit | f3a1c785b2743e9c48c3d28df0c6772ce579d7c8 (patch) | |
| tree | 1b39799f45878d89b4f9e2f9bea8fa8a7ed07150 /examples/multitouch/src | |
| parent | c9453cd55d84f0dd2ad0050208863d036c98843f (diff) | |
| parent | 8ce16aba6204cb5c02a709cdf79c309f7b7e0196 (diff) | |
| download | iced-f3a1c785b2743e9c48c3d28df0c6772ce579d7c8.tar.gz iced-f3a1c785b2743e9c48c3d28df0c6772ce579d7c8.tar.bz2 iced-f3a1c785b2743e9c48c3d28df0c6772ce579d7c8.zip | |
Merge branch 'iced-rs:master' into viewer_content_fit
Diffstat (limited to '')
| -rw-r--r-- | examples/multitouch/src/main.rs | 73 | 
1 files changed, 15 insertions, 58 deletions
| diff --git a/examples/multitouch/src/main.rs b/examples/multitouch/src/main.rs index 956ad471..2453c7f5 100644 --- a/examples/multitouch/src/main.rs +++ b/examples/multitouch/src/main.rs @@ -2,101 +2,58 @@  //! a circle around each fingertip. This only works on touch-enabled  //! computers like Microsoft Surface.  use iced::mouse; +use iced::touch;  use iced::widget::canvas::event;  use iced::widget::canvas::stroke::{self, Stroke};  use iced::widget::canvas::{self, Canvas, Geometry}; -use iced::{ -    executor, touch, window, Application, Color, Command, Element, Length, -    Point, Rectangle, Renderer, Settings, Subscription, Theme, -}; +use iced::{Color, Element, Length, Point, Rectangle, Renderer, Theme};  use std::collections::HashMap;  pub fn main() -> iced::Result {      tracing_subscriber::fmt::init(); -    Multitouch::run(Settings { -        antialiasing: true, -        window: window::Settings { -            position: window::Position::Centered, -            ..window::Settings::default() -        }, -        ..Settings::default() -    }) +    iced::program("Multitouch - Iced", Multitouch::update, Multitouch::view) +        .antialiasing(true) +        .centered() +        .run()  } +#[derive(Default)]  struct Multitouch { -    state: State, -} - -#[derive(Debug)] -struct State {      cache: canvas::Cache,      fingers: HashMap<touch::Finger, Point>,  } -impl State { -    fn new() -> Self { -        Self { -            cache: canvas::Cache::new(), -            fingers: HashMap::new(), -        } -    } -} -  #[derive(Debug)]  enum Message {      FingerPressed { id: touch::Finger, position: Point },      FingerLifted { id: touch::Finger },  } -impl Application for Multitouch { -    type Executor = executor::Default; -    type Message = Message; -    type Theme = Theme; -    type Flags = (); - -    fn new(_flags: ()) -> (Self, Command<Message>) { -        ( -            Multitouch { -                state: State::new(), -            }, -            Command::none(), -        ) -    } - -    fn title(&self) -> String { -        String::from("Multitouch - Iced") -    } - -    fn update(&mut self, message: Message) -> Command<Message> { +impl Multitouch { +    fn update(&mut self, message: Message) {          match message {              Message::FingerPressed { id, position } => { -                self.state.fingers.insert(id, position); -                self.state.cache.clear(); +                self.fingers.insert(id, position); +                self.cache.clear();              }              Message::FingerLifted { id } => { -                self.state.fingers.remove(&id); -                self.state.cache.clear(); +                self.fingers.remove(&id); +                self.cache.clear();              }          } - -        Command::none() -    } - -    fn subscription(&self) -> Subscription<Message> { -        Subscription::none()      }      fn view(&self) -> Element<Message> { -        Canvas::new(&self.state) +        Canvas::new(self)              .width(Length::Fill)              .height(Length::Fill)              .into()      }  } -impl canvas::Program<Message> for State { +impl canvas::Program<Message> for Multitouch {      type State = ();      fn update( | 
