Skip to main content

ferrix_app/
sidebar.rs

1/* sidebar.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
21//! Sidebar widget
22
23use iced::{
24    Alignment::Center,
25    Element, Length,
26    widget::{Id, column, container, row, scrollable, text},
27};
28
29use crate::{
30    Page, fl,
31    messages::Message,
32    widgets::{icon_button, sidebar_button},
33};
34
35pub fn sidebar<'a>(cur_page: Page) -> Element<'a, Message> {
36    let buttons = row![
37        icon_button("export", fl!("sidebar-export")).on_press(Message::SelectPage(Page::Export)),
38        icon_button("settings", fl!("sidebar-settings"))
39            .on_press(Message::SelectPage(Page::Settings)),
40        icon_button("about", fl!("sidebar-about")).on_press(Message::SelectPage(Page::About)),
41    ]
42    .spacing(5)
43    .align_y(Center);
44
45    let pages = [
46        Item::Group(fl!("sidebar-basic")),
47        Item::Page(Page::Dashboard),
48        Item::Page(Page::SystemMonitor),
49        Item::Group(fl!("sidebar-hardware")),
50        Item::Page(Page::Processors),
51        Item::Page(Page::CPUFrequency),
52        Item::Page(Page::CPUVulnerabilities),
53        Item::Page(Page::Memory),
54        Item::Page(Page::FileSystems),
55        Item::Page(Page::Network),
56        Item::Page(Page::DMI),
57        Item::Page(Page::Battery),
58        Item::Page(Page::Screen),
59        Item::Page(Page::Sensors),
60        Item::Group(fl!("sidebar-admin")),
61        Item::Page(Page::Distro),
62        Item::Page(Page::Users),
63        Item::Page(Page::Groups),
64        Item::Page(Page::Environment),
65        Item::Page(Page::SystemManager),
66        Item::Page(Page::Software),
67        Item::Group(fl!("sidebar-system")),
68        Item::Page(Page::Kernel),
69        Item::Page(Page::KModules),
70        Item::Page(Page::SystemMisc),
71        Item::Group(fl!("sidebar-manage")),
72        Item::Page(Page::Settings),
73        Item::Page(Page::About),
74    ];
75    let mut pages_list = iced::widget::Column::with_capacity(pages.len()).spacing(3);
76
77    for page in pages {
78        pages_list = pages_list.push(page.widget(cur_page));
79    }
80
81    container(column![
82        buttons,
83        scrollable(pages_list).spacing(5).id(Id::new("sidebar")),
84    ])
85    .padding(5)
86    .style(container::bordered_box)
87    .height(Length::Fill)
88    .into()
89}
90
91enum Item {
92    Group(String),
93    Page(Page),
94}
95
96impl Item {
97    pub fn widget<'a>(self, cur_page: Page) -> Element<'a, Message> {
98        match self {
99            Self::Group(name) => text(name).style(text::secondary).into(),
100            Self::Page(page) => sidebar_button(page, cur_page).into(),
101        }
102    }
103}