mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-03-21 17:09:20 +01:00
grouping on bar, converting AlphaColour from_rgba_unmultiplied, simplified grouping
This commit is contained in:
@@ -244,6 +244,13 @@ impl Komobar {
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(background) = self.config.background {
|
||||
let theme_color = *self.bg_color.borrow();
|
||||
|
||||
self.bg_color
|
||||
.replace(background.to_color32_or(Some(theme_color)));
|
||||
}
|
||||
|
||||
if let Some(font_size) = &config.font_size {
|
||||
tracing::info!("attempting to set custom font size: {font_size}");
|
||||
Self::set_font_size(ctx, *font_size);
|
||||
@@ -430,22 +437,15 @@ 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(theme_color)
|
||||
.fill(*self.bg_color.borrow())
|
||||
} else {
|
||||
Frame::none().fill(theme_color)
|
||||
Frame::none().fill(*self.bg_color.borrow())
|
||||
};
|
||||
|
||||
// NOTE: is there a better way?
|
||||
@@ -453,21 +453,26 @@ impl eframe::App for Komobar {
|
||||
let render_config_clone = *render_config;
|
||||
|
||||
CentralPanel::default().frame(frame).show(ctx, |ui| {
|
||||
ui.horizontal_centered(|ui| {
|
||||
ui.with_layout(Layout::left_to_right(Align::Center), |ui| {
|
||||
render_config.grouping.apply_on_side(ui, |ui| {
|
||||
for w in &mut self.left_widgets {
|
||||
w.render(ctx, ui, render_config_clone);
|
||||
}
|
||||
// Apply grouping logic for the bar as a whole
|
||||
render_config.grouping.clone().apply_on_bar(ui, |ui| {
|
||||
ui.horizontal_centered(|ui| {
|
||||
// Left-aligned widgets layout
|
||||
ui.with_layout(Layout::left_to_right(Align::Center), |ui| {
|
||||
render_config.grouping.apply_on_side(ui, |ui| {
|
||||
for w in &mut self.left_widgets {
|
||||
w.render(ctx, ui, render_config_clone);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
ui.with_layout(Layout::right_to_left(Align::Center), |ui| {
|
||||
render_config.grouping.apply_on_side(ui, |ui| {
|
||||
for w in &mut self.right_widgets {
|
||||
w.render(ctx, ui, render_config_clone);
|
||||
}
|
||||
});
|
||||
// Right-aligned widgets layout
|
||||
ui.with_layout(Layout::right_to_left(Align::Center), |ui| {
|
||||
render_config.grouping.apply_on_side(ui, |ui| {
|
||||
for w in &mut self.right_widgets {
|
||||
w.render(ctx, ui, render_config_clone);
|
||||
}
|
||||
});
|
||||
})
|
||||
})
|
||||
})
|
||||
});
|
||||
|
||||
@@ -218,7 +218,7 @@ impl AlphaColour {
|
||||
};
|
||||
|
||||
if let Some(alpha) = self.transparency_alpha {
|
||||
return Color32::from_rgba_premultiplied(color.r(), color.g(), color.b(), alpha);
|
||||
return Color32::from_rgba_unmultiplied(color.r(), color.g(), color.b(), alpha);
|
||||
}
|
||||
|
||||
color
|
||||
|
||||
@@ -20,53 +20,38 @@ use serde::Serialize;
|
||||
pub enum Grouping {
|
||||
/// No grouping is applied
|
||||
None,
|
||||
/// Widgets are grouped individually
|
||||
Widget(GroupingConfig),
|
||||
/// Widgets are grouped on the bar
|
||||
Bar(GroupingConfig),
|
||||
/// Widgets are grouped on each side
|
||||
Side(GroupingConfig),
|
||||
/// Widgets are grouped individually
|
||||
Widget(GroupingConfig),
|
||||
}
|
||||
|
||||
impl Grouping {
|
||||
pub fn apply_on_bar<R>(
|
||||
&mut self,
|
||||
ui: &mut Ui,
|
||||
add_contents: impl FnOnce(&mut Ui) -> R,
|
||||
) -> InnerResponse<R> {
|
||||
match self {
|
||||
Self::Bar(config) => Self::define_frame(ui, config).show(ui, add_contents),
|
||||
Self::Widget(_) => Self::default_response(ui, add_contents),
|
||||
Self::Side(_) => Self::default_response(ui, add_contents),
|
||||
Self::None => Self::default_response(ui, add_contents),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn apply_on_widget<R>(
|
||||
&mut self,
|
||||
ui: &mut Ui,
|
||||
add_contents: impl FnOnce(&mut Ui) -> R,
|
||||
) -> InnerResponse<R> {
|
||||
match self {
|
||||
Self::Widget(config) => Frame::none()
|
||||
.fill(match config.fill {
|
||||
Some(color) => color.to_color32_or(None),
|
||||
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(5.0, 2.0),
|
||||
})
|
||||
.rounding(match config.rounding {
|
||||
Some(rounding) => rounding.into(),
|
||||
None => Rounding::same(5.0),
|
||||
})
|
||||
.stroke(match config.stroke {
|
||||
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),
|
||||
response: ui.response().clone(),
|
||||
},
|
||||
Self::None => InnerResponse {
|
||||
inner: add_contents(ui),
|
||||
response: ui.response().clone(),
|
||||
},
|
||||
Self::Bar(_) => Self::default_response(ui, add_contents),
|
||||
Self::Widget(config) => Self::define_frame(ui, config).show(ui, add_contents),
|
||||
Self::Side(_) => Self::default_response(ui, add_contents),
|
||||
Self::None => Self::default_response(ui, add_contents),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,36 +61,48 @@ impl Grouping {
|
||||
add_contents: impl FnOnce(&mut Ui) -> R,
|
||||
) -> InnerResponse<R> {
|
||||
match self {
|
||||
Self::Widget(_config) => InnerResponse {
|
||||
inner: add_contents(ui),
|
||||
response: ui.response().clone(),
|
||||
},
|
||||
Self::Side(config) => Frame::none()
|
||||
.fill(match config.fill {
|
||||
Some(color) => color.to_color32_or(None),
|
||||
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(5.0, 2.0),
|
||||
})
|
||||
.rounding(match config.rounding {
|
||||
Some(rounding) => rounding.into(),
|
||||
None => Rounding::same(5.0),
|
||||
})
|
||||
.stroke(match config.stroke {
|
||||
Some(line) => line.into(),
|
||||
None => ui.style().visuals.widgets.noninteractive.bg_stroke,
|
||||
})
|
||||
.show(ui, add_contents),
|
||||
Self::None => InnerResponse {
|
||||
inner: add_contents(ui),
|
||||
response: ui.response().clone(),
|
||||
},
|
||||
Self::Bar(_) => Self::default_response(ui, add_contents),
|
||||
Self::Widget(_) => Self::default_response(ui, add_contents),
|
||||
Self::Side(config) => Self::define_frame(ui, config).show(ui, add_contents),
|
||||
Self::None => Self::default_response(ui, add_contents),
|
||||
}
|
||||
}
|
||||
|
||||
fn define_frame(ui: &mut Ui, config: &mut GroupingConfig) -> Frame {
|
||||
Frame::none()
|
||||
.fill(match config.fill {
|
||||
Some(color) => color.to_color32_or(None),
|
||||
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(5.0, 2.0),
|
||||
})
|
||||
.rounding(match config.rounding {
|
||||
Some(rounding) => rounding.into(),
|
||||
None => Rounding::same(5.0),
|
||||
})
|
||||
.stroke(match config.stroke {
|
||||
Some(line) => line.into(),
|
||||
None => ui.style().visuals.widgets.noninteractive.bg_stroke,
|
||||
})
|
||||
.shadow(match config.shadow {
|
||||
Some(shadow) => shadow.into(),
|
||||
None => Shadow::NONE,
|
||||
})
|
||||
}
|
||||
|
||||
fn default_response<R>(
|
||||
ui: &mut Ui,
|
||||
add_contents: impl FnOnce(&mut Ui) -> R,
|
||||
) -> InnerResponse<R> {
|
||||
InnerResponse {
|
||||
inner: add_contents(ui),
|
||||
response: ui.response().clone(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user