-
Notifications
You must be signed in to change notification settings - Fork 134
/
Copy pathoptions.rs
164 lines (149 loc) · 5.69 KB
/
options.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
// Copyright 2023 System76 <[email protected]>
// SPDX-License-Identifier: GPL-3.0-only
use super::Message;
use apply::Apply;
use cosmic::{
iced::Length,
theme,
widget::{button, container, horizontal_space, icon, list, row, settings, toggler},
Element,
};
use cosmic_settings_page::Section;
use cosmic_settings_page::{self as page, section};
use slotmap::SlotMap;
#[derive(Default)]
pub struct Page;
impl page::Page<crate::pages::Message> for Page {
#[allow(clippy::too_many_lines)]
fn content(
&self,
sections: &mut SlotMap<section::Entity, Section<crate::pages::Message>>,
) -> Option<page::Content> {
Some(vec![
sections.insert(super_key_action()),
sections.insert(window_controls()),
sections.insert(panel_dock_links()),
])
}
fn info(&self) -> page::Info {
page::Info::new("desktop-panel-options", "video-display-symbolic")
.title(fl!("desktop-panel-options"))
.description(fl!("desktop-panel-options", "desc"))
}
}
impl page::AutoBind<crate::pages::Message> for Page {
fn sub_pages(page: page::Insert<crate::pages::Message>) -> page::Insert<crate::pages::Message> {
page.sub_page::<super::panel::Page>()
.sub_page::<super::dock::Page>()
}
}
pub fn super_key_action() -> Section<crate::pages::Message> {
Section::default()
.title(fl!("super-key-action"))
.descriptions(vec![
fl!("super-key-action", "launcher").into(),
fl!("super-key-action", "workspaces").into(),
fl!("super-key-action", "applications").into(),
])
.view::<Page>(|_binder, _page, section| {
let descriptions = §ion.descriptions;
settings::view_section(§ion.title)
.add(settings::item(
&*descriptions[0],
horizontal_space(Length::Fill),
))
.add(settings::item(
&*descriptions[1],
horizontal_space(Length::Fill),
))
.add(settings::item(
&*descriptions[2],
horizontal_space(Length::Fill),
))
.into()
})
}
pub fn window_controls() -> Section<crate::pages::Message> {
Section::default()
.title(fl!("window-controls"))
.descriptions(vec![
fl!("window-controls", "minimize").into(),
fl!("window-controls", "maximize").into(),
])
.view::<Page>(|binder, _page, section| {
let desktop = binder
.page::<super::Page>()
.expect("desktop page not found");
let descriptions = §ion.descriptions;
settings::view_section(§ion.title)
.add(settings::item(
&*descriptions[0],
toggler(
None,
desktop.show_minimize_button,
Message::ShowMinimizeButton,
),
))
.add(settings::item(
&*descriptions[1],
toggler(
None,
desktop.show_maximize_button,
Message::ShowMaximizeButton,
),
))
.apply(Element::from)
.map(crate::pages::Message::Desktop)
})
}
pub fn panel_dock_links() -> Section<crate::pages::Message> {
Section::default()
.title(fl!("desktop-panels-and-applets"))
.view::<Page>(|binder, _page, section| {
// TODO probably a way of getting the entity and its info
let mut settings = settings::view_section(§ion.title);
settings = if let Some((panel_entity, panel_info)) =
binder.info.iter().find(|(_, v)| v.id == "panel")
{
let control = row::with_children(vec![
horizontal_space(Length::Fill).into(),
icon::from_name("go-next-symbolic").size(16).into(),
]);
settings.add(
settings::item::builder(panel_info.title.clone())
.description(panel_info.description.clone())
.control(control)
.spacing(16)
.apply(container)
.style(theme::Container::custom(list::style))
.apply(button)
.style(theme::Button::Transparent)
.on_press(crate::pages::Message::Page(panel_entity)),
)
} else {
settings
};
settings = if let Some((dock_entity, dock_info)) =
binder.info.iter().find(|(_, v)| v.id == "dock")
{
let control = row::with_children(vec![
horizontal_space(Length::Fill).into(),
icon::from_name("go-next-symbolic").size(16).into(),
]);
settings.add(
settings::item::builder(dock_info.title.clone())
.description(dock_info.description.clone())
.control(control)
.spacing(16)
.apply(container)
.style(theme::Container::custom(list::style))
.apply(button)
.style(theme::Button::Transparent)
.on_press(crate::pages::Message::Page(dock_entity)),
)
} else {
settings
};
Element::from(settings)
})
}