mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-03-19 16:21:17 +01:00
added widget_spacing to config
This commit is contained in:
@@ -349,7 +349,9 @@ impl Komobar {
|
||||
let mut komobar = Self {
|
||||
config: config.clone(),
|
||||
render_config: Rc::new(RefCell::new(RenderConfig {
|
||||
spacing: 0.0,
|
||||
grouping: Grouping::None,
|
||||
alignment: None,
|
||||
})),
|
||||
komorebi_notification_state: None,
|
||||
left_widgets: vec![],
|
||||
@@ -466,9 +468,7 @@ impl eframe::App for Komobar {
|
||||
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;
|
||||
|
||||
CentralPanel::default().frame(frame).show(ctx, |ui| {
|
||||
// Apply grouping logic for the bar as a whole
|
||||
@@ -476,18 +476,24 @@ impl eframe::App for Komobar {
|
||||
ui.horizontal_centered(|ui| {
|
||||
// Left-aligned widgets layout
|
||||
ui.with_layout(Layout::left_to_right(Align::Center), |ui| {
|
||||
let mut render_conf = *render_config;
|
||||
render_conf.alignment = Some(Alignment::Left);
|
||||
|
||||
render_config.grouping.apply_on_alignment(ui, |ui| {
|
||||
for w in &mut self.left_widgets {
|
||||
w.render(ctx, ui, render_config_clone, Alignment::Left);
|
||||
w.render(ctx, ui, render_conf);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Right-aligned widgets layout
|
||||
ui.with_layout(Layout::right_to_left(Align::Center), |ui| {
|
||||
let mut render_conf = *render_config;
|
||||
render_conf.alignment = Some(Alignment::Right);
|
||||
|
||||
render_config.grouping.apply_on_alignment(ui, |ui| {
|
||||
for w in &mut self.right_widgets {
|
||||
w.render(ctx, ui, render_config_clone, Alignment::Right);
|
||||
w.render(ctx, ui, render_conf);
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use crate::bar::Alignment;
|
||||
use crate::config::LabelPrefix;
|
||||
use crate::widget::BarWidget;
|
||||
use crate::widget::RenderConfig;
|
||||
@@ -116,13 +115,7 @@ impl Battery {
|
||||
}
|
||||
|
||||
impl BarWidget for Battery {
|
||||
fn render(
|
||||
&mut self,
|
||||
ctx: &Context,
|
||||
ui: &mut Ui,
|
||||
mut config: RenderConfig,
|
||||
alignment: Alignment,
|
||||
) {
|
||||
fn render(&mut self, ctx: &Context, ui: &mut Ui, mut config: RenderConfig) {
|
||||
if self.enable {
|
||||
let output = self.output();
|
||||
if !output.is_empty() {
|
||||
@@ -154,7 +147,7 @@ impl BarWidget for Battery {
|
||||
TextFormat::simple(font_id, ctx.style().visuals.text_color()),
|
||||
);
|
||||
|
||||
config.grouping.apply_on_widget(true, alignment, ui, |ui| {
|
||||
config.grouping.apply_on_widget(true, config, ui, |ui| {
|
||||
ui.add(
|
||||
Label::new(layout_job)
|
||||
.selectable(false)
|
||||
|
||||
@@ -33,6 +33,8 @@ pub struct KomobarConfig {
|
||||
pub theme: Option<KomobarTheme>,
|
||||
/// Alpha value for the color transparency [[0-255]] (default: 200)
|
||||
pub transparency_alpha: Option<u8>,
|
||||
/// Spacing between widgets
|
||||
pub widget_spacing: Option<f32>,
|
||||
/// Visual grouping for widgets
|
||||
pub grouping: Option<Grouping>,
|
||||
/// Left side widgets (ordered left-to-right)
|
||||
@@ -73,10 +75,9 @@ impl KomobarConfig {
|
||||
impl From<&KomobarConfig> for RenderConfig {
|
||||
fn from(value: &KomobarConfig) -> Self {
|
||||
RenderConfig {
|
||||
grouping: match value.grouping {
|
||||
Some(grouping) => grouping,
|
||||
None => Grouping::None,
|
||||
},
|
||||
spacing: value.widget_spacing.unwrap_or(10.0),
|
||||
grouping: value.grouping.unwrap_or(Grouping::None),
|
||||
alignment: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use crate::bar::Alignment;
|
||||
use crate::config::LabelPrefix;
|
||||
use crate::widget::BarWidget;
|
||||
use crate::widget::RenderConfig;
|
||||
@@ -71,13 +70,7 @@ impl Cpu {
|
||||
}
|
||||
|
||||
impl BarWidget for Cpu {
|
||||
fn render(
|
||||
&mut self,
|
||||
ctx: &Context,
|
||||
ui: &mut Ui,
|
||||
mut config: RenderConfig,
|
||||
alignment: Alignment,
|
||||
) {
|
||||
fn render(&mut self, ctx: &Context, ui: &mut Ui, mut config: RenderConfig) {
|
||||
if self.enable {
|
||||
let output = self.output();
|
||||
if !output.is_empty() {
|
||||
@@ -106,7 +99,7 @@ impl BarWidget for Cpu {
|
||||
TextFormat::simple(font_id, ctx.style().visuals.text_color()),
|
||||
);
|
||||
|
||||
config.grouping.apply_on_widget(true, alignment, ui, |ui| {
|
||||
config.grouping.apply_on_widget(true, config, ui, |ui| {
|
||||
if ui
|
||||
.add(
|
||||
Label::new(layout_job)
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use crate::bar::Alignment;
|
||||
use crate::config::LabelPrefix;
|
||||
use crate::widget::BarWidget;
|
||||
use crate::widget::RenderConfig;
|
||||
@@ -87,13 +86,7 @@ impl Date {
|
||||
}
|
||||
|
||||
impl BarWidget for Date {
|
||||
fn render(
|
||||
&mut self,
|
||||
ctx: &Context,
|
||||
ui: &mut Ui,
|
||||
mut config: RenderConfig,
|
||||
alignment: Alignment,
|
||||
) {
|
||||
fn render(&mut self, ctx: &Context, ui: &mut Ui, mut config: RenderConfig) {
|
||||
if self.enable {
|
||||
let mut output = self.output();
|
||||
if !output.is_empty() {
|
||||
@@ -126,7 +119,7 @@ impl BarWidget for Date {
|
||||
TextFormat::simple(font_id, ctx.style().visuals.text_color()),
|
||||
);
|
||||
|
||||
config.grouping.apply_on_widget(true, alignment, ui, |ui| {
|
||||
config.grouping.apply_on_widget(true, config, ui, |ui| {
|
||||
if ui
|
||||
.add(
|
||||
Label::new(WidgetText::LayoutJob(layout_job.clone()))
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use crate::bar::Alignment;
|
||||
use crate::config::Color32Ext;
|
||||
use crate::widget::RenderConfig;
|
||||
use crate::BACKGROUND_COLOR;
|
||||
use crate::WIDGET_SPACING;
|
||||
use eframe::egui::Color32;
|
||||
use eframe::egui::Frame;
|
||||
use eframe::egui::InnerResponse;
|
||||
@@ -58,29 +58,29 @@ impl Grouping {
|
||||
pub fn apply_on_widget<R>(
|
||||
&mut self,
|
||||
use_spacing: bool,
|
||||
alignment: Alignment,
|
||||
render_config: RenderConfig,
|
||||
ui: &mut Ui,
|
||||
add_contents: impl FnOnce(&mut Ui) -> R,
|
||||
) -> InnerResponse<R> {
|
||||
match self {
|
||||
Self::Bar(_) => Self::widget_group(use_spacing, alignment, ui, add_contents),
|
||||
Self::Alignment(_) => Self::widget_group(use_spacing, alignment, ui, add_contents),
|
||||
Self::Bar(_) => Self::widget_group(use_spacing, render_config, ui, add_contents),
|
||||
Self::Alignment(_) => Self::widget_group(use_spacing, render_config, ui, add_contents),
|
||||
Self::Widget(config) => {
|
||||
Self::define_group(use_spacing, Some(alignment), ui, add_contents, config)
|
||||
Self::define_group(use_spacing, Some(render_config), ui, add_contents, config)
|
||||
}
|
||||
Self::None => Self::widget_group(use_spacing, alignment, ui, add_contents),
|
||||
Self::None => Self::widget_group(use_spacing, render_config, ui, add_contents),
|
||||
}
|
||||
}
|
||||
|
||||
fn define_group<R>(
|
||||
use_spacing: bool,
|
||||
alignment: Option<Alignment>,
|
||||
render_config: Option<RenderConfig>,
|
||||
ui: &mut Ui,
|
||||
add_contents: impl FnOnce(&mut Ui) -> R,
|
||||
config: &mut GroupingConfig,
|
||||
) -> InnerResponse<R> {
|
||||
Frame::none()
|
||||
.outer_margin(Self::widget_outer_margin(alignment))
|
||||
.outer_margin(Self::widget_outer_margin(render_config))
|
||||
.inner_margin(match use_spacing {
|
||||
true => Margin::symmetric(5.0 + 3.0, 3.0),
|
||||
false => Margin::symmetric(3.0, 3.0),
|
||||
@@ -112,12 +112,12 @@ impl Grouping {
|
||||
|
||||
fn widget_group<R>(
|
||||
use_spacing: bool,
|
||||
alignment: Alignment,
|
||||
render_config: RenderConfig,
|
||||
ui: &mut Ui,
|
||||
add_contents: impl FnOnce(&mut Ui) -> R,
|
||||
) -> InnerResponse<R> {
|
||||
Frame::none()
|
||||
.outer_margin(Self::widget_outer_margin(Some(alignment)))
|
||||
.outer_margin(Self::widget_outer_margin(Some(render_config)))
|
||||
.inner_margin(match use_spacing {
|
||||
true => Margin::symmetric(5.0, 0.0),
|
||||
false => Margin::same(0.0),
|
||||
@@ -132,19 +132,25 @@ impl Grouping {
|
||||
}
|
||||
}
|
||||
|
||||
fn widget_outer_margin(alignment: Option<Alignment>) -> Margin {
|
||||
fn widget_outer_margin(render_config: Option<RenderConfig>) -> Margin {
|
||||
Margin {
|
||||
left: match alignment {
|
||||
Some(align) => match align {
|
||||
Alignment::Left => 0.0,
|
||||
Alignment::Right => WIDGET_SPACING,
|
||||
left: match render_config {
|
||||
Some(config) => match config.alignment {
|
||||
Some(align) => match align {
|
||||
Alignment::Left => 0.0,
|
||||
Alignment::Right => config.spacing,
|
||||
},
|
||||
None => 0.0,
|
||||
},
|
||||
None => 0.0,
|
||||
},
|
||||
right: match alignment {
|
||||
Some(align) => match align {
|
||||
Alignment::Left => WIDGET_SPACING,
|
||||
Alignment::Right => 0.0,
|
||||
right: match render_config {
|
||||
Some(config) => match config.alignment {
|
||||
Some(align) => match align {
|
||||
Alignment::Left => config.spacing,
|
||||
Alignment::Right => 0.0,
|
||||
},
|
||||
None => 0.0,
|
||||
},
|
||||
None => 0.0,
|
||||
},
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
use crate::bar::apply_theme;
|
||||
use crate::bar::Alignment;
|
||||
use crate::config::KomobarTheme;
|
||||
use crate::ui::CustomUi;
|
||||
use crate::widget::BarWidget;
|
||||
@@ -123,20 +122,14 @@ pub struct Komorebi {
|
||||
}
|
||||
|
||||
impl BarWidget for Komorebi {
|
||||
fn render(
|
||||
&mut self,
|
||||
ctx: &Context,
|
||||
ui: &mut Ui,
|
||||
mut config: RenderConfig,
|
||||
alignment: Alignment,
|
||||
) {
|
||||
fn render(&mut self, ctx: &Context, ui: &mut Ui, mut config: RenderConfig) {
|
||||
let mut komorebi_notification_state = self.komorebi_notification_state.borrow_mut();
|
||||
|
||||
if self.workspaces.enable {
|
||||
let mut update = None;
|
||||
|
||||
// NOTE: There should always be at least one workspace.
|
||||
config.grouping.apply_on_widget(false, alignment, ui, |ui| {
|
||||
config.grouping.apply_on_widget(false, config, ui, |ui| {
|
||||
for (i, (ws, should_show)) in
|
||||
komorebi_notification_state.workspaces.iter().enumerate()
|
||||
{
|
||||
@@ -203,7 +196,7 @@ impl BarWidget for Komorebi {
|
||||
|
||||
if let Some(layout) = self.layout {
|
||||
if layout.enable {
|
||||
config.grouping.apply_on_widget(true, alignment, ui, |ui| {
|
||||
config.grouping.apply_on_widget(true, config, ui, |ui| {
|
||||
if ui
|
||||
.add(
|
||||
Label::new(komorebi_notification_state.layout.to_string())
|
||||
@@ -254,7 +247,7 @@ impl BarWidget for Komorebi {
|
||||
for (name, location) in configuration_switcher.configurations.iter() {
|
||||
let path = PathBuf::from(location);
|
||||
if path.is_file() {
|
||||
config.grouping.apply_on_widget(true, alignment, ui,|ui|{
|
||||
config.grouping.apply_on_widget(true, config, ui,|ui|{
|
||||
if ui
|
||||
.add(Label::new(name).selectable(false).sense(Sense::click()))
|
||||
.clicked()
|
||||
@@ -312,7 +305,7 @@ impl BarWidget for Komorebi {
|
||||
let titles = &komorebi_notification_state.focused_container_information.0;
|
||||
|
||||
if !titles.is_empty() {
|
||||
config.grouping.apply_on_widget(true, alignment, ui, |ui| {
|
||||
config.grouping.apply_on_widget(true, config, ui, |ui| {
|
||||
let icons = &komorebi_notification_state.focused_container_information.1;
|
||||
let focused_window_idx =
|
||||
komorebi_notification_state.focused_container_information.2;
|
||||
|
||||
@@ -44,8 +44,6 @@ use windows::Win32::UI::HiDpi::DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2;
|
||||
use windows::Win32::UI::WindowsAndMessaging::EnumThreadWindows;
|
||||
use windows::Win32::UI::WindowsAndMessaging::GetWindowThreadProcessId;
|
||||
|
||||
pub static WIDGET_SPACING: f32 = 10.0;
|
||||
|
||||
pub static BACKGROUND_COLOR: AtomicU32 = AtomicU32::new(0);
|
||||
pub static MAX_LABEL_WIDTH: AtomicI32 = AtomicI32::new(400);
|
||||
pub static MONITOR_LEFT: AtomicI32 = AtomicI32::new(0);
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use crate::bar::Alignment;
|
||||
use crate::ui::CustomUi;
|
||||
use crate::widget::BarWidget;
|
||||
use crate::widget::RenderConfig;
|
||||
@@ -79,13 +78,7 @@ impl Media {
|
||||
}
|
||||
|
||||
impl BarWidget for Media {
|
||||
fn render(
|
||||
&mut self,
|
||||
ctx: &Context,
|
||||
ui: &mut Ui,
|
||||
mut config: RenderConfig,
|
||||
alignment: Alignment,
|
||||
) {
|
||||
fn render(&mut self, ctx: &Context, ui: &mut Ui, mut config: RenderConfig) {
|
||||
if self.enable {
|
||||
let output = self.output();
|
||||
if !output.is_empty() {
|
||||
@@ -109,7 +102,7 @@ impl BarWidget for Media {
|
||||
TextFormat::simple(font_id, ctx.style().visuals.text_color()),
|
||||
);
|
||||
|
||||
config.grouping.apply_on_widget(true, alignment, ui, |ui| {
|
||||
config.grouping.apply_on_widget(true, config, ui, |ui| {
|
||||
let available_height = ui.available_height();
|
||||
let mut custom_ui = CustomUi(ui);
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use crate::bar::Alignment;
|
||||
use crate::config::LabelPrefix;
|
||||
use crate::widget::BarWidget;
|
||||
use crate::widget::RenderConfig;
|
||||
@@ -74,13 +73,7 @@ impl Memory {
|
||||
}
|
||||
|
||||
impl BarWidget for Memory {
|
||||
fn render(
|
||||
&mut self,
|
||||
ctx: &Context,
|
||||
ui: &mut Ui,
|
||||
mut config: RenderConfig,
|
||||
alignment: Alignment,
|
||||
) {
|
||||
fn render(&mut self, ctx: &Context, ui: &mut Ui, mut config: RenderConfig) {
|
||||
if self.enable {
|
||||
let output = self.output();
|
||||
if !output.is_empty() {
|
||||
@@ -109,7 +102,7 @@ impl BarWidget for Memory {
|
||||
TextFormat::simple(font_id, ctx.style().visuals.text_color()),
|
||||
);
|
||||
|
||||
config.grouping.apply_on_widget(true, alignment, ui, |ui| {
|
||||
config.grouping.apply_on_widget(true, config, ui, |ui| {
|
||||
if ui
|
||||
.add(
|
||||
Label::new(layout_job)
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use crate::bar::Alignment;
|
||||
use crate::config::LabelPrefix;
|
||||
use crate::widget::BarWidget;
|
||||
use crate::widget::RenderConfig;
|
||||
@@ -318,16 +317,10 @@ impl Network {
|
||||
}
|
||||
|
||||
impl BarWidget for Network {
|
||||
fn render(
|
||||
&mut self,
|
||||
ctx: &Context,
|
||||
ui: &mut Ui,
|
||||
mut config: RenderConfig,
|
||||
alignment: Alignment,
|
||||
) {
|
||||
fn render(&mut self, ctx: &Context, ui: &mut Ui, mut config: RenderConfig) {
|
||||
if self.show_total_data_transmitted {
|
||||
for output in self.total_data_transmitted() {
|
||||
config.grouping.apply_on_widget(true, alignment, ui, |ui| {
|
||||
config.grouping.apply_on_widget(true, config, ui, |ui| {
|
||||
ui.add(Label::new(output).selectable(false));
|
||||
});
|
||||
}
|
||||
@@ -335,7 +328,7 @@ impl BarWidget for Network {
|
||||
|
||||
if self.show_network_activity {
|
||||
for output in self.network_activity() {
|
||||
config.grouping.apply_on_widget(true, alignment, ui, |ui| {
|
||||
config.grouping.apply_on_widget(true, config, ui, |ui| {
|
||||
ui.add(Label::new(output).selectable(false));
|
||||
});
|
||||
}
|
||||
@@ -374,7 +367,7 @@ impl BarWidget for Network {
|
||||
TextFormat::simple(font_id, ctx.style().visuals.text_color()),
|
||||
);
|
||||
|
||||
config.grouping.apply_on_widget(true, alignment, ui, |ui| {
|
||||
config.grouping.apply_on_widget(true, config, ui, |ui| {
|
||||
if ui
|
||||
.add(
|
||||
Label::new(layout_job)
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use crate::bar::Alignment;
|
||||
use crate::config::LabelPrefix;
|
||||
use crate::widget::BarWidget;
|
||||
use crate::widget::RenderConfig;
|
||||
@@ -80,13 +79,7 @@ impl Storage {
|
||||
}
|
||||
|
||||
impl BarWidget for Storage {
|
||||
fn render(
|
||||
&mut self,
|
||||
ctx: &Context,
|
||||
ui: &mut Ui,
|
||||
mut config: RenderConfig,
|
||||
alignment: Alignment,
|
||||
) {
|
||||
fn render(&mut self, ctx: &Context, ui: &mut Ui, mut config: RenderConfig) {
|
||||
if self.enable {
|
||||
let font_id = ctx
|
||||
.style()
|
||||
@@ -114,7 +107,7 @@ impl BarWidget for Storage {
|
||||
TextFormat::simple(font_id.clone(), ctx.style().visuals.text_color()),
|
||||
);
|
||||
|
||||
config.grouping.apply_on_widget(true, alignment, ui, |ui| {
|
||||
config.grouping.apply_on_widget(true, config, ui, |ui| {
|
||||
if ui
|
||||
.add(
|
||||
Label::new(layout_job)
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use crate::bar::Alignment;
|
||||
use crate::config::LabelPrefix;
|
||||
use crate::widget::BarWidget;
|
||||
use crate::widget::RenderConfig;
|
||||
@@ -78,13 +77,7 @@ impl Time {
|
||||
}
|
||||
|
||||
impl BarWidget for Time {
|
||||
fn render(
|
||||
&mut self,
|
||||
ctx: &Context,
|
||||
ui: &mut Ui,
|
||||
mut config: RenderConfig,
|
||||
alignment: Alignment,
|
||||
) {
|
||||
fn render(&mut self, ctx: &Context, ui: &mut Ui, mut config: RenderConfig) {
|
||||
if self.enable {
|
||||
let mut output = self.output();
|
||||
if !output.is_empty() {
|
||||
@@ -117,7 +110,7 @@ impl BarWidget for Time {
|
||||
TextFormat::simple(font_id, ctx.style().visuals.text_color()),
|
||||
);
|
||||
|
||||
config.grouping.apply_on_widget(true, alignment, ui, |ui| {
|
||||
config.grouping.apply_on_widget(true, config, ui, |ui| {
|
||||
if ui
|
||||
.add(
|
||||
Label::new(layout_job)
|
||||
|
||||
@@ -25,13 +25,17 @@ use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
pub trait BarWidget {
|
||||
fn render(&mut self, ctx: &Context, ui: &mut Ui, config: RenderConfig, alignment: Alignment);
|
||||
fn render(&mut self, ctx: &Context, ui: &mut Ui, config: RenderConfig);
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct RenderConfig {
|
||||
/// Spacing between widgets
|
||||
pub spacing: f32,
|
||||
/// Sets how widgets are grouped
|
||||
pub grouping: Grouping,
|
||||
/// Alignment of the widgets
|
||||
pub alignment: Option<Alignment>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
|
||||
|
||||
Reference in New Issue
Block a user