ferrix_app/widgets/
separated_view.rs1use crate::messages::Message;
22use iced::{
23 Element, Length, Pixels,
24 widget::{Id, column, container, scrollable},
25};
26
27pub struct SeparatedView<'a> {
28 pub first_pane: Element<'a, Message>,
29 pub second_pane: Element<'a, Message>,
30 pub first_pane_id: Option<&'static str>,
31 pub second_pane_id: Option<&'static str>,
32 pub fpane_max_height: f32,
33}
34
35impl<'a> SeparatedView<'a> {
36 pub fn new(f: impl Into<Element<'a, Message>>, s: impl Into<Element<'a, Message>>) -> Self {
37 Self {
38 first_pane: f.into(),
39 second_pane: s.into(),
40 first_pane_id: None,
41 second_pane_id: None,
42 fpane_max_height: 170.,
43 }
44 }
45
46 pub fn set_fpane_id(mut self, id: &'static str) -> Self {
47 self.first_pane_id = Some(id);
48 self
49 }
50
51 pub fn set_spane_id(mut self, id: &'static str) -> Self {
52 self.second_pane_id = Some(id);
53 self
54 }
55
56 pub fn set_fpane_max_height(mut self, height: f32) -> Self {
57 self.fpane_max_height = height;
58 self
59 }
60
61 pub fn view(self) -> Element<'a, Message> {
62 let f = container(
63 scrollable(self.first_pane)
64 .width(Length::Fill)
65 .spacing(5)
66 .id(match self.first_pane_id {
67 Some(id) => Id::new(id),
68 None => Id::unique(),
69 }),
70 );
71 let s = container(
72 scrollable(self.second_pane)
73 .width(Length::Fill)
74 .spacing(5)
75 .id(match self.second_pane_id {
76 Some(id) => Id::new(id),
77 None => Id::unique(),
78 }),
79 );
80
81 container(
82 column![
83 f.height(Length::Shrink)
84 .max_height(Pixels(self.fpane_max_height)),
85 s,
86 ]
87 .spacing(5),
88 )
89 .into()
90 }
91}