Replace stateful widgets with new iced_pure API
This commit is contained in:
parent
c44267b85f
commit
ff2519b1d4
142 changed files with 3631 additions and 14494 deletions
|
|
@ -1,7 +1,5 @@
|
|||
use crate::{
|
||||
canvas::{Frame, Geometry},
|
||||
Primitive,
|
||||
};
|
||||
use crate::widget::canvas::{Frame, Geometry};
|
||||
use crate::Primitive;
|
||||
|
||||
use iced_native::Size;
|
||||
use std::{cell::RefCell, sync::Arc};
|
||||
|
|
|
|||
|
|
@ -2,11 +2,10 @@ use std::borrow::Cow;
|
|||
|
||||
use iced_native::{Point, Rectangle, Size, Vector};
|
||||
|
||||
use crate::{
|
||||
canvas::path,
|
||||
canvas::{Fill, Geometry, Path, Stroke, Text},
|
||||
triangle, Primitive,
|
||||
};
|
||||
use crate::triangle;
|
||||
use crate::widget::canvas::path;
|
||||
use crate::widget::canvas::{Fill, Geometry, Path, Stroke, Text};
|
||||
use crate::Primitive;
|
||||
|
||||
use lyon::tessellation;
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ mod builder;
|
|||
pub use arc::Arc;
|
||||
pub use builder::Builder;
|
||||
|
||||
use crate::canvas::LineDash;
|
||||
use crate::widget::canvas::LineDash;
|
||||
|
||||
use iced_native::{Point, Size};
|
||||
use lyon::algorithms::walk::{walk_along_path, RepeatedPattern, WalkerEvent};
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use crate::canvas::path::{arc, Arc, Path};
|
||||
use crate::widget::canvas::path::{arc, Arc, Path};
|
||||
|
||||
use iced_native::{Point, Size};
|
||||
use lyon::path::builder::SvgPathBuilder;
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
use crate::canvas::event::{self, Event};
|
||||
use crate::canvas::{Cursor, Geometry};
|
||||
|
||||
use iced_native::mouse;
|
||||
use iced_native::Rectangle;
|
||||
use crate::widget::canvas::event::{self, Event};
|
||||
use crate::widget::canvas::mouse;
|
||||
use crate::widget::canvas::{Cursor, Geometry};
|
||||
use crate::Rectangle;
|
||||
|
||||
/// The state and logic of a [`Canvas`].
|
||||
///
|
||||
|
|
@ -11,7 +10,10 @@ use iced_native::Rectangle;
|
|||
///
|
||||
/// [`Canvas`]: crate::widget::Canvas
|
||||
pub trait Program<Message, Theme = iced_native::Theme> {
|
||||
/// Updates the state of the [`Program`].
|
||||
/// The internal state mutated by the [`Program`].
|
||||
type State: Default + 'static;
|
||||
|
||||
/// Updates the [`State`](Self::State) of the [`Program`].
|
||||
///
|
||||
/// When a [`Program`] is used in a [`Canvas`], the runtime will call this
|
||||
/// method for each [`Event`].
|
||||
|
|
@ -23,7 +25,8 @@ pub trait Program<Message, Theme = iced_native::Theme> {
|
|||
///
|
||||
/// [`Canvas`]: crate::widget::Canvas
|
||||
fn update(
|
||||
&mut self,
|
||||
&self,
|
||||
_state: &mut Self::State,
|
||||
_event: Event,
|
||||
_bounds: Rectangle,
|
||||
_cursor: Cursor,
|
||||
|
|
@ -40,6 +43,7 @@ pub trait Program<Message, Theme = iced_native::Theme> {
|
|||
/// [`Cache`]: crate::widget::canvas::Cache
|
||||
fn draw(
|
||||
&self,
|
||||
state: &Self::State,
|
||||
theme: &Theme,
|
||||
bounds: Rectangle,
|
||||
cursor: Cursor,
|
||||
|
|
@ -53,6 +57,7 @@ pub trait Program<Message, Theme = iced_native::Theme> {
|
|||
/// [`Canvas`]: crate::widget::Canvas
|
||||
fn mouse_interaction(
|
||||
&self,
|
||||
_state: &Self::State,
|
||||
_bounds: Rectangle,
|
||||
_cursor: Cursor,
|
||||
) -> mouse::Interaction {
|
||||
|
|
@ -60,33 +65,38 @@ pub trait Program<Message, Theme = iced_native::Theme> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T, Message, Theme> Program<Message, Theme> for &mut T
|
||||
impl<Message, Theme, T> Program<Message, Theme> for &T
|
||||
where
|
||||
T: Program<Message, Theme>,
|
||||
{
|
||||
type State = T::State;
|
||||
|
||||
fn update(
|
||||
&mut self,
|
||||
&self,
|
||||
state: &mut Self::State,
|
||||
event: Event,
|
||||
bounds: Rectangle,
|
||||
cursor: Cursor,
|
||||
) -> (event::Status, Option<Message>) {
|
||||
T::update(self, event, bounds, cursor)
|
||||
T::update(self, state, event, bounds, cursor)
|
||||
}
|
||||
|
||||
fn draw(
|
||||
&self,
|
||||
state: &Self::State,
|
||||
theme: &Theme,
|
||||
bounds: Rectangle,
|
||||
cursor: Cursor,
|
||||
) -> Vec<Geometry> {
|
||||
T::draw(self, theme, bounds, cursor)
|
||||
T::draw(self, state, theme, bounds, cursor)
|
||||
}
|
||||
|
||||
fn mouse_interaction(
|
||||
&self,
|
||||
state: &Self::State,
|
||||
bounds: Rectangle,
|
||||
cursor: Cursor,
|
||||
) -> mouse::Interaction {
|
||||
T::mouse_interaction(self, bounds, cursor)
|
||||
T::mouse_interaction(self, state, bounds, cursor)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue