diff options
| author | 2022-06-07 05:24:43 +0200 | |
|---|---|---|
| committer | 2022-06-07 05:24:43 +0200 | |
| commit | fc13bb3d65c85cfad9f231c0776d3a45f4fbf480 (patch) | |
| tree | 224bbe489cc8e90ab0824c2b745403958667077a /graphics/src/widget/pure | |
| parent | f92afa795062cf38f0f99d0a1545a990ed35b09c (diff) | |
| download | iced-fc13bb3d65c85cfad9f231c0776d3a45f4fbf480.tar.gz iced-fc13bb3d65c85cfad9f231c0776d3a45f4fbf480.tar.bz2 iced-fc13bb3d65c85cfad9f231c0776d3a45f4fbf480.zip  | |
Implement theme styling for `Canvas`
Diffstat (limited to '')
| -rw-r--r-- | graphics/src/widget/pure/canvas.rs | 31 | ||||
| -rw-r--r-- | graphics/src/widget/pure/canvas/program.rs | 10 | 
2 files changed, 23 insertions, 18 deletions
diff --git a/graphics/src/widget/pure/canvas.rs b/graphics/src/widget/pure/canvas.rs index d53b20f6..d9c7e66b 100644 --- a/graphics/src/widget/pure/canvas.rs +++ b/graphics/src/widget/pure/canvas.rs @@ -30,10 +30,10 @@ use std::marker::PhantomData;  /// #     pub mod pure {  /// #         pub use iced_graphics::pure::canvas;  /// #     } -/// #     pub use iced_native::{Color, Rectangle}; +/// #     pub use iced_native::{Color, Rectangle, Theme};  /// # }  /// use iced::pure::canvas::{self, Canvas, Cursor, Fill, Frame, Geometry, Path, Program}; -/// use iced::{Color, Rectangle}; +/// use iced::{Color, Rectangle, Theme};  ///  /// // First, we define the data we need for drawing  /// #[derive(Debug)] @@ -45,7 +45,7 @@ use std::marker::PhantomData;  /// impl Program<()> for Circle {  ///     type State = ();  /// -///     fn draw(&self, _state: &(), bounds: Rectangle, _cursor: Cursor) -> Vec<Geometry>{ +///     fn draw(&self, _state: &(), _theme: &Theme, bounds: Rectangle, _cursor: Cursor) -> Vec<Geometry>{  ///         // We prepare a new `Frame`  ///         let mut frame = Frame::new(bounds.size());  /// @@ -64,19 +64,20 @@ use std::marker::PhantomData;  /// let canvas = Canvas::new(Circle { radius: 50.0 });  /// ```  #[derive(Debug)] -pub struct Canvas<Message, P> +pub struct Canvas<Message, Theme, P>  where -    P: Program<Message>, +    P: Program<Message, Theme>,  {      width: Length,      height: Length,      program: P,      message_: PhantomData<Message>, +    theme_: PhantomData<Theme>,  } -impl<Message, P> Canvas<Message, P> +impl<Message, Theme, P> Canvas<Message, Theme, P>  where -    P: Program<Message>, +    P: Program<Message, Theme>,  {      const DEFAULT_SIZE: u16 = 100; @@ -87,6 +88,7 @@ where              height: Length::Units(Self::DEFAULT_SIZE),              program,              message_: PhantomData, +            theme_: PhantomData,          }      } @@ -103,9 +105,9 @@ where      }  } -impl<Message, P, B, T> Widget<Message, Renderer<B, T>> for Canvas<Message, P> +impl<Message, P, B, T> Widget<Message, Renderer<B, T>> for Canvas<Message, T, P>  where -    P: Program<Message>, +    P: Program<Message, T>,      B: Backend,  {      fn tag(&self) -> tree::Tag { @@ -194,7 +196,7 @@ where          &self,          tree: &Tree,          renderer: &mut Renderer<B, T>, -        _theme: &T, +        theme: &T,          _style: &renderer::Style,          layout: Layout<'_>,          cursor_position: Point, @@ -216,7 +218,7 @@ where              renderer.draw_primitive(Primitive::Group {                  primitives: self                      .program -                    .draw(state, bounds, cursor) +                    .draw(state, theme, bounds, cursor)                      .into_iter()                      .map(Geometry::into_primitive)                      .collect(), @@ -225,15 +227,16 @@ where      }  } -impl<'a, Message, P, B, T> From<Canvas<Message, P>> +impl<'a, Message, P, B, T> From<Canvas<Message, T, P>>      for Element<'a, Message, Renderer<B, T>>  where      Message: 'a, -    P: Program<Message> + 'a, +    P: Program<Message, T> + 'a,      B: Backend, +    T: 'a,  {      fn from( -        canvas: Canvas<Message, P>, +        canvas: Canvas<Message, T, P>,      ) -> Element<'a, Message, Renderer<B, T>> {          Element::new(canvas)      } diff --git a/graphics/src/widget/pure/canvas/program.rs b/graphics/src/widget/pure/canvas/program.rs index 058b364b..20c6406e 100644 --- a/graphics/src/widget/pure/canvas/program.rs +++ b/graphics/src/widget/pure/canvas/program.rs @@ -9,7 +9,7 @@ use crate::Rectangle;  /// application.  ///  /// [`Canvas`]: crate::widget::Canvas -pub trait Program<Message> { +pub trait Program<Message, Theme = iced_native::Theme> {      /// The internal state mutated by the [`Program`].      type State: Default + 'static; @@ -44,6 +44,7 @@ pub trait Program<Message> {      fn draw(          &self,          state: &Self::State, +        theme: &Theme,          bounds: Rectangle,          cursor: Cursor,      ) -> Vec<Geometry>; @@ -64,9 +65,9 @@ pub trait Program<Message> {      }  } -impl<Message, T> Program<Message> for &T +impl<Message, Theme, T> Program<Message, Theme> for &T  where -    T: Program<Message>, +    T: Program<Message, Theme>,  {      type State = T::State; @@ -83,10 +84,11 @@ where      fn draw(          &self,          state: &Self::State, +        theme: &Theme,          bounds: Rectangle,          cursor: Cursor,      ) -> Vec<Geometry> { -        T::draw(self, state, bounds, cursor) +        T::draw(self, state, theme, bounds, cursor)      }      fn mouse_interaction(  | 
