1
0
Fork 0
mirror of https://github.com/Zedfrigg/ironbar.git synced 2025-07-01 18:51:04 +02:00

feat(clock): format option for popup header

This commit is contained in:
Jake Stanger 2023-06-30 11:10:19 +01:00
parent 7016f7f79e
commit bd90167f4e
No known key found for this signature in database
GPG key ID: C51FC8F9CB0BEA61
2 changed files with 25 additions and 18 deletions

View file

@ -8,9 +8,12 @@ Clicking on the widget opens a popup with the time and a calendar.
> Type: `clock` > Type: `clock`
| Name | Type | Default | Description | | Name | Type | Default | Description |
|----------|----------|------------------|------------------------------------------------------------------------------------------------------------------------------------------| |----------------|----------|------------------|---------------------------------------------------------|
| `format` | `string` | `%d/%m/%Y %H:%M` | Date/time format string. Detail on available tokens can be found here: <https://docs.rs/chrono/latest/chrono/format/strftime/index.html> | | `format` | `string` | `%d/%m/%Y %H:%M` | Date/time format string. |
| `format_popup` | `string` | `%H:%M:%S` | Date/time format string to display in the popup header. |
> Detail on available tokens can be found here: <https://docs.rs/chrono/latest/chrono/format/strftime/index.html>
<details> <details>
<summary>JSON</summary> <summary>JSON</summary>

View file

@ -23,6 +23,9 @@ pub struct ClockModule {
#[serde(default = "default_format")] #[serde(default = "default_format")]
format: String, format: String,
#[serde(default = "default_popup_format")]
format_popup: String,
#[serde(flatten)] #[serde(flatten)]
pub common: Option<CommonConfig>, pub common: Option<CommonConfig>,
} }
@ -31,6 +34,10 @@ fn default_format() -> String {
String::from("%d/%m/%Y %H:%M") String::from("%d/%m/%Y %H:%M")
} }
fn default_popup_format() -> String {
String::from("%H:%M:%S")
}
impl Module<Button> for ClockModule { impl Module<Button> for ClockModule {
type SendMessage = DateTime<Local>; type SendMessage = DateTime<Local>;
type ReceiveMessage = (); type ReceiveMessage = ();
@ -75,13 +82,12 @@ impl Module<Button> for ClockModule {
}); });
let format = self.format.clone(); let format = self.format.clone();
{
context.widget_rx.attach(None, move |date| { context.widget_rx.attach(None, move |date| {
let date_string = format!("{}", date.format(&format)); let date_string = format!("{}", date.format(&format));
label.set_label(&date_string); label.set_label(&date_string);
Continue(true) Continue(true)
}); });
}
let popup = self.into_popup(context.controller_tx, context.popup_rx, info); let popup = self.into_popup(context.controller_tx, context.popup_rx, info);
@ -101,7 +107,6 @@ impl Module<Button> for ClockModule {
let clock = Label::builder().halign(Align::Center).build(); let clock = Label::builder().halign(Align::Center).build();
add_class(&clock, "calendar-clock"); add_class(&clock, "calendar-clock");
let format = "%H:%M:%S";
container.add(&clock); container.add(&clock);
@ -109,13 +114,12 @@ impl Module<Button> for ClockModule {
add_class(&calendar, "calendar"); add_class(&calendar, "calendar");
container.add(&calendar); container.add(&calendar);
{ let format = self.format_popup;
rx.attach(None, move |date| { rx.attach(None, move |date| {
let date_string = format!("{}", date.format(format)); let date_string = format!("{}", date.format(&format));
clock.set_label(&date_string); clock.set_label(&date_string);
Continue(true) Continue(true)
}); });
}
container.show_all(); container.show_all();