Implement theme styling for Canvas

This commit is contained in:
Héctor Ramón Jiménez 2022-06-07 05:24:43 +02:00
parent f92afa7950
commit fc13bb3d65
No known key found for this signature in database
GPG key ID: 140CC052C94F138E
10 changed files with 94 additions and 45 deletions

View file

@ -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(