feat(bar): allow right side widget ordering

This commit is contained in:
LGUG2Z
2024-09-07 12:54:39 -07:00
parent fdc7706d23
commit 025162769b
9 changed files with 260 additions and 197 deletions
+38 -6
View File
@@ -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);
}
}
}