feat: Add orientation and direction support for sys info

This commit is contained in:
Claire Neveu 2024-04-05 13:28:47 -04:00
parent 70b2c592b2
commit 44be58594b
10 changed files with 66 additions and 36 deletions

View File

@ -19,6 +19,8 @@ Pango markup is supported.
| `interval.temps` | `integer` | `5` | Seconds between refreshing temperature data |
| `interval.disks` | `integer` | `5` | Seconds between refreshing disk data |
| `interval.network` | `integer` | `5` | Seconds between refreshing network data |
| `orientation` | `'horizontal'` or `'vertical'` (shorthand: `'h'` or `'v'`) | `'horizontal'` | Orientation of the labels. |
| `direction` | `'horizontal'` or `'vertical'` (shorthand: `'h'` or `'v'`) | `'horizontal'` | How the labels are laid out (not the rotation of an individual label). |
<details>
<summary>JSON</summary>

View File

@ -40,9 +40,10 @@ pub enum TransitionType {
SlideEnd,
}
#[derive(Debug, Deserialize, Clone)]
#[derive(Debug, Default, Deserialize, Clone, Copy)]
#[serde(rename_all = "snake_case")]
pub enum ModuleOrientation {
#[default]
#[serde(alias = "h")]
Horizontal,
#[serde(alias = "v")]
@ -50,10 +51,10 @@ pub enum ModuleOrientation {
}
impl ModuleOrientation {
pub const fn to_angle(&self) -> f64 {
pub const fn to_angle(self) -> f64 {
match self {
Self::Horizontal => 0.0,
Self::Vertical => 90.0
Self::Vertical => 90.0,
}
}
}
@ -61,18 +62,12 @@ impl ModuleOrientation {
impl From<ModuleOrientation> for Orientation {
fn from(o: ModuleOrientation) -> Self {
match o {
ModuleOrientation::Horizontal => Orientation::Horizontal,
ModuleOrientation::Vertical => Orientation::Vertical
ModuleOrientation::Horizontal => Self::Horizontal,
ModuleOrientation::Vertical => Self::Vertical,
}
}
}
impl Default for ModuleOrientation {
fn default() -> Self {
ModuleOrientation::Horizontal
}
}
impl TransitionType {
pub const fn to_revealer_transition_type(
&self,

View File

@ -2,7 +2,7 @@ use super::{CustomWidget, CustomWidgetContext};
use crate::build;
use crate::config::ModuleOrientation;
use crate::modules::custom::WidgetConfig;
use gtk::{prelude::*, Orientation};
use gtk::prelude::*;
use serde::Deserialize;
#[derive(Debug, Deserialize, Clone)]
@ -20,9 +20,7 @@ impl CustomWidget for BoxWidget {
let container = build!(self, Self::Widget);
if let Some(orientation) = self.orientation {
container.set_orientation(
Orientation::from(orientation),
);
container.set_orientation(orientation.into());
}
if let Some(widgets) = self.widgets {

View File

@ -39,9 +39,7 @@ impl CustomWidget for ButtonWidget {
let label = Label::new(None);
label.set_use_markup(true);
label.set_angle(
self.orientation.to_angle(),
);
label.set_angle(self.orientation.to_angle());
button.add(&label);

View File

@ -23,9 +23,7 @@ impl CustomWidget for LabelWidget {
fn into_widget(self, _context: CustomWidgetContext) -> Self::Widget {
let label = build!(self, Self::Widget);
label.set_angle(
self.orientation.to_angle(),
);
label.set_angle(self.orientation.to_angle());
label.set_use_markup(true);

View File

@ -18,7 +18,7 @@ use crate::modules::{
};
use crate::script::Script;
use crate::{module_impl, send_async, spawn};
use color_eyre::{Report, Result};
use color_eyre::Result;
use gtk::prelude::*;
use gtk::{Button, IconTheme, Orientation};
use serde::Deserialize;

View File

@ -1,5 +1,4 @@
use gtk::prelude::*;
use gtk::Orientation;
use gtk::ProgressBar;
use serde::Deserialize;
use tokio::sync::mpsc;
@ -36,9 +35,7 @@ impl CustomWidget for ProgressWidget {
fn into_widget(self, context: CustomWidgetContext) -> Self::Widget {
let progress = build!(self, Self::Widget);
progress.set_orientation(
Orientation::from(self.orientation),
);
progress.set_orientation(self.orientation.into());
if let Some(length) = self.length {
set_length(&progress, length, context.bar_orientation);

View File

@ -1,5 +1,4 @@
use glib::Propagation;
use gtk::Orientation;
use std::cell::Cell;
use std::ops::Neg;
@ -48,9 +47,7 @@ impl CustomWidget for SliderWidget {
fn into_widget(self, context: CustomWidgetContext) -> Self::Widget {
let scale = build!(self, Self::Widget);
scale.set_orientation(
Orientation::from(self.orientation),
);
scale.set_orientation(self.orientation.into());
if let Some(length) = self.length {
set_length(&scale, length, context.bar_orientation);

View File

@ -1,4 +1,4 @@
use crate::config::CommonConfig;
use crate::config::{CommonConfig, ModuleOrientation};
use crate::gtk_helpers::IronbarGtkExt;
use crate::modules::{Module, ModuleInfo, ModuleParts, ModuleUpdateEvent, WidgetContext};
use crate::{glib_recv, module_impl, send_async, spawn};
@ -21,6 +21,11 @@ pub struct SysInfoModule {
#[serde(default = "Interval::default")]
interval: Interval,
#[serde(default)]
orientation: ModuleOrientation,
direction: Option<ModuleOrientation>,
#[serde(flatten)]
pub common: Option<CommonConfig>,
}
@ -182,11 +187,16 @@ impl Module<gtk::Box> for SysInfoModule {
fn into_widget(
self,
context: WidgetContext<Self::SendMessage, Self::ReceiveMessage>,
info: &ModuleInfo,
_info: &ModuleInfo,
) -> Result<ModuleParts<gtk::Box>> {
let re = Regex::new(r"\{([^}]+)}")?;
let container = gtk::Box::new(info.bar_position.orientation(), 10);
let layout = match self.direction {
Some(orientation) => orientation,
None => self.orientation,
};
let container = gtk::Box::new(layout.into(), 10);
let mut labels = Vec::new();
@ -194,7 +204,7 @@ impl Module<gtk::Box> for SysInfoModule {
let label = Label::builder().label(format).use_markup(true).build();
label.add_class("item");
label.set_angle(info.bar_position.get_angle());
label.set_angle(self.orientation.to_angle());
container.add(&label);
labels.push(label);

View File

@ -1,4 +1,4 @@
position: "left"
position: "bottom"
start:
- type: clock
format: "%H:%M"
@ -79,4 +79,39 @@ start:
- type: slider
value: "echo 50"
length: 100
orientation: v
orientation: v
- type: sys_info
format:
- ' {cpu_percent}%'
- ' {memory_used} / {memory_total} GB ({memory_percent}%)'
- '󰥔 {uptime}'
interval:
cpu: 1
disks: 300
memory: 30
networks: 3
temps: 5
- type: sys_info
orientation: vertical
format:
- ' {cpu_percent}%'
- ' {memory_used} / {memory_total} GB ({memory_percent}%)'
- '󰥔 {uptime}'
interval:
cpu: 1
disks: 300
memory: 30
networks: 3
temps: 5
- type: sys_info
layout: vertical
format:
- ' {cpu_percent}%'
- ' {memory_used} / {memory_total} GB ({memory_percent}%)'
- '󰥔 {uptime}'
interval:
cpu: 1
disks: 300
memory: 30
networks: 3
temps: 5