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