Skip to main content

ferrix_app/widgets/
separated_view.rs

1/* separated_view.rs
2 *
3 * Copyright 2025-2026 Michail Krasnov <mskrasnov07@ya.ru>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
17 *
18 * SPDX-License-Identifier: GPL-3.0-or-later
19 */
20
21use 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}