From 63e00e8271ed9835bfd672f030c493f88e13ef43 Mon Sep 17 00:00:00 2001 From: Daniel Bulant Date: Tue, 7 Jan 2025 23:14:14 +0100 Subject: [PATCH] working top bar --- src/bar/mod.rs | 29 +++++++++++++++++++++++------ src/bar/spotify.rs | 11 ++++++----- src/theme.rs | 9 ++++++--- 3 files changed, 35 insertions(+), 14 deletions(-) diff --git a/src/bar/mod.rs b/src/bar/mod.rs index 34c4e85..7038039 100644 --- a/src/bar/mod.rs +++ b/src/bar/mod.rs @@ -1,19 +1,36 @@ -use cushy::{kludgine::app::winit::window::WindowLevel, widget::MakeWidget, Application, Open}; +use cushy::{ + figures::{units::Px, Point}, + kludgine::app::winit::{platform::wayland::Anchor, window::WindowLevel}, + value::{Destination, Dynamic, Source}, + widget::MakeWidget, + Application, Open, +}; mod spotify; pub fn start_bar(app: &mut impl Application) -> cushy::Result { + let pos = Dynamic::default(); let mut window = spotify::spotify_controls() .pad() + .centered() + .expand_horizontally() .into_window() .transparent() .app_name("rshell") .decorated(false) - // .resizable(false) + .outer_position(pos.clone(), false) .window_level(WindowLevel::AlwaysOnTop); - window.sans_serif_font_family.push(cushy::styles::FamilyOwned::Name("Iosevka NF".into())); - window - .open(app).map(|_| ()) -} \ No newline at end of file + .sans_serif_font_family + .push(cushy::styles::FamilyOwned::Name("Iosevka NF".into())); + + window.open(app).map(|handle| { + handle.execute(|ctx| { + // safe unwrap: we just created the window + let winit = ctx.winit().unwrap(); + winit.set_exclusive_zone(40); + winit.set_anchor(Anchor::LEFT | Anchor::TOP | Anchor::RIGHT); + }); + }) +} diff --git a/src/bar/spotify.rs b/src/bar/spotify.rs index 6904683..26d295b 100644 --- a/src/bar/spotify.rs +++ b/src/bar/spotify.rs @@ -5,14 +5,14 @@ use std::{ }; use crate::{ - theme::{BG_DEFAULT, TEXT_SPOTIFY}, + theme::{BG_DEFAULT, CORNER_RADIUS, TEXT_SPOTIFY}, vibrancy::Vibrancy, }; use cushy::{ figures::{units::Lp, Size, Zero}, kludgine::{AnyTexture, LazyTexture}, styles::{ - components::{FontWeight, TextColor, WidgetBackground}, + components::{FontWeight, LineHeight, TextColor, TextSize, WidgetBackground}, Color, CornerRadii, Dimension, DimensionRange, Weight, }, value::{Destination, Dynamic, Source}, @@ -45,9 +45,8 @@ pub fn spotify_controls() -> impl MakeWidget { let (progress, track) = get_track_dynamics(); let (texture, vibrancy) = get_texture_dynamic(track.clone()); - const IMAGE_SIDE: i32 = 16 /* lineheight */ + 2 * 6 /* padding */; + const IMAGE_SIDE: i32 = 10 /* lineheight */ + 2 * 6 /* padding */; let image_size = Size::squared(DimensionRange::from(Dimension::Lp(Lp::points(IMAGE_SIDE)))); - const CORNER_RADIUS: Dimension = Dimension::Lp(Lp::points(6)); Image::new(texture) .aspect_fit() @@ -73,7 +72,9 @@ pub fn spotify_controls() -> impl MakeWidget { }) .into_label() .with(&TextColor, TEXT_SPOTIFY) - .with(&FontWeight, Weight::BOLD) + // .with(&FontWeight, Weight::BOLD) + .with(&TextSize, Dimension::Lp(Lp::points(10))) + .with(&LineHeight, Dimension::Lp(Lp::points(10))) .centered() .pad(), ) diff --git a/src/theme.rs b/src/theme.rs index 2c946f8..49ecfea 100644 --- a/src/theme.rs +++ b/src/theme.rs @@ -1,5 +1,8 @@ -use cushy::styles::Color; - +use cushy::{ + figures::units::Lp, + styles::{Color, Dimension}, +}; pub const TEXT_SPOTIFY: Color = Color(0x1DB954FF); -pub const BG_DEFAULT: Color = Color(0x191724FF); \ No newline at end of file +pub const BG_DEFAULT: Color = Color(0x191724FF); +pub const CORNER_RADIUS: Dimension = Dimension::Lp(Lp::points(6));