From 39ee45a98195eb958774a2d14bdcb50a8f5642ba Mon Sep 17 00:00:00 2001 From: edouard Date: Tue, 7 Jun 2022 18:35:10 +0200 Subject: [PATCH] fix --- src/app/view/vault.rs | 8 +++++- ui/src/component/collapse.rs | 47 ++++++++++++++---------------------- 2 files changed, 25 insertions(+), 30 deletions(-) diff --git a/src/app/view/vault.rs b/src/app/view/vault.rs index e4b112ce..672ba6e0 100644 --- a/src/app/view/vault.rs +++ b/src/app/view/vault.rs @@ -142,7 +142,13 @@ fn transaction_collapse<'a, T: 'a>( Container::new(Pure::new( state, collapse( - iced::pure::text(title).into(), + Box::new(move || { + iced::pure::row() + .push(iced::pure::text("hello")) + .push(iced::pure::text("hello-again")) + .width(Length::Fill) + .into() + }), Box::new(move || { iced::pure::column() .push(iced::pure::text(format!("{}", tx.txid()))) diff --git a/ui/src/component/collapse.rs b/ui/src/component/collapse.rs index 1671cdad..ac465b9d 100644 --- a/ui/src/component/collapse.rs +++ b/ui/src/component/collapse.rs @@ -8,63 +8,52 @@ use iced_native::text; use iced_pure::Element; pub fn collapse<'a, Message: 'a, Renderer: text::Renderer + 'static>( - header: Element<'a, Message, Renderer>, - second: Box Element<'a, Collapsed, Renderer>>, + header: Box Element<'a, Event, Renderer>>, + content: Box Element<'a, Event, Renderer>>, ) -> impl Into> { - Collapse { - header, - state: State { content: second }, - } + Collapse { header, content } } -struct Collapse<'a, Message, Renderer> { - header: Element<'a, Message, Renderer>, - state: State<'a, Collapsed, Renderer>, +struct Collapse<'a, Renderer> { + header: Box Element<'a, Event, Renderer>>, + content: Box Element<'a, Event, Renderer>>, } #[derive(Debug, Clone, Copy)] -pub struct Collapsed(bool); - -struct State<'a, Event, Renderer> { - content: Box Element<'a, Event, Renderer>>, -} +pub struct Event(bool); -impl<'a, Message, Renderer> Component for State<'a, Collapsed, Renderer> +impl<'a, Message, Renderer> Component for Collapse<'a, Renderer> where Renderer: text::Renderer + 'static, { type State = bool; - type Event = Collapsed; + type Event = Event; - fn update(&mut self, state: &mut Self::State, event: Collapsed) -> Option { + fn update(&mut self, state: &mut Self::State, event: Event) -> Option { *state = event.0; None } - fn view(&self, state: &Self::State) -> Element { + fn view(&self, state: &Self::State) -> Element { if *state { column() - .push(button("back").on_press(Collapsed(false))) + .push(button((self.header)()).on_press(Event(false))) .push((self.content)()) .into() } else { - button("collapse").on_press(Collapsed(true)).into() + column() + .push(button((self.header)()).on_press(Event(true))) + .into() } } } -impl<'a, Message, Renderer> From> for Element<'a, Message, Renderer> +impl<'a, Message, Renderer> From> for Element<'a, Message, Renderer> where Message: 'a, Renderer: 'static + text::Renderer, { - fn from(collapse: Collapse<'a, Message, Renderer>) -> Self { - column() - .push( - row() - .push(collapse.header) - .push(pure::component(collapse.state)), - ) - .into() + fn from(c: Collapse<'a, Renderer>) -> Self { + column().push(row().push(pure::component(c))).into() } }