code cleanup

This commit is contained in:
Daniel Bulant 2025-01-11 10:29:37 +01:00
parent 53544c6dbe
commit 715527b138
No known key found for this signature in database
6 changed files with 31 additions and 36 deletions

View file

@ -1,7 +1,7 @@
use battery::State; use battery::State;
use cushy::{styles::components::TextColor, widget::MakeWidget}; use cushy::{styles::components::TextColor, widget::MakeWidget};
use crate::theme::{TEXT_BATTERY, TEXT_TEMP, WIDGET_PADDING}; use crate::theme::{TEXT_BATTERY, WIDGET_PADDING};
const BATTERY_LOW: &str = "󱃍"; const BATTERY_LOW: &str = "󱃍";

View file

@ -8,16 +8,18 @@ use cushy::{
styles::{ styles::{
components::{ components::{
BaseLineHeight, BaseTextSize, CornerRadius, DefaultBackgroundColor, FontWeight, BaseLineHeight, BaseTextSize, CornerRadius, DefaultBackgroundColor, FontWeight,
WidgetBackground,
}, },
FontFamilyList, FontFamilyList,
}, },
value::{Dynamic, Source}, value::Dynamic,
widget::MakeWidget, widget::MakeWidget,
Application, Open, Application, Open,
}; };
use crate::theme::{BG_DEFAULT, CORNER_RADIUS, DEFAULT_FONT_WEIGHT, TEXT_FONT, TEXT_SIZE}; use crate::{
theme::{BG_DEFAULT, CORNER_RADIUS, DEFAULT_FONT_WEIGHT, TEXT_FONT, TEXT_SIZE},
widgets::WidgetExt,
};
mod battery; mod battery;
mod spotify; mod spotify;
@ -29,27 +31,13 @@ pub fn start_bar(app: &mut impl Application) -> cushy::Result {
monitor_size.height = UPx::new(40); monitor_size.height = UPx::new(40);
monitor_size.width = UPx::new((monitor_size.width.get() as f64 / 1.25) as _); monitor_size.width = UPx::new((monitor_size.width.get() as f64 / 1.25) as _);
let size = Dynamic::new(monitor_size); let size = Dynamic::new(monitor_size);
let mut window = ((time::time_widget() let mut window = ((time::time_widget().bar_pill())
.expand_vertically() .and(spotify::spotify_controls().bar_pill())
.with(&WidgetBackground, BG_DEFAULT)
.pad())
.and(
spotify::spotify_controls()
.expand_vertically()
.with(&WidgetBackground, BG_DEFAULT)
.pad(),
)
.into_columns() .into_columns()
.centered() .centered()
.expand_horizontally()) .expand_horizontally())
.and( .and(battery().bar_pill())
battery()
.expand_vertically()
.with(&WidgetBackground, BG_DEFAULT)
.pad(),
)
.into_columns() .into_columns()
.centered()
.expand_horizontally() .expand_horizontally()
.width(monitor_size.width) .width(monitor_size.width)
.height(Lp::points(30)) .height(Lp::points(30))

View file

@ -6,16 +6,13 @@ use std::{
use crate::{ use crate::{
rt::tokio_runtime, rt::tokio_runtime,
theme::{BG_DEFAULT, CORNER_RADIUS, TEXT_SPOTIFY, WIDGET_PADDING}, theme::{CORNER_RADIUS, TEXT_SPOTIFY, WIDGET_PADDING},
vibrancy::Vibrancy, vibrancy::Vibrancy,
}; };
use cushy::{ use cushy::{
figures::{units::Lp, Size, Zero}, figures::{units::Lp, Size, Zero},
kludgine::{AnyTexture, LazyTexture}, kludgine::{AnyTexture, LazyTexture},
styles::{ styles::{components::TextColor, Color, CornerRadii, Dimension, DimensionRange},
components::{TextColor, WidgetBackground},
Color, CornerRadii, Dimension, DimensionRange,
},
value::{Destination, Dynamic, Source}, value::{Destination, Dynamic, Source},
widget::MakeWidget, widget::MakeWidget,
widgets::{image::ImageCornerRadius, label::Displayable, Image}, widgets::{image::ImageCornerRadius, label::Displayable, Image},

View file

@ -1,13 +1,13 @@
use chrono::{Local, Timelike}; use chrono::{Local, Timelike};
use cushy::{ use cushy::{
styles::components::{TextColor, WidgetBackground}, styles::components::TextColor,
value::{Destination, Dynamic, MapEach}, value::{Destination, Dynamic, MapEach},
widget::MakeWidget, widget::MakeWidget,
}; };
use crate::{ use crate::{
rt::tokio_runtime, rt::tokio_runtime,
theme::{BG_DEFAULT, TEXT_CLOCK, WIDGET_PADDING}, theme::{TEXT_CLOCK, WIDGET_PADDING},
}; };
const FORMAT: &'static str = " %H:%M %p 󰃭 %a %d "; const FORMAT: &'static str = " %H:%M %p 󰃭 %a %d ";

View file

@ -10,6 +10,7 @@ mod menu;
pub mod rt; pub mod rt;
mod theme; mod theme;
mod vibrancy; mod vibrancy;
pub mod widgets;
fn main() -> cushy::Result { fn main() -> cushy::Result {
let args = Args::parse(); let args = Args::parse();
@ -19,11 +20,7 @@ fn main() -> cushy::Result {
Commands::Bar => start_bar(app).unwrap(), Commands::Bar => start_bar(app).unwrap(),
Commands::Menu => start_menu(app).unwrap(), Commands::Menu => start_menu(app).unwrap(),
Commands::Power => { Commands::Power => {
let win = "Hello world!".open(app).unwrap(); "Hello world!".open(app).unwrap();
// std::thread::spawn(move || {
// std::thread::sleep(std::time::Duration::from_secs(2));
// win.request_close();
// });
} }
}); });

13
src/widgets.rs Normal file
View file

@ -0,0 +1,13 @@
use cushy::{styles::components::WidgetBackground, widget::MakeWidget, widgets::Container};
use crate::theme::BG_DEFAULT;
pub trait WidgetExt: MakeWidget {
fn bar_pill(self) -> Container {
self.expand_vertically()
.with(&WidgetBackground, BG_DEFAULT)
.pad()
}
}
impl<T: MakeWidget> WidgetExt for T {}