mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-09-15 22:31:52 +02:00
feat(bar): allow right side widget ordering
This commit is contained in:
@@ -1,4 +1,22 @@
|
||||
use crate::widget::BarWidget;
|
||||
use eframe::egui::Label;
|
||||
use eframe::egui::Sense;
|
||||
use eframe::egui::Ui;
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub struct TimeConfig {
|
||||
pub enable: bool,
|
||||
pub format: TimeFormat,
|
||||
}
|
||||
|
||||
impl From<TimeConfig> for Time {
|
||||
fn from(value: TimeConfig) -> Self {
|
||||
Self {
|
||||
enable: value.enable,
|
||||
format: value.format,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub enum TimeFormat {
|
||||
@@ -28,16 +46,30 @@ pub struct Time {
|
||||
pub format: TimeFormat,
|
||||
}
|
||||
|
||||
impl Time {
|
||||
pub fn new(enable: bool, format: TimeFormat) -> Self {
|
||||
Self { enable, format }
|
||||
}
|
||||
}
|
||||
|
||||
impl BarWidget for Time {
|
||||
fn output(&mut self) -> Vec<String> {
|
||||
vec![chrono::Local::now()
|
||||
.format(&self.format.fmt_string())
|
||||
.to_string()]
|
||||
}
|
||||
|
||||
fn render(&mut self, ui: &mut Ui) {
|
||||
if self.enable {
|
||||
for output in self.output() {
|
||||
if ui
|
||||
.add(
|
||||
Label::new(format!("🕐 {}", output))
|
||||
.selectable(false)
|
||||
.sense(Sense::click()),
|
||||
)
|
||||
.clicked()
|
||||
{
|
||||
self.format.toggle()
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: make spacing configurable
|
||||
ui.add_space(10.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user