Skip to content

Instantly share code, notes, and snippets.

@sowbug
Created October 19, 2022 19:30
Show Gist options
  • Save sowbug/6200cacc3d05329f1d0d75b1aa07a81b to your computer and use it in GitHub Desktop.
Save sowbug/6200cacc3d05329f1d0d75b1aa07a81b to your computer and use it in GitHub Desktop.
$ 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