diff options
author | 2024-04-25 01:40:06 +0200 | |
---|---|---|
committer | 2024-04-25 01:40:06 +0200 | |
commit | 8b1c514c3816795437da2ec25c2cfc559ebe5b9a (patch) | |
tree | 65c52d4aeda943b2f243fac81efce98a479bdde5 /examples/bezier_tool | |
parent | 0c74d2645649a88799a894ed684a728d135043fa (diff) | |
download | iced-8b1c514c3816795437da2ec25c2cfc559ebe5b9a.tar.gz iced-8b1c514c3816795437da2ec25c2cfc559ebe5b9a.tar.bz2 iced-8b1c514c3816795437da2ec25c2cfc559ebe5b9a.zip |
Showcase new `Stack` widget in `bezier_tool` example
Diffstat (limited to 'examples/bezier_tool')
-rw-r--r-- | examples/bezier_tool/src/main.rs | 53 |
1 files changed, 35 insertions, 18 deletions
diff --git a/examples/bezier_tool/src/main.rs b/examples/bezier_tool/src/main.rs index 289c919b..ba51a00e 100644 --- a/examples/bezier_tool/src/main.rs +++ b/examples/bezier_tool/src/main.rs @@ -1,9 +1,11 @@ //! This example showcases an interactive `Canvas` for drawing Bézier curves. -use iced::widget::{button, column, text}; -use iced::{Alignment, Element, Length}; +use iced::alignment; +use iced::widget::{button, container, stack}; +use iced::{Element, Length, Theme}; pub fn main() -> iced::Result { iced::program("Bezier Tool - Iced", Example::update, Example::view) + .theme(|_| Theme::CatppuccinMocha) .antialiasing(true) .run() } @@ -35,16 +37,18 @@ impl Example { } fn view(&self) -> Element<Message> { - column![ - text("Bezier tool example").width(Length::Shrink).size(50), + container(stack![ self.bezier.view(&self.curves).map(Message::AddCurve), - button("Clear") - .style(button::danger) - .on_press(Message::Clear), - ] + container( + button("Clear") + .style(button::danger) + .on_press(Message::Clear) + ) + .padding(10) + .width(Length::Fill) + .align_x(alignment::Horizontal::Right), + ]) .padding(20) - .spacing(20) - .align_items(Alignment::Center) .into() } } @@ -139,22 +143,24 @@ mod bezier { &self, state: &Self::State, renderer: &Renderer, - _theme: &Theme, + theme: &Theme, bounds: Rectangle, cursor: mouse::Cursor, ) -> Vec<Geometry> { let content = self.state.cache.draw(renderer, bounds.size(), |frame| { - Curve::draw_all(self.curves, frame); + Curve::draw_all(self.curves, frame, theme); frame.stroke( &Path::rectangle(Point::ORIGIN, frame.size()), - Stroke::default().with_width(2.0), + Stroke::default() + .with_width(2.0) + .with_color(theme.palette().text), ); }); if let Some(pending) = state { - vec![content, pending.draw(renderer, bounds, cursor)] + vec![content, pending.draw(renderer, theme, bounds, cursor)] } else { vec![content] } @@ -182,7 +188,7 @@ mod bezier { } impl Curve { - fn draw_all(curves: &[Curve], frame: &mut Frame) { + fn draw_all(curves: &[Curve], frame: &mut Frame, theme: &Theme) { let curves = Path::new(|p| { for curve in curves { p.move_to(curve.from); @@ -190,7 +196,12 @@ mod bezier { } }); - frame.stroke(&curves, Stroke::default().with_width(2.0)); + frame.stroke( + &curves, + Stroke::default() + .with_width(2.0) + .with_color(theme.palette().text), + ); } } @@ -204,6 +215,7 @@ mod bezier { fn draw( &self, renderer: &Renderer, + theme: &Theme, bounds: Rectangle, cursor: mouse::Cursor, ) -> Geometry { @@ -213,7 +225,12 @@ mod bezier { match *self { Pending::One { from } => { let line = Path::line(from, cursor_position); - frame.stroke(&line, Stroke::default().with_width(2.0)); + frame.stroke( + &line, + Stroke::default() + .with_width(2.0) + .with_color(theme.palette().text), + ); } Pending::Two { from, to } => { let curve = Curve { @@ -222,7 +239,7 @@ mod bezier { control: cursor_position, }; - Curve::draw_all(&[curve], &mut frame); + Curve::draw_all(&[curve], &mut frame, theme); } }; } |