popup fixes and clock gets nicer popup

This commit is contained in:
2026-09-15 11:46:16 +01:00
parent fb6b03b369
commit ac70a9133a
7 changed files with 87 additions and 63 deletions
+16 -21
View File
@@ -3,10 +3,12 @@
//! service to switch which kind it publishes; right-click opens a popup.
use iced::widget::{container, mouse_area, text};
use iced::{Element, Padding, Task};
use iced::Length::Fill;
use iced::{alignment, Element, Padding, Task};
use common::{
pill, BarModule, ClockKind, ClockMsg, ClockPayload, Endpoint, ModuleEffect, Service, Wire,
pill, BarModule, ClockKind, ClockMsg, ClockPayload, Endpoint, ModuleEffect, PopupSettings,
Service, Wire,
};
use serde::Deserialize;
use toml::Table;
@@ -82,7 +84,12 @@ impl BarModule for Clock {
let me = Endpoint::module(self.id());
match window_id {
// Popup surface: current time in large text.
Some(_) => container(text(&self.value).size(56)).padding(20).into(),
Some(_) => container(text(&self.value).size(56))
.align_x(alignment::Horizontal::Center)
.align_y(alignment::Vertical::Center)
.padding(20)
.width(Fill)
.into(),
// Bar surface: clickable time. Container carries the module id
// so the popup can anchor to these bounds.
None => container(
@@ -125,10 +132,12 @@ impl BarModule for Clock {
want,
)))
}
Some(ClockMsg::OpenPopup) => Task::done(ModuleEffect::RequestPopup(
self.id().to_string(),
self.id().to_string(),
)),
Some(ClockMsg::OpenPopup) => Task::done(ModuleEffect::RequestPopup(PopupSettings {
// name: "barbar".into(),
module_id: self.id().into(),
element_id: "clock".into(),
gap: 8,
})),
None => Task::none(),
}
}
@@ -141,17 +150,3 @@ impl BarModule for Clock {
Some((POPUP_W, POPUP_H))
}
}
#[cfg(test)]
mod tests {
use super::*;
/// Regression: `new(None)` used to call `default()`, which called
/// `new(None)` — infinite recursion (hard stack overflow) whenever the
/// clock config was absent or failed to parse.
#[test]
fn no_config_terminates() {
assert!(!Clock::new(None).show_seconds);
assert!(!Clock::default().show_seconds);
}
}