diff options
-rw-r--r-- | Cargo.toml | 1 | ||||
-rw-r--r-- | examples/pure/nested_component/Cargo.toml | 12 | ||||
-rw-r--r-- | examples/pure/nested_component/src/main.rs | 166 |
3 files changed, 0 insertions, 179 deletions
@@ -89,7 +89,6 @@ members = [ "examples/pure/component", "examples/pure/counter", "examples/pure/game_of_life", - "examples/pure/nested_component", "examples/pure/pane_grid", "examples/pure/pick_list", "examples/pure/todos", diff --git a/examples/pure/nested_component/Cargo.toml b/examples/pure/nested_component/Cargo.toml deleted file mode 100644 index 6b1b3570..00000000 --- a/examples/pure/nested_component/Cargo.toml +++ /dev/null @@ -1,12 +0,0 @@ -[package] -name = "pure_nested_component" -version = "0.1.0" -authors = ["Héctor Ramón Jiménez <hector0193@gmail.com>"] -edition = "2021" -publish = false - -[dependencies] -iced = { path = "../../..", features = ["debug", "pure"] } -iced_native = { path = "../../../native" } -iced_lazy = { path = "../../../lazy", features = ["pure"] } -iced_pure = { path = "../../../pure" } diff --git a/examples/pure/nested_component/src/main.rs b/examples/pure/nested_component/src/main.rs deleted file mode 100644 index d2f0ac37..00000000 --- a/examples/pure/nested_component/src/main.rs +++ /dev/null @@ -1,166 +0,0 @@ -use iced::pure::container; -use iced::pure::{Element, Sandbox}; -use iced::{Length, Settings}; - -use counter::counter; - -pub fn main() -> iced::Result { - Component::run(Settings::default()) -} - -#[derive(Default)] -struct Component; - -#[derive(Debug, Clone, Copy)] -enum Message {} - -impl Sandbox for Component { - type Message = Message; - - fn new() -> Self { - Self::default() - } - - fn title(&self) -> String { - String::from("Component - Iced") - } - - fn update(&mut self, _message: Message) {} - - fn view(&self) -> Element<Message> { - container(counter()) - .padding(20) - .height(Length::Fill) - .center_y() - .into() - } -} - -mod counter { - use iced::pure::{column, text}; - use iced_lazy::pure::{self, Component}; - use iced_native::text; - use iced_pure::Element; - - use custom_button::custom_button; - - pub struct Counter; - - pub fn counter() -> Counter { - Counter::new() - } - - #[derive(Debug, Clone)] - pub enum Event { - IncrementPressed, - } - - impl Counter { - pub fn new() -> Self { - Self {} - } - } - - #[derive(Default)] - pub struct State { - count: u32, - } - - impl<Message, Renderer> Component<Message, Renderer> for Counter - where - Renderer: text::Renderer + 'static, - { - type State = State; - type Event = Event; - - fn update( - &mut self, - state: &mut Self::State, - event: Event, - ) -> Option<Message> { - match event { - Event::IncrementPressed => { - state.count += 1; - - None - } - } - } - - fn view(&self, state: &Self::State) -> Element<Event, Renderer> { - column() - .push(text(&state.count.to_string())) - .push(custom_button("Increment", Event::IncrementPressed)) - .into() - } - } - - impl<'a, Message, Renderer> From<Counter> for Element<'a, Message, Renderer> - where - Message: 'a, - Renderer: 'static + text::Renderer, - { - fn from(counter: Counter) -> Self { - pure::component(counter) - } - } - - mod custom_button { - use iced::pure::{button, text}; - use iced_lazy::pure::{self, Component}; - use iced_native::text; - use iced_pure::Element; - - pub struct CustomButton<'a, Message> { - text: &'a str, - on_press: Message, - } - - pub fn custom_button<'a, Message>( - text: &'a str, - on_press: Message, - ) -> CustomButton<'a, Message> { - CustomButton { text, on_press } - } - - #[derive(Clone)] - pub enum Event { - Press, - } - - impl<'a, Message, Renderer> Component<Message, Renderer> - for CustomButton<'a, Message> - where - Message: Clone, - Renderer: iced_native::Renderer + text::Renderer + 'static, - { - type State = (); - type Event = Event; - - fn update( - &mut self, - _state: &mut Self::State, - event: Event, - ) -> Option<Message> { - match event { - Event::Press => Some(self.on_press.clone()), - } - } - - fn view(&self, _state: &Self::State) -> Element<Event, Renderer> { - button(text(self.text)).on_press(Event::Press).into() - } - } - - impl<'a, Message, Renderer> From<CustomButton<'a, Message>> - for Element<'a, Message, Renderer> - where - Message: Clone + 'a, - Renderer: 'static + text::Renderer, - { - fn from(custom_button: CustomButton<'a, Message>) -> Self { - pure::component(custom_button) - } - } - } -} |