mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-07-09 14:42:44 +02:00
rounding from settings, and apply_on_side
This commit is contained in:
+18
-20
@@ -2,9 +2,7 @@ use crate::config::KomobarConfig;
|
|||||||
use crate::config::KomobarTheme;
|
use crate::config::KomobarTheme;
|
||||||
use crate::config::Position;
|
use crate::config::Position;
|
||||||
use crate::config::PositionConfig;
|
use crate::config::PositionConfig;
|
||||||
use crate::group::BorderRadius;
|
|
||||||
use crate::group::Grouping;
|
use crate::group::Grouping;
|
||||||
use crate::group::GroupingConfig;
|
|
||||||
use crate::komorebi::Komorebi;
|
use crate::komorebi::Komorebi;
|
||||||
use crate::komorebi::KomorebiNotificationState;
|
use crate::komorebi::KomorebiNotificationState;
|
||||||
use crate::process_hwnd;
|
use crate::process_hwnd;
|
||||||
@@ -45,7 +43,7 @@ use std::sync::Arc;
|
|||||||
|
|
||||||
pub struct Komobar {
|
pub struct Komobar {
|
||||||
pub config: Arc<KomobarConfig>,
|
pub config: Arc<KomobarConfig>,
|
||||||
pub render_config: RenderConfig,
|
pub render_config: Rc<RefCell<RenderConfig>>,
|
||||||
pub komorebi_notification_state: Option<Rc<RefCell<KomorebiNotificationState>>>,
|
pub komorebi_notification_state: Option<Rc<RefCell<KomorebiNotificationState>>>,
|
||||||
pub left_widgets: Vec<Box<dyn BarWidget>>,
|
pub left_widgets: Vec<Box<dyn BarWidget>>,
|
||||||
pub right_widgets: Vec<Box<dyn BarWidget>>,
|
pub right_widgets: Vec<Box<dyn BarWidget>>,
|
||||||
@@ -320,20 +318,12 @@ impl Komobar {
|
|||||||
) -> Self {
|
) -> Self {
|
||||||
let mut komobar = Self {
|
let mut komobar = Self {
|
||||||
config: config.clone(),
|
config: config.clone(),
|
||||||
render_config: RenderConfig {
|
render_config: Rc::new(RefCell::new(RenderConfig {
|
||||||
grouping: match config.grouping {
|
grouping: match config.grouping {
|
||||||
// TESTING
|
None => Grouping::None,
|
||||||
None => Grouping::Widget(GroupingConfig {
|
|
||||||
rounding: Some(BorderRadius {
|
|
||||||
nw: 15.0,
|
|
||||||
ne: 15.0,
|
|
||||||
sw: 15.0,
|
|
||||||
se: 15.0,
|
|
||||||
}),
|
|
||||||
}),
|
|
||||||
Some(grouping) => grouping,
|
Some(grouping) => grouping,
|
||||||
},
|
},
|
||||||
},
|
})),
|
||||||
komorebi_notification_state: None,
|
komorebi_notification_state: None,
|
||||||
left_widgets: vec![],
|
left_widgets: vec![],
|
||||||
right_widgets: vec![],
|
right_widgets: vec![],
|
||||||
@@ -452,18 +442,26 @@ impl eframe::App for Komobar {
|
|||||||
Frame::none().fill(*self.bg_color.borrow())
|
Frame::none().fill(*self.bg_color.borrow())
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// NOTE: is there a better way?
|
||||||
|
let mut render_config = self.render_config.borrow_mut();
|
||||||
|
let render_config_clone = render_config.clone();
|
||||||
|
|
||||||
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| {
|
||||||
for w in &mut self.left_widgets {
|
render_config.grouping.apply_on_side(ui, |ui| {
|
||||||
w.render(ctx, ui, self.render_config);
|
for w in &mut self.left_widgets {
|
||||||
}
|
w.render(ctx, ui, render_config_clone);
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
ui.with_layout(Layout::right_to_left(Align::Center), |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, self.render_config);
|
for w in &mut self.right_widgets {
|
||||||
}
|
w.render(ctx, ui, render_config_clone);
|
||||||
|
}
|
||||||
|
});
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
//use eframe::egui::Color32;
|
||||||
use eframe::egui::Frame;
|
use eframe::egui::Frame;
|
||||||
use eframe::egui::InnerResponse;
|
use eframe::egui::InnerResponse;
|
||||||
use eframe::egui::Margin;
|
use eframe::egui::Margin;
|
||||||
@@ -28,21 +29,49 @@ impl Grouping {
|
|||||||
inner: add_contents(ui),
|
inner: add_contents(ui),
|
||||||
response: ui.response().clone(),
|
response: ui.response().clone(),
|
||||||
},
|
},
|
||||||
Self::Widget(_config) => {
|
Self::Widget(config) => Frame::none()
|
||||||
Frame::none()
|
//.fill(Color32::from_black_alpha(255u8))
|
||||||
//.fill(Color32::from_black_alpha(255u8))
|
.outer_margin(Margin::symmetric(0.0, 0.0))
|
||||||
.outer_margin(Margin::symmetric(0.0, 0.0))
|
.inner_margin(Margin::symmetric(7.0, 2.0))
|
||||||
.inner_margin(Margin::symmetric(7.0, 2.0))
|
.rounding(match config.rounding {
|
||||||
.rounding(Rounding::same(15.0))
|
None => Rounding::same(15.0),
|
||||||
.stroke(ui.style().visuals.widgets.noninteractive.bg_stroke)
|
Some(rounding) => rounding.into(),
|
||||||
.show(ui, add_contents)
|
})
|
||||||
}
|
.stroke(ui.style().visuals.widgets.noninteractive.bg_stroke)
|
||||||
|
.show(ui, add_contents),
|
||||||
Self::Side(_config) => InnerResponse {
|
Self::Side(_config) => InnerResponse {
|
||||||
inner: add_contents(ui),
|
inner: add_contents(ui),
|
||||||
response: ui.response().clone(),
|
response: ui.response().clone(),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn apply_on_side<R>(
|
||||||
|
&mut self,
|
||||||
|
ui: &mut Ui,
|
||||||
|
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(),
|
||||||
|
})
|
||||||
|
.stroke(ui.style().visuals.widgets.noninteractive.bg_stroke)
|
||||||
|
.show(ui, add_contents),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema)]
|
#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema)]
|
||||||
|
|||||||
Reference in New Issue
Block a user