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