added widget grouping and group module

This commit is contained in:
Csaba
2024-11-08 00:40:13 +01:00
parent f446a6a45f
commit d188222be7
14 changed files with 436 additions and 376 deletions
+13 -3
View File
@@ -1,8 +1,10 @@
use crate::config::Grouping;
use crate::config::KomobarConfig; 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::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;
@@ -319,8 +321,16 @@ impl Komobar {
let mut komobar = Self { let mut komobar = Self {
config: config.clone(), config: config.clone(),
render_config: RenderConfig { render_config: RenderConfig {
_grouping: match config.grouping { grouping: match config.grouping {
None => Grouping::None, // TESTING
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,
}, },
}, },
+8 -6
View File
@@ -116,7 +116,7 @@ impl Battery {
} }
impl BarWidget for Battery { impl BarWidget for Battery {
fn render(&mut self, ctx: &Context, ui: &mut Ui, _config: RenderConfig) { fn render(&mut self, ctx: &Context, ui: &mut Ui, mut config: RenderConfig) {
if self.enable { if self.enable {
let output = self.output(); let output = self.output();
if !output.is_empty() { if !output.is_empty() {
@@ -148,11 +148,13 @@ impl BarWidget for Battery {
TextFormat::simple(font_id, ctx.style().visuals.text_color()), TextFormat::simple(font_id, ctx.style().visuals.text_color()),
); );
ui.add( config.grouping.apply_on_widget(ui, |ui| {
Label::new(layout_job) ui.add(
.selectable(false) Label::new(layout_job)
.sense(Sense::click()), .selectable(false)
); .sense(Sense::click()),
);
});
} }
ui.add_space(WIDGET_SPACING); ui.add_space(WIDGET_SPACING);
+1 -39
View File
@@ -1,6 +1,6 @@
use crate::group::Grouping;
use crate::widget::WidgetConfig; use crate::widget::WidgetConfig;
use eframe::egui::Pos2; use eframe::egui::Pos2;
use eframe::egui::Rounding;
use eframe::egui::TextBuffer; use eframe::egui::TextBuffer;
use eframe::egui::Vec2; use eframe::egui::Vec2;
use komorebi_client::KomorebiTheme; use komorebi_client::KomorebiTheme;
@@ -181,41 +181,3 @@ pub enum LabelPrefix {
/// Show an icon and text /// Show an icon and text
IconAndText, IconAndText,
} }
#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema)]
pub enum Grouping {
/// No grouping is applied
None,
/// Widgets are grouped individually
Widget(GroupingConfig),
/// Widgets are grouped on each side
Side(GroupingConfig),
}
#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema)]
pub struct GroupingConfig {
pub rounding: Option<BorderRadius>,
}
#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema)]
pub struct BorderRadius {
/// Radius of the rounding of the North-West (left top) corner.
pub nw: f32,
/// Radius of the rounding of the North-East (right top) corner.
pub ne: f32,
/// Radius of the rounding of the South-West (left bottom) corner.
pub sw: f32,
/// Radius of the rounding of the South-East (right bottom) corner.
pub se: f32,
}
impl From<BorderRadius> for Rounding {
fn from(value: BorderRadius) -> Self {
Self {
nw: value.nw,
ne: value.ne,
sw: value.sw,
se: value.se,
}
}
}
+15 -12
View File
@@ -71,7 +71,7 @@ impl Cpu {
} }
impl BarWidget for Cpu { impl BarWidget for Cpu {
fn render(&mut self, ctx: &Context, ui: &mut Ui, _config: RenderConfig) { fn render(&mut self, ctx: &Context, ui: &mut Ui, mut config: RenderConfig) {
if self.enable { if self.enable {
let output = self.output(); let output = self.output();
if !output.is_empty() { if !output.is_empty() {
@@ -100,19 +100,22 @@ impl BarWidget for Cpu {
TextFormat::simple(font_id, ctx.style().visuals.text_color()), TextFormat::simple(font_id, ctx.style().visuals.text_color()),
); );
if ui config.grouping.apply_on_widget(ui, |ui| {
.add( if ui
Label::new(layout_job) .add(
.selectable(false) Label::new(layout_job)
.sense(Sense::click()), .selectable(false)
) .sense(Sense::click()),
.clicked() )
{ .clicked()
if let Err(error) = Command::new("cmd.exe").args(["/C", "taskmgr.exe"]).spawn()
{ {
eprintln!("{}", error) if let Err(error) =
Command::new("cmd.exe").args(["/C", "taskmgr.exe"]).spawn()
{
eprintln!("{}", error)
}
} }
} });
} }
ui.add_space(WIDGET_SPACING); ui.add_space(WIDGET_SPACING);
+13 -11
View File
@@ -87,7 +87,7 @@ impl Date {
} }
impl BarWidget for Date { impl BarWidget for Date {
fn render(&mut self, ctx: &Context, ui: &mut Ui, _config: RenderConfig) { fn render(&mut self, ctx: &Context, ui: &mut Ui, mut config: RenderConfig) {
if self.enable { if self.enable {
let mut output = self.output(); let mut output = self.output();
if !output.is_empty() { if !output.is_empty() {
@@ -120,16 +120,18 @@ impl BarWidget for Date {
TextFormat::simple(font_id, ctx.style().visuals.text_color()), TextFormat::simple(font_id, ctx.style().visuals.text_color()),
); );
if ui config.grouping.apply_on_widget(ui, |ui| {
.add( if ui
Label::new(WidgetText::LayoutJob(layout_job.clone())) .add(
.selectable(false) Label::new(WidgetText::LayoutJob(layout_job.clone()))
.sense(Sense::click()), .selectable(false)
) .sense(Sense::click()),
.clicked() )
{ .clicked()
self.format.next() {
} self.format.next()
}
});
} }
ui.add_space(WIDGET_SPACING); ui.add_space(WIDGET_SPACING);
+74
View File
@@ -0,0 +1,74 @@
use eframe::egui::Frame;
use eframe::egui::InnerResponse;
use eframe::egui::Margin;
use eframe::egui::Rounding;
use eframe::egui::Ui;
use schemars::JsonSchema;
use serde::Deserialize;
use serde::Serialize;
#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema)]
pub enum Grouping {
/// No grouping is applied
None,
/// Widgets are grouped individually
Widget(GroupingConfig),
/// Widgets are grouped on each side
Side(GroupingConfig),
}
impl Grouping {
pub fn apply_on_widget<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) => {
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(Rounding::same(15.0))
.stroke(ui.style().visuals.widgets.noninteractive.bg_stroke)
.show(ui, add_contents)
}
Self::Side(_config) => InnerResponse {
inner: add_contents(ui),
response: ui.response().clone(),
},
}
}
}
#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema)]
pub struct GroupingConfig {
pub rounding: Option<BorderRadius>,
}
#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema)]
pub struct BorderRadius {
/// Radius of the rounding of the North-West (left top) corner.
pub nw: f32,
/// Radius of the rounding of the North-East (right top) corner.
pub ne: f32,
/// Radius of the rounding of the South-West (left bottom) corner.
pub sw: f32,
/// Radius of the rounding of the South-East (right bottom) corner.
pub se: f32,
}
impl From<BorderRadius> for Rounding {
fn from(value: BorderRadius) -> Self {
Self {
nw: value.nw,
ne: value.ne,
sw: value.sw,
se: value.se,
}
}
}
+221 -191
View File
@@ -123,58 +123,71 @@ pub struct Komorebi {
} }
impl BarWidget for Komorebi { impl BarWidget for Komorebi {
fn render(&mut self, ctx: &Context, ui: &mut Ui, _config: RenderConfig) { fn render(&mut self, ctx: &Context, ui: &mut Ui, mut config: RenderConfig) {
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;
for (i, (ws, should_show)) in komorebi_notification_state.workspaces.iter().enumerate() config.grouping.apply_on_widget(ui, |ui| {
{ for (i, (ws, should_show)) in
if *should_show komorebi_notification_state.workspaces.iter().enumerate()
&& ui
.add(SelectableLabel::new(
komorebi_notification_state.selected_workspace.eq(ws),
ws.to_string(),
))
.clicked()
{ {
update = Some(ws.to_string()); if *should_show
let mut proceed = true; && ui
.add(SelectableLabel::new(
if komorebi_client::send_message(&SocketMessage::MouseFollowsFocus(false)) komorebi_notification_state.selected_workspace.eq(ws),
.is_err() ws.to_string(),
))
.clicked()
{ {
tracing::error!("could not send message to komorebi: MouseFollowsFocus"); update = Some(ws.to_string());
proceed = false; let mut proceed = true;
}
if proceed if komorebi_client::send_message(&SocketMessage::MouseFollowsFocus(false))
&& komorebi_client::send_message(&SocketMessage::FocusWorkspaceNumber(i))
.is_err() .is_err()
{ {
tracing::error!("could not send message to komorebi: FocusWorkspaceNumber"); tracing::error!(
proceed = false; "could not send message to komorebi: MouseFollowsFocus"
} );
proceed = false;
}
if proceed if proceed
&& komorebi_client::send_message(&SocketMessage::MouseFollowsFocus( && komorebi_client::send_message(&SocketMessage::FocusWorkspaceNumber(
komorebi_notification_state.mouse_follows_focus, i,
)) ))
.is_err()
{
tracing::error!("could not send message to komorebi: MouseFollowsFocus");
proceed = false;
}
if proceed
&& komorebi_client::send_message(&SocketMessage::RetileWithResizeDimensions)
.is_err() .is_err()
{ {
tracing::error!("could not send message to komorebi: Retile"); tracing::error!(
"could not send message to komorebi: FocusWorkspaceNumber"
);
proceed = false;
}
if proceed
&& komorebi_client::send_message(&SocketMessage::MouseFollowsFocus(
komorebi_notification_state.mouse_follows_focus,
))
.is_err()
{
tracing::error!(
"could not send message to komorebi: MouseFollowsFocus"
);
proceed = false;
}
if proceed
&& komorebi_client::send_message(
&SocketMessage::RetileWithResizeDimensions,
)
.is_err()
{
tracing::error!("could not send message to komorebi: Retile");
}
} }
} }
} });
if let Some(update) = update { if let Some(update) = update {
komorebi_notification_state.selected_workspace = update; komorebi_notification_state.selected_workspace = update;
@@ -185,38 +198,49 @@ impl BarWidget for Komorebi {
if let Some(layout) = self.layout { if let Some(layout) = self.layout {
if layout.enable { if layout.enable {
if ui config.grouping.apply_on_widget(ui, |ui| {
.add( if ui
Label::new(komorebi_notification_state.layout.to_string()) .add(
.selectable(false) Label::new(komorebi_notification_state.layout.to_string())
.sense(Sense::click()), .selectable(false)
) .sense(Sense::click()),
.clicked() )
{ .clicked()
match komorebi_notification_state.layout { {
KomorebiLayout::Default(_) => { match komorebi_notification_state.layout {
if komorebi_client::send_message(&SocketMessage::CycleLayout( KomorebiLayout::Default(_) => {
CycleDirection::Next, if komorebi_client::send_message(&SocketMessage::CycleLayout(
)) CycleDirection::Next,
.is_err() ))
{ .is_err()
tracing::error!("could not send message to komorebi: CycleLayout"); {
tracing::error!(
"could not send message to komorebi: CycleLayout"
);
}
} }
} KomorebiLayout::Floating => {
KomorebiLayout::Floating => { if komorebi_client::send_message(&SocketMessage::ToggleTiling)
if komorebi_client::send_message(&SocketMessage::ToggleTiling).is_err() .is_err()
{ {
tracing::error!("could not send message to komorebi: ToggleTiling"); tracing::error!(
"could not send message to komorebi: ToggleTiling"
);
}
} }
} KomorebiLayout::Paused => {
KomorebiLayout::Paused => { if komorebi_client::send_message(&SocketMessage::TogglePause)
if komorebi_client::send_message(&SocketMessage::TogglePause).is_err() { .is_err()
tracing::error!("could not send message to komorebi: TogglePause"); {
tracing::error!(
"could not send message to komorebi: TogglePause"
);
}
} }
KomorebiLayout::Custom => {}
} }
KomorebiLayout::Custom => {}
} }
} });
ui.add_space(WIDGET_SPACING); ui.add_space(WIDGET_SPACING);
} }
@@ -226,53 +250,55 @@ impl BarWidget for Komorebi {
if configuration_switcher.enable { if configuration_switcher.enable {
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() {
&& ui config.grouping.apply_on_widget(ui,|ui|{
if ui
.add(Label::new(name).selectable(false).sense(Sense::click())) .add(Label::new(name).selectable(false).sense(Sense::click()))
.clicked() .clicked()
{
let canonicalized = dunce::canonicalize(path.clone()).unwrap_or(path);
let mut proceed = true;
if komorebi_client::send_message(&SocketMessage::ReplaceConfiguration(
canonicalized,
))
.is_err()
{ {
tracing::error!( let canonicalized = dunce::canonicalize(path.clone()).unwrap_or(path);
"could not send message to komorebi: ReplaceConfiguration" let mut proceed = true;
); if komorebi_client::send_message(&SocketMessage::ReplaceConfiguration(
proceed = false; canonicalized,
} ))
.is_err()
{
tracing::error!(
"could not send message to komorebi: ReplaceConfiguration"
);
proceed = false;
}
if let Some(rect) = komorebi_notification_state.work_area_offset { if let Some(rect) = komorebi_notification_state.work_area_offset {
if proceed { if proceed {
match komorebi_client::send_query(&SocketMessage::Query( match komorebi_client::send_query(&SocketMessage::Query(
komorebi_client::StateQuery::FocusedMonitorIndex, komorebi_client::StateQuery::FocusedMonitorIndex,
)) { )) {
Ok(idx) => { Ok(idx) => {
if let Ok(monitor_idx) = idx.parse::<usize>() { if let Ok(monitor_idx) = idx.parse::<usize>() {
if komorebi_client::send_message( if komorebi_client::send_message(
&SocketMessage::MonitorWorkAreaOffset( &SocketMessage::MonitorWorkAreaOffset(
monitor_idx, monitor_idx,
rect, rect,
), ),
) )
.is_err() .is_err()
{ {
tracing::error!( tracing::error!(
"could not send message to komorebi: MonitorWorkAreaOffset" "could not send message to komorebi: MonitorWorkAreaOffset"
); );
}
} }
} }
} Err(_) => {
Err(_) => { tracing::error!(
tracing::error!( "could not send message to komorebi: Query"
"could not send message to komorebi: Query" );
); }
} }
} }
} }
} }});
} }
} }
@@ -282,111 +308,115 @@ impl BarWidget for Komorebi {
if let Some(focused_window) = self.focused_window { if let Some(focused_window) = self.focused_window {
if focused_window.enable { if focused_window.enable {
let titles = &komorebi_notification_state.focused_container_information.0; config.grouping.apply_on_widget(ui, |ui| {
let icons = &komorebi_notification_state.focused_container_information.1; let titles = &komorebi_notification_state.focused_container_information.0;
let focused_window_idx = let icons = &komorebi_notification_state.focused_container_information.1;
komorebi_notification_state.focused_container_information.2; let focused_window_idx =
komorebi_notification_state.focused_container_information.2;
let iter = titles.iter().zip(icons.iter()); let iter = titles.iter().zip(icons.iter());
for (i, (title, icon)) in iter.enumerate() { for (i, (title, icon)) in iter.enumerate() {
if focused_window.show_icon { if focused_window.show_icon {
if let Some(img) = icon { if let Some(img) = icon {
ui.add( ui.add(
Image::from(&img_to_texture(ctx, img)) Image::from(&img_to_texture(ctx, img))
.maintain_aspect_ratio(true) .maintain_aspect_ratio(true)
.max_height(15.0), .max_height(15.0),
); );
}
} }
}
if i == focused_window_idx { if i == focused_window_idx {
let font_id = ctx let font_id = ctx
.style() .style()
.text_styles .text_styles
.get(&TextStyle::Body) .get(&TextStyle::Body)
.cloned() .cloned()
.unwrap_or_else(FontId::default); .unwrap_or_else(FontId::default);
let layout_job = LayoutJob::simple( let layout_job = LayoutJob::simple(
title.to_string(), title.to_string(),
font_id.clone(), font_id.clone(),
komorebi_notification_state komorebi_notification_state
.stack_accent .stack_accent
.unwrap_or(ctx.style().visuals.selection.stroke.color), .unwrap_or(ctx.style().visuals.selection.stroke.color),
100.0, 100.0,
);
if titles.len() > 1 {
let available_height = ui.available_height();
let mut custom_ui = CustomUi(ui);
custom_ui.add_sized_left_to_right(
Vec2::new(
MAX_LABEL_WIDTH.load(Ordering::SeqCst) as f32,
available_height,
),
Label::new(layout_job).selectable(false).truncate(),
); );
if titles.len() > 1 {
let available_height = ui.available_height();
let mut custom_ui = CustomUi(ui);
custom_ui.add_sized_left_to_right(
Vec2::new(
MAX_LABEL_WIDTH.load(Ordering::SeqCst) as f32,
available_height,
),
Label::new(layout_job).selectable(false).truncate(),
);
} else {
let available_height = ui.available_height();
let mut custom_ui = CustomUi(ui);
custom_ui.add_sized_left_to_right(
Vec2::new(
MAX_LABEL_WIDTH.load(Ordering::SeqCst) as f32,
available_height,
),
Label::new(title).selectable(false).truncate(),
);
}
} else { } else {
let available_height = ui.available_height(); let available_height = ui.available_height();
let mut custom_ui = CustomUi(ui); let mut custom_ui = CustomUi(ui);
custom_ui.add_sized_left_to_right(
Vec2::new(
MAX_LABEL_WIDTH.load(Ordering::SeqCst) as f32,
available_height,
),
Label::new(title).selectable(false).truncate(),
);
}
} else {
let available_height = ui.available_height();
let mut custom_ui = CustomUi(ui);
if custom_ui if custom_ui
.add_sized_left_to_right( .add_sized_left_to_right(
Vec2::new( Vec2::new(
MAX_LABEL_WIDTH.load(Ordering::SeqCst) as f32, MAX_LABEL_WIDTH.load(Ordering::SeqCst) as f32,
available_height, available_height,
), ),
Label::new(title) Label::new(title)
.selectable(false) .selectable(false)
.sense(Sense::click()) .sense(Sense::click())
.truncate(), .truncate(),
) )
.clicked() .clicked()
{
if komorebi_client::send_message(&SocketMessage::MouseFollowsFocus(
false,
))
.is_err()
{ {
tracing::error!( if komorebi_client::send_message(&SocketMessage::MouseFollowsFocus(
"could not send message to komorebi: MouseFollowsFocus" false,
); ))
}
if komorebi_client::send_message(&SocketMessage::FocusStackWindow(i))
.is_err() .is_err()
{ {
tracing::error!( tracing::error!(
"could not send message to komorebi: FocusStackWindow" "could not send message to komorebi: MouseFollowsFocus"
); );
} }
if komorebi_client::send_message(&SocketMessage::MouseFollowsFocus( if komorebi_client::send_message(&SocketMessage::FocusStackWindow(
komorebi_notification_state.mouse_follows_focus, i,
)) ))
.is_err() .is_err()
{ {
tracing::error!( tracing::error!(
"could not send message to komorebi: MouseFollowsFocus" "could not send message to komorebi: FocusStackWindow"
); );
}
if komorebi_client::send_message(&SocketMessage::MouseFollowsFocus(
komorebi_notification_state.mouse_follows_focus,
))
.is_err()
{
tracing::error!(
"could not send message to komorebi: MouseFollowsFocus"
);
}
} }
} }
}
ui.add_space(WIDGET_SPACING); ui.add_space(WIDGET_SPACING);
} }
});
} }
ui.add_space(WIDGET_SPACING); ui.add_space(WIDGET_SPACING);
+1
View File
@@ -3,6 +3,7 @@ mod battery;
mod config; mod config;
mod cpu; mod cpu;
mod date; mod date;
mod group;
mod komorebi; mod komorebi;
mod media; mod media;
mod memory; mod memory;
+20 -18
View File
@@ -79,7 +79,7 @@ impl Media {
} }
impl BarWidget for Media { impl BarWidget for Media {
fn render(&mut self, ctx: &Context, ui: &mut Ui, _config: RenderConfig) { fn render(&mut self, ctx: &Context, ui: &mut Ui, mut config: RenderConfig) {
if self.enable { if self.enable {
let output = self.output(); let output = self.output();
if !output.is_empty() { if !output.is_empty() {
@@ -103,24 +103,26 @@ impl BarWidget for Media {
TextFormat::simple(font_id, ctx.style().visuals.text_color()), TextFormat::simple(font_id, ctx.style().visuals.text_color()),
); );
let available_height = ui.available_height(); config.grouping.apply_on_widget(ui, |ui| {
let mut custom_ui = CustomUi(ui); let available_height = ui.available_height();
let mut custom_ui = CustomUi(ui);
if custom_ui if custom_ui
.add_sized_left_to_right( .add_sized_left_to_right(
Vec2::new( Vec2::new(
MAX_LABEL_WIDTH.load(Ordering::SeqCst) as f32, MAX_LABEL_WIDTH.load(Ordering::SeqCst) as f32,
available_height, available_height,
), ),
Label::new(layout_job) Label::new(layout_job)
.selectable(false) .selectable(false)
.sense(Sense::click()) .sense(Sense::click())
.truncate(), .truncate(),
) )
.clicked() .clicked()
{ {
self.toggle(); self.toggle();
} }
});
ui.add_space(WIDGET_SPACING); ui.add_space(WIDGET_SPACING);
} }
+15 -12
View File
@@ -74,7 +74,7 @@ impl Memory {
} }
impl BarWidget for Memory { impl BarWidget for Memory {
fn render(&mut self, ctx: &Context, ui: &mut Ui, _config: RenderConfig) { fn render(&mut self, ctx: &Context, ui: &mut Ui, mut config: RenderConfig) {
if self.enable { if self.enable {
let output = self.output(); let output = self.output();
if !output.is_empty() { if !output.is_empty() {
@@ -103,19 +103,22 @@ impl BarWidget for Memory {
TextFormat::simple(font_id, ctx.style().visuals.text_color()), TextFormat::simple(font_id, ctx.style().visuals.text_color()),
); );
if ui config.grouping.apply_on_widget(ui, |ui| {
.add( if ui
Label::new(layout_job) .add(
.selectable(false) Label::new(layout_job)
.sense(Sense::click()), .selectable(false)
) .sense(Sense::click()),
.clicked() )
{ .clicked()
if let Err(error) = Command::new("cmd.exe").args(["/C", "taskmgr.exe"]).spawn()
{ {
eprintln!("{}", error) if let Err(error) =
Command::new("cmd.exe").args(["/C", "taskmgr.exe"]).spawn()
{
eprintln!("{}", error)
}
} }
} });
} }
ui.add_space(WIDGET_SPACING); ui.add_space(WIDGET_SPACING);
+20 -42
View File
@@ -5,10 +5,7 @@ use crate::WIDGET_SPACING;
use eframe::egui::text::LayoutJob; use eframe::egui::text::LayoutJob;
use eframe::egui::Context; use eframe::egui::Context;
use eframe::egui::FontId; use eframe::egui::FontId;
use eframe::egui::Frame;
use eframe::egui::Label; use eframe::egui::Label;
use eframe::egui::Margin;
use eframe::egui::Rounding;
use eframe::egui::Sense; use eframe::egui::Sense;
use eframe::egui::TextFormat; use eframe::egui::TextFormat;
use eframe::egui::TextStyle; use eframe::egui::TextStyle;
@@ -321,18 +318,12 @@ impl Network {
} }
impl BarWidget for Network { impl BarWidget for Network {
fn render(&mut self, ctx: &Context, ui: &mut Ui, _config: RenderConfig) { fn render(&mut self, ctx: &Context, ui: &mut Ui, mut config: RenderConfig) {
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() {
Frame::none() config.grouping.apply_on_widget(ui, |ui| {
//.fill(Color32::from_black_alpha(255u8)) ui.add(Label::new(output).selectable(false));
.outer_margin(Margin::symmetric(0.0, 0.0)) });
.inner_margin(Margin::symmetric(7.0, 2.0))
.rounding(Rounding::same(15.0))
.stroke(ui.style().visuals.widgets.noninteractive.bg_stroke)
.show(ui, |ui| {
ui.add(Label::new(output).selectable(false));
});
} }
ui.add_space(WIDGET_SPACING); ui.add_space(WIDGET_SPACING);
@@ -340,15 +331,9 @@ 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() {
Frame::none() config.grouping.apply_on_widget(ui, |ui| {
//.fill(Color32::from_black_alpha(255u8)) ui.add(Label::new(output).selectable(false));
.outer_margin(Margin::symmetric(0.0, 0.0)) });
.inner_margin(Margin::symmetric(7.0, 2.0))
.rounding(Rounding::same(15.0))
.stroke(ui.style().visuals.widgets.noninteractive.bg_stroke)
.show(ui, |ui| {
ui.add(Label::new(output).selectable(false));
});
} }
ui.add_space(WIDGET_SPACING); ui.add_space(WIDGET_SPACING);
@@ -387,27 +372,20 @@ impl BarWidget for Network {
TextFormat::simple(font_id, ctx.style().visuals.text_color()), TextFormat::simple(font_id, ctx.style().visuals.text_color()),
); );
Frame::none() config.grouping.apply_on_widget(ui, |ui| {
//.fill(Color32::from_black_alpha(255u8)) if ui
.outer_margin(Margin::symmetric(0.0, 0.0)) .add(
.inner_margin(Margin::symmetric(7.0, 2.0)) Label::new(layout_job)
.rounding(Rounding::same(15.0)) .selectable(false)
.stroke(ui.style().visuals.widgets.noninteractive.bg_stroke) .sense(Sense::click()),
.show(ui, |ui| { )
if ui .clicked()
.add( {
Label::new(layout_job) if let Err(error) = Command::new("cmd.exe").args(["/C", "ncpa"]).spawn() {
.selectable(false) eprintln!("{}", error)
.sense(Sense::click()),
)
.clicked()
{
if let Err(error) = Command::new("cmd.exe").args(["/C", "ncpa"]).spawn()
{
eprintln!("{}", error)
}
} }
}); }
});
} }
ui.add_space(WIDGET_SPACING); ui.add_space(WIDGET_SPACING);
+20 -18
View File
@@ -80,7 +80,7 @@ impl Storage {
} }
impl BarWidget for Storage { impl BarWidget for Storage {
fn render(&mut self, ctx: &Context, ui: &mut Ui, _config: RenderConfig) { fn render(&mut self, ctx: &Context, ui: &mut Ui, mut config: RenderConfig) {
if self.enable { if self.enable {
let font_id = ctx let font_id = ctx
.style() .style()
@@ -108,25 +108,27 @@ impl BarWidget for Storage {
TextFormat::simple(font_id.clone(), ctx.style().visuals.text_color()), TextFormat::simple(font_id.clone(), ctx.style().visuals.text_color()),
); );
if ui config.grouping.apply_on_widget(ui, |ui| {
.add( if ui
Label::new(layout_job) .add(
.selectable(false) Label::new(layout_job)
.sense(Sense::click()), .selectable(false)
) .sense(Sense::click()),
.clicked() )
{ .clicked()
if let Err(error) = Command::new("cmd.exe")
.args([
"/C",
"explorer.exe",
output.split(' ').collect::<Vec<&str>>()[0],
])
.spawn()
{ {
eprintln!("{}", error) if let Err(error) = Command::new("cmd.exe")
.args([
"/C",
"explorer.exe",
output.split(' ').collect::<Vec<&str>>()[0],
])
.spawn()
{
eprintln!("{}", error)
}
} }
} });
ui.add_space(WIDGET_SPACING); ui.add_space(WIDGET_SPACING);
} }
+13 -22
View File
@@ -5,10 +5,7 @@ use crate::WIDGET_SPACING;
use eframe::egui::text::LayoutJob; use eframe::egui::text::LayoutJob;
use eframe::egui::Context; use eframe::egui::Context;
use eframe::egui::FontId; use eframe::egui::FontId;
use eframe::egui::Frame;
use eframe::egui::Label; use eframe::egui::Label;
use eframe::egui::Margin;
use eframe::egui::Rounding;
use eframe::egui::Sense; use eframe::egui::Sense;
use eframe::egui::TextFormat; use eframe::egui::TextFormat;
use eframe::egui::TextStyle; use eframe::egui::TextStyle;
@@ -81,7 +78,7 @@ impl Time {
} }
impl BarWidget for Time { impl BarWidget for Time {
fn render(&mut self, ctx: &Context, ui: &mut Ui, _config: RenderConfig) { fn render(&mut self, ctx: &Context, ui: &mut Ui, mut config: RenderConfig) {
if self.enable { if self.enable {
let mut output = self.output(); let mut output = self.output();
if !output.is_empty() { if !output.is_empty() {
@@ -114,24 +111,18 @@ impl BarWidget for Time {
TextFormat::simple(font_id, ctx.style().visuals.text_color()), TextFormat::simple(font_id, ctx.style().visuals.text_color()),
); );
Frame::none() config.grouping.apply_on_widget(ui, |ui| {
//.fill(Color32::from_black_alpha(255u8)) if ui
.outer_margin(Margin::symmetric(0.0, 0.0)) .add(
.inner_margin(Margin::symmetric(7.0, 2.0)) Label::new(layout_job)
.rounding(Rounding::same(15.0)) .selectable(false)
.stroke(ui.style().visuals.widgets.noninteractive.bg_stroke) .sense(Sense::click()),
.show(ui, |ui| { )
if ui .clicked()
.add( {
Label::new(layout_job) self.format.toggle()
.selectable(false) }
.sense(Sense::click()), });
)
.clicked()
{
self.format.toggle()
}
});
} }
ui.add_space(WIDGET_SPACING); ui.add_space(WIDGET_SPACING);
+2 -2
View File
@@ -1,10 +1,10 @@
use crate::battery::Battery; use crate::battery::Battery;
use crate::battery::BatteryConfig; use crate::battery::BatteryConfig;
use crate::config::Grouping;
use crate::cpu::Cpu; use crate::cpu::Cpu;
use crate::cpu::CpuConfig; use crate::cpu::CpuConfig;
use crate::date::Date; use crate::date::Date;
use crate::date::DateConfig; use crate::date::DateConfig;
use crate::group::Grouping;
use crate::komorebi::Komorebi; use crate::komorebi::Komorebi;
use crate::komorebi::KomorebiConfig; use crate::komorebi::KomorebiConfig;
use crate::media::Media; use crate::media::Media;
@@ -30,7 +30,7 @@ pub trait BarWidget {
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
pub struct RenderConfig { pub struct RenderConfig {
/// Sets how widgets are grouped /// Sets how widgets are grouped
pub _grouping: Grouping, pub grouping: Grouping,
} }
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)] #[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]