From 2cd237fd0d3e78cbf2f3570e16d1a0849e3021df Mon Sep 17 00:00:00 2001 From: Csaba Date: Sun, 10 Nov 2024 13:58:24 +0100 Subject: [PATCH] added shadow to grouping, optional width on grouping stroke --- komorebi-bar/src/group.rs | 49 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/komorebi-bar/src/group.rs b/komorebi-bar/src/group.rs index 264ea5ed..b3b12f73 100644 --- a/komorebi-bar/src/group.rs +++ b/komorebi-bar/src/group.rs @@ -1,11 +1,14 @@ use crate::config::AlphaColour; +use crate::config::Position; use eframe::egui::Color32; use eframe::egui::Frame; use eframe::egui::InnerResponse; use eframe::egui::Margin; use eframe::egui::Rounding; +use eframe::egui::Shadow; use eframe::egui::Stroke; use eframe::egui::Ui; +use eframe::egui::Vec2; use komorebi_client::Colour; use komorebi_client::Rect; use schemars::JsonSchema; @@ -51,6 +54,10 @@ impl Grouping { Some(line) => line.into(), None => ui.style().visuals.widgets.noninteractive.bg_stroke, }) + .shadow(match config.shadow { + Some(shadow) => shadow.into(), + None => Shadow::NONE, + }) .show(ui, add_contents), Self::Side(_config) => InnerResponse { inner: add_contents(ui), @@ -119,18 +126,19 @@ pub struct GroupingConfig { pub outer_margin: Option, pub inner_margin: Option, pub stroke: Option, + pub shadow: Option, } #[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema)] pub struct Line { - pub width: f32, + pub width: Option, pub color: Option, } impl From for Stroke { fn from(value: Line) -> Self { Self { - width: value.width, + width: value.width.unwrap_or(1.0), color: match value.color { Some(color) => color.into(), None => Color32::from_rgb(0, 0, 0), @@ -161,3 +169,40 @@ impl From for Rounding { } } } + +#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema)] +pub struct BoxShadow { + /// Move the shadow by this much. + /// + /// For instance, a value of `[1.0, 2.0]` will move the shadow 1 point to the right and 2 points down, + /// causing a drop-shadow effect. + pub offset: Option, + + /// The width of the blur, i.e. the width of the fuzzy penumbra. + /// + /// A value of 0.0 means a sharp shadow. + pub blur: Option, + + /// Expand the shadow in all directions by this much. + pub spread: Option, + + /// Color of the opaque center of the shadow. + pub color: Option, +} + +impl From for Shadow { + fn from(value: BoxShadow) -> Self { + Shadow { + offset: match value.offset { + Some(offset) => offset.into(), + None => Vec2::ZERO, + }, + blur: value.blur.unwrap_or(0.0), + spread: value.spread.unwrap_or(0.0), + color: match value.color { + Some(color) => color.to_color32_or(None), + None => Color32::TRANSPARENT, + }, + } + } +}