Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
edouardparis committed Jun 7, 2022
1 parent 7d9b287 commit 39ee45a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 30 deletions.
8 changes: 7 additions & 1 deletion src/app/view/vault.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())))
Expand Down
47 changes: 18 additions & 29 deletions ui/src/component/collapse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn Fn() -> Element<'a, Collapsed, Renderer>>,
header: Box<dyn Fn() -> Element<'a, Event, Renderer>>,
content: Box<dyn Fn() -> Element<'a, Event, Renderer>>,
) -> impl Into<Element<'a, Message, Renderer>> {
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<dyn Fn() -> Element<'a, Event, Renderer>>,
content: Box<dyn Fn() -> Element<'a, Event, Renderer>>,
}

#[derive(Debug, Clone, Copy)]
pub struct Collapsed(bool);

struct State<'a, Event, Renderer> {
content: Box<dyn Fn() -> Element<'a, Event, Renderer>>,
}
pub struct Event(bool);

impl<'a, Message, Renderer> Component<Message, Renderer> for State<'a, Collapsed, Renderer>
impl<'a, Message, Renderer> Component<Message, Renderer> 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<Message> {
fn update(&mut self, state: &mut Self::State, event: Event) -> Option<Message> {
*state = event.0;
None
}

fn view(&self, state: &Self::State) -> Element<Collapsed, Renderer> {
fn view(&self, state: &Self::State) -> Element<Event, Renderer> {
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<Collapse<'a, Message, Renderer>> for Element<'a, Message, Renderer>
impl<'a, Message, Renderer> From<Collapse<'a, Renderer>> 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()
}
}

0 comments on commit 39ee45a

Please sign in to comment.