mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-03-24 10:21:21 +01:00
adding RenderConfig, and some test frames on widgets
This commit is contained in:
@@ -6,6 +6,7 @@ use crate::komorebi::Komorebi;
|
||||
use crate::komorebi::KomorebiNotificationState;
|
||||
use crate::process_hwnd;
|
||||
use crate::widget::BarWidget;
|
||||
use crate::widget::RenderConfig;
|
||||
use crate::widget::WidgetConfig;
|
||||
use crate::BAR_HEIGHT;
|
||||
use crate::MAX_LABEL_WIDTH;
|
||||
@@ -41,6 +42,7 @@ use std::sync::Arc;
|
||||
|
||||
pub struct Komobar {
|
||||
pub config: Arc<KomobarConfig>,
|
||||
pub render_config: RenderConfig,
|
||||
pub komorebi_notification_state: Option<Rc<RefCell<KomorebiNotificationState>>>,
|
||||
pub left_widgets: Vec<Box<dyn BarWidget>>,
|
||||
pub right_widgets: Vec<Box<dyn BarWidget>>,
|
||||
@@ -315,6 +317,7 @@ impl Komobar {
|
||||
) -> Self {
|
||||
let mut komobar = Self {
|
||||
config: config.clone(),
|
||||
render_config: RenderConfig::from(config.clone()),
|
||||
komorebi_notification_state: None,
|
||||
left_widgets: vec![],
|
||||
right_widgets: vec![],
|
||||
@@ -437,13 +440,13 @@ impl eframe::App for Komobar {
|
||||
ui.horizontal_centered(|ui| {
|
||||
ui.with_layout(Layout::left_to_right(Align::Center), |ui| {
|
||||
for w in &mut self.left_widgets {
|
||||
w.render(ctx, ui);
|
||||
w.render(ctx, ui, self.render_config.clone());
|
||||
}
|
||||
});
|
||||
|
||||
ui.with_layout(Layout::right_to_left(Align::Center), |ui| {
|
||||
for w in &mut self.right_widgets {
|
||||
w.render(ctx, ui);
|
||||
w.render(ctx, ui, self.render_config.clone());
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use crate::config::LabelPrefix;
|
||||
use crate::widget::BarWidget;
|
||||
use crate::widget::RenderConfig;
|
||||
use crate::WIDGET_SPACING;
|
||||
use eframe::egui::text::LayoutJob;
|
||||
use eframe::egui::Context;
|
||||
@@ -115,7 +116,7 @@ impl Battery {
|
||||
}
|
||||
|
||||
impl BarWidget for Battery {
|
||||
fn render(&mut self, ctx: &Context, ui: &mut Ui) {
|
||||
fn render(&mut self, ctx: &Context, ui: &mut Ui, config: RenderConfig) {
|
||||
if self.enable {
|
||||
let output = self.output();
|
||||
if !output.is_empty() {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use crate::config::LabelPrefix;
|
||||
use crate::widget::BarWidget;
|
||||
use crate::widget::RenderConfig;
|
||||
use crate::WIDGET_SPACING;
|
||||
use eframe::egui::text::LayoutJob;
|
||||
use eframe::egui::Context;
|
||||
@@ -70,7 +71,7 @@ impl Cpu {
|
||||
}
|
||||
|
||||
impl BarWidget for Cpu {
|
||||
fn render(&mut self, ctx: &Context, ui: &mut Ui) {
|
||||
fn render(&mut self, ctx: &Context, ui: &mut Ui, config: RenderConfig) {
|
||||
if self.enable {
|
||||
let output = self.output();
|
||||
if !output.is_empty() {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use crate::config::LabelPrefix;
|
||||
use crate::widget::BarWidget;
|
||||
use crate::widget::RenderConfig;
|
||||
use crate::WIDGET_SPACING;
|
||||
use eframe::egui::text::LayoutJob;
|
||||
use eframe::egui::Context;
|
||||
@@ -86,7 +87,7 @@ impl Date {
|
||||
}
|
||||
|
||||
impl BarWidget for Date {
|
||||
fn render(&mut self, ctx: &Context, ui: &mut Ui) {
|
||||
fn render(&mut self, ctx: &Context, ui: &mut Ui, config: RenderConfig) {
|
||||
if self.enable {
|
||||
let mut output = self.output();
|
||||
if !output.is_empty() {
|
||||
|
||||
@@ -2,6 +2,7 @@ use crate::bar::apply_theme;
|
||||
use crate::config::KomobarTheme;
|
||||
use crate::ui::CustomUi;
|
||||
use crate::widget::BarWidget;
|
||||
use crate::widget::RenderConfig;
|
||||
use crate::MAX_LABEL_WIDTH;
|
||||
use crate::WIDGET_SPACING;
|
||||
use crossbeam_channel::Receiver;
|
||||
@@ -122,7 +123,7 @@ pub struct Komorebi {
|
||||
}
|
||||
|
||||
impl BarWidget for Komorebi {
|
||||
fn render(&mut self, ctx: &Context, ui: &mut Ui) {
|
||||
fn render(&mut self, ctx: &Context, ui: &mut Ui, config: RenderConfig) {
|
||||
let mut komorebi_notification_state = self.komorebi_notification_state.borrow_mut();
|
||||
|
||||
if self.workspaces.enable {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use crate::ui::CustomUi;
|
||||
use crate::widget::BarWidget;
|
||||
use crate::widget::RenderConfig;
|
||||
use crate::MAX_LABEL_WIDTH;
|
||||
use crate::WIDGET_SPACING;
|
||||
use eframe::egui::text::LayoutJob;
|
||||
@@ -78,7 +79,7 @@ impl Media {
|
||||
}
|
||||
|
||||
impl BarWidget for Media {
|
||||
fn render(&mut self, ctx: &Context, ui: &mut Ui) {
|
||||
fn render(&mut self, ctx: &Context, ui: &mut Ui, config: RenderConfig) {
|
||||
if self.enable {
|
||||
let output = self.output();
|
||||
if !output.is_empty() {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use crate::config::LabelPrefix;
|
||||
use crate::widget::BarWidget;
|
||||
use crate::widget::RenderConfig;
|
||||
use crate::WIDGET_SPACING;
|
||||
use eframe::egui::text::LayoutJob;
|
||||
use eframe::egui::Context;
|
||||
@@ -73,7 +74,7 @@ impl Memory {
|
||||
}
|
||||
|
||||
impl BarWidget for Memory {
|
||||
fn render(&mut self, ctx: &Context, ui: &mut Ui) {
|
||||
fn render(&mut self, ctx: &Context, ui: &mut Ui, config: RenderConfig) {
|
||||
if self.enable {
|
||||
let output = self.output();
|
||||
if !output.is_empty() {
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
use crate::config::LabelPrefix;
|
||||
use crate::widget::BarWidget;
|
||||
use crate::widget::RenderConfig;
|
||||
use crate::WIDGET_SPACING;
|
||||
use eframe::egui::text::LayoutJob;
|
||||
use eframe::egui::Context;
|
||||
use eframe::egui::FontId;
|
||||
use eframe::egui::Frame;
|
||||
use eframe::egui::Label;
|
||||
use eframe::egui::Margin;
|
||||
use eframe::egui::Rounding;
|
||||
use eframe::egui::Sense;
|
||||
use eframe::egui::TextFormat;
|
||||
use eframe::egui::TextStyle;
|
||||
@@ -317,10 +321,18 @@ impl Network {
|
||||
}
|
||||
|
||||
impl BarWidget for Network {
|
||||
fn render(&mut self, ctx: &Context, ui: &mut Ui) {
|
||||
fn render(&mut self, ctx: &Context, ui: &mut Ui, config: RenderConfig) {
|
||||
if self.show_total_data_transmitted {
|
||||
for output in self.total_data_transmitted() {
|
||||
ui.add(Label::new(output).selectable(false));
|
||||
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, |ui| {
|
||||
ui.add(Label::new(output).selectable(false));
|
||||
});
|
||||
}
|
||||
|
||||
ui.add_space(WIDGET_SPACING);
|
||||
@@ -328,7 +340,15 @@ impl BarWidget for Network {
|
||||
|
||||
if self.show_network_activity {
|
||||
for output in self.network_activity() {
|
||||
ui.add(Label::new(output).selectable(false));
|
||||
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, |ui| {
|
||||
ui.add(Label::new(output).selectable(false));
|
||||
});
|
||||
}
|
||||
|
||||
ui.add_space(WIDGET_SPACING);
|
||||
@@ -367,18 +387,27 @@ impl BarWidget for Network {
|
||||
TextFormat::simple(font_id, ctx.style().visuals.text_color()),
|
||||
);
|
||||
|
||||
if ui
|
||||
.add(
|
||||
Label::new(layout_job)
|
||||
.selectable(false)
|
||||
.sense(Sense::click()),
|
||||
)
|
||||
.clicked()
|
||||
{
|
||||
if let Err(error) = Command::new("cmd.exe").args(["/C", "ncpa"]).spawn() {
|
||||
eprintln!("{}", error)
|
||||
}
|
||||
}
|
||||
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, |ui| {
|
||||
if ui
|
||||
.add(
|
||||
Label::new(layout_job)
|
||||
.selectable(false)
|
||||
.sense(Sense::click()),
|
||||
)
|
||||
.clicked()
|
||||
{
|
||||
if let Err(error) = Command::new("cmd.exe").args(["/C", "ncpa"]).spawn()
|
||||
{
|
||||
eprintln!("{}", error)
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ui.add_space(WIDGET_SPACING);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use crate::config::LabelPrefix;
|
||||
use crate::widget::BarWidget;
|
||||
use crate::widget::RenderConfig;
|
||||
use crate::WIDGET_SPACING;
|
||||
use eframe::egui::text::LayoutJob;
|
||||
use eframe::egui::Context;
|
||||
@@ -79,7 +80,7 @@ impl Storage {
|
||||
}
|
||||
|
||||
impl BarWidget for Storage {
|
||||
fn render(&mut self, ctx: &Context, ui: &mut Ui) {
|
||||
fn render(&mut self, ctx: &Context, ui: &mut Ui, config: RenderConfig) {
|
||||
if self.enable {
|
||||
let font_id = ctx
|
||||
.style()
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
use crate::config::LabelPrefix;
|
||||
use crate::widget::BarWidget;
|
||||
use crate::widget::RenderConfig;
|
||||
use crate::WIDGET_SPACING;
|
||||
use eframe::egui::text::LayoutJob;
|
||||
use eframe::egui::Context;
|
||||
use eframe::egui::FontId;
|
||||
use eframe::egui::Frame;
|
||||
use eframe::egui::Label;
|
||||
use eframe::egui::Margin;
|
||||
use eframe::egui::Rounding;
|
||||
use eframe::egui::Sense;
|
||||
use eframe::egui::TextFormat;
|
||||
use eframe::egui::TextStyle;
|
||||
@@ -77,7 +81,7 @@ impl Time {
|
||||
}
|
||||
|
||||
impl BarWidget for Time {
|
||||
fn render(&mut self, ctx: &Context, ui: &mut Ui) {
|
||||
fn render(&mut self, ctx: &Context, ui: &mut Ui, config: RenderConfig) {
|
||||
if self.enable {
|
||||
let mut output = self.output();
|
||||
if !output.is_empty() {
|
||||
@@ -110,16 +114,24 @@ impl BarWidget for Time {
|
||||
TextFormat::simple(font_id, ctx.style().visuals.text_color()),
|
||||
);
|
||||
|
||||
if ui
|
||||
.add(
|
||||
Label::new(layout_job)
|
||||
.selectable(false)
|
||||
.sense(Sense::click()),
|
||||
)
|
||||
.clicked()
|
||||
{
|
||||
self.format.toggle()
|
||||
}
|
||||
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, |ui| {
|
||||
if ui
|
||||
.add(
|
||||
Label::new(layout_job)
|
||||
.selectable(false)
|
||||
.sense(Sense::click()),
|
||||
)
|
||||
.clicked()
|
||||
{
|
||||
self.format.toggle()
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ui.add_space(WIDGET_SPACING);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use crate::battery::Battery;
|
||||
use crate::battery::BatteryConfig;
|
||||
use crate::config::KomobarConfig;
|
||||
use crate::cpu::Cpu;
|
||||
use crate::cpu::CpuConfig;
|
||||
use crate::date::Date;
|
||||
@@ -21,9 +22,25 @@ use eframe::egui::Ui;
|
||||
use schemars::JsonSchema;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use std::sync::Arc;
|
||||
|
||||
pub trait BarWidget {
|
||||
fn render(&mut self, ctx: &Context, ui: &mut Ui);
|
||||
fn render(&mut self, ctx: &Context, ui: &mut Ui, config: RenderConfig);
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct RenderConfig {
|
||||
group: i32,
|
||||
}
|
||||
|
||||
impl RenderConfig {
|
||||
pub fn from(config: Arc<KomobarConfig>) -> Self {
|
||||
Self { group: 1 }
|
||||
}
|
||||
|
||||
//fn clone(&self) -> Self {
|
||||
// Self { group: self.group }
|
||||
//}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
|
||||
|
||||
Reference in New Issue
Block a user