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 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 = "󱃍";

View file

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

View file

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

View file

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

View file

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

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 {}