mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-03-17 23:13:55 +01:00
background color using theme color, AlphaColour.to_color32_or, updating json format for Grouping and RoundingConfig
This commit is contained in:
@@ -326,7 +326,6 @@ impl Komobar {
|
||||
Some(grouping) => grouping,
|
||||
None => Grouping::None,
|
||||
},
|
||||
background_color: config.background.map(|value| value.into()),
|
||||
})),
|
||||
komorebi_notification_state: None,
|
||||
left_widgets: vec![],
|
||||
@@ -432,26 +431,28 @@ impl eframe::App for Komobar {
|
||||
);
|
||||
}
|
||||
|
||||
let theme_color = *self.bg_color.borrow();
|
||||
|
||||
if let Some(background) = self.config.background {
|
||||
self.bg_color
|
||||
.replace(background.to_color32_or(Some(theme_color)));
|
||||
}
|
||||
|
||||
let frame = if let Some(frame) = &self.config.frame {
|
||||
Frame::none()
|
||||
.inner_margin(Margin::symmetric(
|
||||
frame.inner_margin.x,
|
||||
frame.inner_margin.y,
|
||||
))
|
||||
.fill(*self.bg_color.borrow())
|
||||
.fill(theme_color)
|
||||
} else {
|
||||
Frame::none().fill(*self.bg_color.borrow())
|
||||
Frame::none().fill(theme_color)
|
||||
};
|
||||
|
||||
// NOTE: is there a better way?
|
||||
let mut render_config = self.render_config.borrow_mut();
|
||||
let render_config_clone = *render_config;
|
||||
|
||||
// prefer the custom background from the config over the theme background
|
||||
if let Some(bg_color) = render_config.background_color {
|
||||
self.bg_color.replace(bg_color);
|
||||
};
|
||||
|
||||
CentralPanel::default().frame(frame).show(ctx, |ui| {
|
||||
ui.horizontal_centered(|ui| {
|
||||
ui.with_layout(Layout::left_to_right(Align::Center), |ui| {
|
||||
|
||||
@@ -194,14 +194,18 @@ pub struct AlphaColour {
|
||||
pub transparency_alpha: Option<u8>,
|
||||
}
|
||||
|
||||
impl From<AlphaColour> for Color32 {
|
||||
fn from(value: AlphaColour) -> Self {
|
||||
let color = match value.color {
|
||||
impl AlphaColour {
|
||||
/// Returns an Rgb or Rgba color using the alpha, and default_color or Rgb(0,0,0)
|
||||
pub fn to_color32_or(self, default_color: Option<Color32>) -> Color32 {
|
||||
let color = match self.color {
|
||||
Some(color) => color.into(),
|
||||
None => Color32::from_rgb(0, 0, 0),
|
||||
None => match default_color {
|
||||
Some(color) => color,
|
||||
None => Color32::from_rgb(0, 0, 0),
|
||||
},
|
||||
};
|
||||
|
||||
if let Some(alpha) = value.transparency_alpha {
|
||||
if let Some(alpha) = self.transparency_alpha {
|
||||
return Color32::from_rgba_premultiplied(color.r(), color.g(), color.b(), alpha);
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema)]
|
||||
#[serde(tag = "kind")]
|
||||
pub enum Grouping {
|
||||
/// No grouping is applied
|
||||
None,
|
||||
@@ -31,7 +32,7 @@ impl Grouping {
|
||||
match self {
|
||||
Self::Widget(config) => Frame::none()
|
||||
.fill(match config.fill {
|
||||
Some(color) => color.into(),
|
||||
Some(color) => color.to_color32_or(None),
|
||||
None => Color32::TRANSPARENT,
|
||||
})
|
||||
.outer_margin(match config.outer_margin {
|
||||
@@ -74,7 +75,7 @@ impl Grouping {
|
||||
},
|
||||
Self::Side(config) => Frame::none()
|
||||
.fill(match config.fill {
|
||||
Some(color) => color.into(),
|
||||
Some(color) => color.to_color32_or(None),
|
||||
None => Color32::TRANSPARENT,
|
||||
})
|
||||
.outer_margin(match config.outer_margin {
|
||||
@@ -139,6 +140,7 @@ impl From<Line> for Stroke {
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema)]
|
||||
#[serde(untagged)]
|
||||
pub enum RoundingConfig {
|
||||
/// All 4 corners are the same
|
||||
Same(f32),
|
||||
|
||||
@@ -17,7 +17,6 @@ use crate::storage::Storage;
|
||||
use crate::storage::StorageConfig;
|
||||
use crate::time::Time;
|
||||
use crate::time::TimeConfig;
|
||||
use eframe::egui::Color32;
|
||||
use eframe::egui::Context;
|
||||
use eframe::egui::Ui;
|
||||
use schemars::JsonSchema;
|
||||
@@ -32,7 +31,6 @@ pub trait BarWidget {
|
||||
pub struct RenderConfig {
|
||||
/// Sets how widgets are grouped
|
||||
pub grouping: Grouping,
|
||||
pub background_color: Option<Color32>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
|
||||
|
||||
Reference in New Issue
Block a user