tangled
alpha
login
or
join now
lesbian.skin
/
nanel
1
fork
atom
[MIRROR] https://codeberg.org/naomi/nanel
1
fork
atom
overview
issues
pulls
pipelines
Configurable format for DateTime module
lesbian.skin
1 year ago
170952f1
b7d59bbc
+53
-85
4 changed files
expand all
collapse all
unified
split
examples
default.ron
src
modules.rs
panel.rs
widgets
button_with_position.rs
+2
-3
examples/default.ron
···
22
22
),
23
23
DateTime(
24
24
calendar: true,
25
25
-
mm_dd_yyyy: false,
26
26
-
military: true,
27
27
-
seconds: false,
25
25
+
upper_format: "%H:%M", // https://docs.rs/chrono/latest/chrono/format/strftime/index.html
26
26
+
lower_format: "%d/%m/%Y",
28
27
),
29
28
NotificationTray,
30
29
ViewDesktop(show_on_hover: true, thin: true)
+34
-75
src/modules.rs
···
11
11
msg::{Message, NanelWindowType},
12
12
panel::label,
13
13
styles::{solid, transparent},
14
14
-
widgets::{icon, small_icon, taskbar_button, taskbar_button_thin, taskbar_button_with_info},
14
14
+
widgets::{
15
15
+
button_with_position::ButtonInfo, icon, small_icon, taskbar_button, taskbar_button_thin,
16
16
+
taskbar_button_with_info,
17
17
+
},
15
18
windows::{
16
19
calendar_menu, directory_menu, notification_menu, quick_settings_menu, start_menu,
17
20
systray_menu,
···
38
41
},
39
42
DateTime {
40
43
calendar: bool,
41
41
-
mm_dd_yyyy: bool,
42
42
-
military: bool,
43
43
-
seconds: bool,
44
44
+
upper_format: String,
45
45
+
lower_format: String,
44
46
},
45
47
NotificationTray,
46
48
ViewDesktop {
···
178
180
.into()
179
181
}
180
182
181
181
-
fn get_time(
182
182
-
time: DateTime<Local>,
183
183
-
mm_dd_yyyy: &bool,
184
184
-
military: &bool,
185
185
-
seconds: &bool,
186
186
-
) -> (String, String) {
187
187
-
let dd = time.day();
188
188
-
let dd = match dd {
189
189
-
x if x <= 9 => format!("0{}", x),
190
190
-
x => format!("{}", x),
191
191
-
};
192
192
-
let mm = time.month();
193
193
-
let mm = match mm {
194
194
-
x if x <= 9 => format!("0{}", x),
195
195
-
x => format!("{}", x),
196
196
-
};
197
197
-
let yyyy = time.year();
198
198
-
199
199
-
let date = match mm_dd_yyyy {
200
200
-
true => format!(" {}/{}/{} ", mm, dd, yyyy),
201
201
-
false => format!(" {}/{}/{} ", dd, mm, yyyy),
202
202
-
};
203
203
-
204
204
-
let h = time.hour();
205
205
-
let h = match military {
206
206
-
true => h,
207
207
-
false => {
208
208
-
if h > 12 {
209
209
-
h - 12
210
210
-
} else {
211
211
-
h
212
212
-
}
213
213
-
}
214
214
-
};
215
215
-
let h = match h {
216
216
-
x if x <= 9 => format!("0{}", x),
217
217
-
x => format!("{}", x),
218
218
-
};
219
219
-
let m = time.minute();
220
220
-
let m = match m {
221
221
-
x if x <= 9 => format!("0{}", x),
222
222
-
x => format!("{}", x),
223
223
-
};
224
224
-
let s = time.second();
225
225
-
let s = match s {
226
226
-
x if x <= 9 => format!("0{}", x),
227
227
-
x => format!("{}", x),
228
228
-
};
229
229
-
230
230
-
let time = match seconds {
231
231
-
true => format!(" {}:{}:{} ", h, m, s),
232
232
-
false => format!(" {}:{} ", h, m),
233
233
-
};
234
234
-
235
235
-
(date, time)
236
236
-
}
237
237
-
238
183
pub fn date_time<'a>(
239
184
datetime: DateTime<Local>,
240
240
-
mm_dd_yyyy: &bool,
241
241
-
military: &bool,
242
242
-
seconds: &bool,
185
185
+
calendar: &bool,
186
186
+
upper_format: &String,
187
187
+
lower_format: &String,
243
188
vertical: &bool,
244
189
) -> Element<'a, Message> {
245
245
-
let (date, time) = get_time(datetime, mm_dd_yyyy, military, seconds);
246
246
-
247
190
taskbar_button_with_info(
248
191
match vertical {
249
192
true => Into::<Element<Message>>::into(
250
193
row![text("TODO")].clip(false).align_y(Alignment::Center),
251
194
),
252
195
false => Into::<Element<Message>>::into(
253
253
-
column![label(time.as_str()), label(date.as_str())]
254
254
-
.clip(false)
255
255
-
.align_x(Alignment::Center),
196
196
+
column![
197
197
+
label(
198
198
+
(String::from(" ")
199
199
+
+ datetime.format(upper_format.as_str()).to_string().as_str()
200
200
+
+ " ")
201
201
+
.as_str()
202
202
+
),
203
203
+
label(
204
204
+
(String::from(" ")
205
205
+
+ datetime.format(lower_format.as_str()).to_string().as_str()
206
206
+
+ " ")
207
207
+
.as_str()
208
208
+
),
209
209
+
]
210
210
+
.clip(false)
211
211
+
.align_x(Alignment::Center),
256
212
),
257
213
},
258
214
false,
259
215
vertical,
260
216
transparent,
261
217
)
262
262
-
.on_press_with(|info| Message::UserToggledWindow {
263
263
-
x: info.position.x as i32,
264
264
-
y: info.position.y as i32,
265
265
-
viewport: (info.viewport.0 as i32, info.viewport.1 as i32),
266
266
-
window_type: NanelWindowType::Calendar,
267
267
-
container_id: calendar_menu::CALENDAR_MENU.clone(),
218
218
+
.on_press_with_maybe(match calendar {
219
219
+
true => Some(|info: ButtonInfo| Message::UserToggledWindow {
220
220
+
x: info.position.x as i32,
221
221
+
y: info.position.y as i32,
222
222
+
viewport: (info.viewport.0 as i32, info.viewport.1 as i32),
223
223
+
window_type: NanelWindowType::Calendar,
224
224
+
container_id: calendar_menu::CALENDAR_MENU.clone(),
225
225
+
}),
226
226
+
false => None,
268
227
})
269
228
.padding(1)
270
229
.into()
+6
-7
src/panel.rs
···
142
142
&self.is_vertical(),
143
143
),
144
144
Module::DateTime {
145
145
-
calendar: _,
146
146
-
mm_dd_yyyy,
147
147
-
military,
148
148
-
seconds,
145
145
+
calendar,
146
146
+
upper_format,
147
147
+
lower_format,
149
148
} => date_time(
150
149
self.datetime,
151
151
-
mm_dd_yyyy,
152
152
-
military,
153
153
-
seconds,
150
150
+
calendar,
151
151
+
upper_format,
152
152
+
lower_format,
154
153
&self.is_vertical(),
155
154
),
156
155
Module::ViewDesktop {
+11
src/widgets/button_with_position.rs
···
101
101
self
102
102
}
103
103
104
104
+
pub fn on_press_with_maybe(
105
105
+
mut self,
106
106
+
on_press: Option<impl Fn(ButtonInfo) -> Message + 'a>,
107
107
+
) -> Self {
108
108
+
self.on_press = match on_press {
109
109
+
Some(on_press) => Some(OnPress::Closure(Box::new(on_press))),
110
110
+
None => None,
111
111
+
};
112
112
+
self
113
113
+
}
114
114
+
104
115
/// Sets whether the contents of the [`ButtonWithPosition`] should be clipped on
105
116
/// overflow.
106
117
pub fn clip(mut self, clip: bool) -> Self {