1
0
Fork 0
mirror of https://github.com/Zedfrigg/ironbar.git synced 2025-04-19 19:34:24 +02:00

feat: Add orientation support for clock

This commit is contained in:
Claire Neveu 2024-04-02 23:04:48 -04:00
parent 751bb7b95e
commit 702b0a63bf
3 changed files with 28 additions and 6 deletions

View file

@ -40,6 +40,19 @@ pub enum TransitionType {
SlideEnd, SlideEnd,
} }
#[derive(Debug, Deserialize, Clone)]
#[serde(rename_all = "snake_case")]
pub enum ModuleOrientation {
Horizontal,
Vertical,
}
impl Default for ModuleOrientation {
fn default() -> Self {
ModuleOrientation::Horizontal
}
}
impl TransitionType { impl TransitionType {
pub const fn to_revealer_transition_type( pub const fn to_revealer_transition_type(
&self, &self,

View file

@ -34,7 +34,7 @@ use color_eyre::Result;
use serde::Deserialize; use serde::Deserialize;
use std::collections::HashMap; use std::collections::HashMap;
pub use self::common::{CommonConfig, TransitionType}; pub use self::common::{CommonConfig, ModuleOrientation, TransitionType};
pub use self::truncate::TruncateMode; pub use self::truncate::TruncateMode;
#[derive(Debug, Deserialize, Clone)] #[derive(Debug, Deserialize, Clone)]

View file

@ -8,7 +8,7 @@ use serde::Deserialize;
use tokio::sync::{broadcast, mpsc}; use tokio::sync::{broadcast, mpsc};
use tokio::time::sleep; use tokio::time::sleep;
use crate::config::CommonConfig; use crate::config::{CommonConfig, ModuleOrientation};
use crate::gtk_helpers::IronbarGtkExt; use crate::gtk_helpers::IronbarGtkExt;
use crate::modules::{ use crate::modules::{
Module, ModuleInfo, ModuleParts, ModulePopup, ModuleUpdateEvent, PopupButton, WidgetContext, Module, ModuleInfo, ModuleParts, ModulePopup, ModuleUpdateEvent, PopupButton, WidgetContext,
@ -31,6 +31,9 @@ pub struct ClockModule {
#[serde(default = "default_locale")] #[serde(default = "default_locale")]
locale: String, locale: String,
#[serde(default)]
orientation: ModuleOrientation,
#[serde(flatten)] #[serde(flatten)]
pub common: Option<CommonConfig>, pub common: Option<CommonConfig>,
} }
@ -41,6 +44,7 @@ impl Default for ClockModule {
format: default_format(), format: default_format(),
format_popup: default_popup_format(), format_popup: default_popup_format(),
locale: default_locale(), locale: default_locale(),
orientation: ModuleOrientation::Horizontal,
common: Some(CommonConfig::default()), common: Some(CommonConfig::default()),
} }
} }
@ -97,10 +101,15 @@ impl Module<Button> for ClockModule {
info: &ModuleInfo, info: &ModuleInfo,
) -> Result<ModuleParts<Button>> { ) -> Result<ModuleParts<Button>> {
let button = Button::new(); let button = Button::new();
let label = Label::builder() let label = if matches!(self.orientation, ModuleOrientation::Vertical) {
.angle(info.bar_position.get_angle()) Label::builder()
.use_markup(true) .angle(info.bar_position.get_angle())
.build(); .use_markup(true)
} else {
Label::builder()
.use_markup(true)
}.build();
button.add(&label); button.add(&label);
let tx = context.tx.clone(); let tx = context.tx.clone();