mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-07-13 16:42:50 +02:00
AlphaColour, transparency, bar background, more grouping config options
This commit is contained in:
+94
-24
@@ -1,9 +1,14 @@
|
||||
//use eframe::egui::Color32;
|
||||
use crate::config::AlphaColour;
|
||||
use eframe::egui::Color32;
|
||||
use eframe::egui::Frame;
|
||||
use eframe::egui::InnerResponse;
|
||||
use eframe::egui::Margin;
|
||||
use eframe::egui::Rounding;
|
||||
use eframe::egui::Stroke;
|
||||
use eframe::egui::Ui;
|
||||
use komorebi_client::Colour;
|
||||
use komorebi_client::Rect;
|
||||
use komorebi_client::Rgb;
|
||||
use schemars::JsonSchema;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
@@ -25,21 +30,33 @@ impl Grouping {
|
||||
add_contents: impl FnOnce(&mut Ui) -> R,
|
||||
) -> InnerResponse<R> {
|
||||
match self {
|
||||
Self::None => InnerResponse {
|
||||
Self::Widget(config) => Frame::none()
|
||||
.fill(match config.fill {
|
||||
Some(color) => color.into(),
|
||||
None => Color32::TRANSPARENT,
|
||||
})
|
||||
.outer_margin(match config.outer_margin {
|
||||
Some(margin) => Self::rect_to_margin(margin),
|
||||
None => Margin::symmetric(0.0, 0.0),
|
||||
})
|
||||
.inner_margin(match config.inner_margin {
|
||||
Some(margin) => Self::rect_to_margin(margin),
|
||||
None => Margin::symmetric(7.0, 2.0),
|
||||
})
|
||||
.rounding(match config.rounding {
|
||||
Some(rounding) => rounding.into(),
|
||||
None => Rounding::same(10.0),
|
||||
})
|
||||
.stroke(match config.stroke {
|
||||
Some(line) => line.into(),
|
||||
None => ui.style().visuals.widgets.noninteractive.bg_stroke,
|
||||
})
|
||||
.show(ui, add_contents),
|
||||
Self::Side(_config) => InnerResponse {
|
||||
inner: add_contents(ui),
|
||||
response: ui.response().clone(),
|
||||
},
|
||||
Self::Widget(config) => Frame::none()
|
||||
//.fill(Color32::from_black_alpha(255u8))
|
||||
.outer_margin(Margin::symmetric(0.0, 0.0))
|
||||
.inner_margin(Margin::symmetric(7.0, 2.0))
|
||||
.rounding(match config.rounding {
|
||||
None => Rounding::same(15.0),
|
||||
Some(rounding) => rounding.into(),
|
||||
})
|
||||
.stroke(ui.style().visuals.widgets.noninteractive.bg_stroke)
|
||||
.show(ui, add_contents),
|
||||
Self::Side(_config) => InnerResponse {
|
||||
Self::None => InnerResponse {
|
||||
inner: add_contents(ui),
|
||||
response: ui.response().clone(),
|
||||
},
|
||||
@@ -52,31 +69,84 @@ impl Grouping {
|
||||
add_contents: impl FnOnce(&mut Ui) -> R,
|
||||
) -> InnerResponse<R> {
|
||||
match self {
|
||||
Self::None => InnerResponse {
|
||||
inner: add_contents(ui),
|
||||
response: ui.response().clone(),
|
||||
},
|
||||
Self::Widget(_config) => InnerResponse {
|
||||
inner: add_contents(ui),
|
||||
response: ui.response().clone(),
|
||||
},
|
||||
Self::Side(config) => Frame::none()
|
||||
//.fill(Color32::from_black_alpha(255u8))
|
||||
.outer_margin(Margin::symmetric(0.0, 0.0))
|
||||
.inner_margin(Margin::symmetric(7.0, 2.0))
|
||||
.rounding(match config.rounding {
|
||||
None => Rounding::same(15.0),
|
||||
Some(rounding) => rounding.into(),
|
||||
.fill(match config.fill {
|
||||
Some(color) => color.into(),
|
||||
None => Color32::TRANSPARENT,
|
||||
})
|
||||
.outer_margin(match config.outer_margin {
|
||||
Some(margin) => Self::rect_to_margin(margin),
|
||||
None => Margin::symmetric(0.0, 0.0),
|
||||
})
|
||||
.inner_margin(match config.inner_margin {
|
||||
Some(margin) => Self::rect_to_margin(margin),
|
||||
None => Margin::symmetric(7.0, 2.0),
|
||||
})
|
||||
.rounding(match config.rounding {
|
||||
Some(rounding) => rounding.into(),
|
||||
None => Rounding::same(10.0),
|
||||
})
|
||||
.stroke(match config.stroke {
|
||||
Some(line) => line.into(),
|
||||
None => ui.style().visuals.widgets.noninteractive.bg_stroke,
|
||||
})
|
||||
.stroke(ui.style().visuals.widgets.noninteractive.bg_stroke)
|
||||
.show(ui, add_contents),
|
||||
Self::None => InnerResponse {
|
||||
inner: add_contents(ui),
|
||||
response: ui.response().clone(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
fn rect_to_margin(rect: Rect) -> Margin {
|
||||
Margin {
|
||||
left: rect.left as f32,
|
||||
right: rect.right as f32,
|
||||
top: rect.top as f32,
|
||||
bottom: rect.bottom as f32,
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE: this is also in the komorebi_gui. Should be moved to the "komorebi colour"
|
||||
pub fn colour_to_color32(colour: Option<Colour>) -> Color32 {
|
||||
match colour {
|
||||
Some(Colour::Rgb(rgb)) => Color32::from_rgb(rgb.r as u8, rgb.g as u8, rgb.b as u8),
|
||||
Some(Colour::Hex(hex)) => {
|
||||
let rgb = Rgb::from(hex);
|
||||
Color32::from_rgb(rgb.r as u8, rgb.g as u8, rgb.b as u8)
|
||||
}
|
||||
//None => Color32::from_rgb(0, 0, 0),
|
||||
None => Color32::TRANSPARENT,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema)]
|
||||
pub struct GroupingConfig {
|
||||
pub fill: Option<AlphaColour>,
|
||||
pub rounding: Option<BorderRadius>,
|
||||
pub outer_margin: Option<Rect>,
|
||||
pub inner_margin: Option<Rect>,
|
||||
pub stroke: Option<Line>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema)]
|
||||
pub struct Line {
|
||||
pub width: f32,
|
||||
pub color: Option<Colour>,
|
||||
}
|
||||
|
||||
impl From<Line> for Stroke {
|
||||
fn from(value: Line) -> Self {
|
||||
Self {
|
||||
width: value.width,
|
||||
color: Grouping::colour_to_color32(value.color),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema)]
|
||||
|
||||
Reference in New Issue
Block a user