From 70b2c592b284965382182098b0b90b40bdac9965 Mon Sep 17 00:00:00 2001 From: Claire Neveu Date: Thu, 4 Apr 2024 16:12:45 -0400 Subject: [PATCH] feat: Add orientation support for custom label and button --- docs/modules/Clock.md | 1 + docs/modules/Custom.md | 2 + src/config/common.rs | 20 +++++++++ src/modules/clock.rs | 13 ++---- src/modules/custom/box.rs | 10 ++--- src/modules/custom/button.rs | 8 ++++ src/modules/custom/label.rs | 7 +++ src/modules/custom/mod.rs | 11 ----- src/modules/custom/progress.rs | 15 ++++--- src/modules/custom/slider.rs | 15 ++++--- test-configs/orientation.yaml | 82 ++++++++++++++++++++++++++++++++++ 11 files changed, 145 insertions(+), 39 deletions(-) create mode 100644 test-configs/orientation.yaml diff --git a/docs/modules/Clock.md b/docs/modules/Clock.md index 28630ff..627be83 100644 --- a/docs/modules/Clock.md +++ b/docs/modules/Clock.md @@ -13,6 +13,7 @@ Clicking on the widget opens a popup with the time and a calendar. | `format` | `string` | `%d/%m/%Y %H:%M` | Date/time format string. Pango markup is supported. | | `format_popup` | `string` | `%H:%M:%S` | Date/time format string to display in the popup header. Pango markup is supported. | | `locale` | `string` | `$LC_TIME` or `$LANG` or `'POSIX'` | Locale to use (eg `en_GB`). Defaults to the system language (reading from env var). | +| `orientation` | `'horizontal'` or `'vertical'` (shorthand: `'h'` or `'v'`) | `'horizontal'` | Orientation of the time on the clock button. | > Detail on available tokens can be found here: diff --git a/docs/modules/Custom.md b/docs/modules/Custom.md index 4d9a44b..f9e718f 100644 --- a/docs/modules/Custom.md +++ b/docs/modules/Custom.md @@ -57,6 +57,7 @@ A text label. Pango markup is supported. | Name | Type | Default | Description | |---------|-------------------------------------------------|---------|---------------------------------------------------------------------| | `label` | [Dynamic String](dynamic-values#dynamic-string) | `null` | Widget text label. Pango markup and embedded scripts are supported. | +| `orientation` | `'horizontal'` or `'vertical'` (shorthand: `'h'` or `'v'`) | `'horizontal'` | Orientation of the label. | #### Button @@ -69,6 +70,7 @@ A clickable button, which can run a command when clicked. | `label` | [Dynamic String](dynamic-values#dynamic-string) | `null` | Widget text label. Pango markup and embedded scripts are supported. Ignored if `widgets` is set. | | `widgets` | `(Module or Widget)[]` | `[]` | List of modules/widgets to add to this button. | | `on_click` | `string [command]` | `null` | Command to execute. More on this [below](#commands). | +| `orientation` | `'horizontal'` or `'vertical'` (shorthand: `'h'` or `'v'`) | `'horizontal'` | Orientation of the button. | #### Image diff --git a/src/config/common.rs b/src/config/common.rs index 876334a..bc8ba20 100644 --- a/src/config/common.rs +++ b/src/config/common.rs @@ -43,10 +43,30 @@ pub enum TransitionType { #[derive(Debug, Deserialize, Clone)] #[serde(rename_all = "snake_case")] pub enum ModuleOrientation { + #[serde(alias = "h")] Horizontal, + #[serde(alias = "v")] Vertical, } +impl ModuleOrientation { + pub const fn to_angle(&self) -> f64 { + match self { + Self::Horizontal => 0.0, + Self::Vertical => 90.0 + } + } +} + +impl From for Orientation { + fn from(o: ModuleOrientation) -> Self { + match o { + ModuleOrientation::Horizontal => Orientation::Horizontal, + ModuleOrientation::Vertical => Orientation::Vertical + } + } +} + impl Default for ModuleOrientation { fn default() -> Self { ModuleOrientation::Horizontal diff --git a/src/modules/clock.rs b/src/modules/clock.rs index 295ae13..602c6e4 100644 --- a/src/modules/clock.rs +++ b/src/modules/clock.rs @@ -101,15 +101,10 @@ impl Module