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