Created
October 19, 2022 19:30
-
-
Save sowbug/6200cacc3d05329f1d0d75b1aa07a81b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ diff ../iced/examples/counter/src/main.rs src/main.rs | |
1,3c1,4 | |
< use iced::{ | |
< button, Alignment, Button, Column, Element, Sandbox, Settings, Text, | |
< }; | |
--- | |
> use iced::Sandbox; | |
> use iced::{button, Alignment, Button, Column, Container, Element, Settings, Text}; | |
> use std::cell::RefCell; | |
> use std::rc::Rc; | |
8a10,35 | |
> #[derive(Debug, Default)] | |
> struct Thing { | |
> name: String, | |
> } | |
> | |
> impl Thing { | |
> pub fn view(&mut self) -> Element<Message> { | |
> Container::new(Text::new(self.name.clone())).into() | |
> } | |
> } | |
> | |
> #[derive(Debug, Default)] | |
> struct OtherStruct { | |
> pub things: Vec<Rc<RefCell<Thing>>>, | |
> } | |
> | |
> impl OtherStruct { | |
> fn new() -> Self { | |
> Self { | |
> things: vec![Rc::new(RefCell::new(Thing { | |
> name: "hello".to_string(), | |
> }))], | |
> } | |
> } | |
> } | |
> | |
13a41 | |
> o: OtherStruct, | |
26c54,57 | |
< Self::default() | |
--- | |
> Self { | |
> o: OtherStruct::new(), | |
> ..Default::default() | |
> } | |
44a76,83 | |
> let other_view = self | |
> .o | |
> .things | |
> .iter_mut() | |
> .enumerate() | |
> .fold(Column::new(), |column, (_, item)| { | |
> column.push(item.borrow_mut().view()) | |
> }); | |
56a96 | |
> .push(other_view) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment