changes
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
use std::error::Error;
|
||||
|
||||
use common::{BarModule, Endpoint, ModuleEffect, Service, WeatherKind, Wire};
|
||||
use iced::{
|
||||
widget::{container, mouse_area, text},
|
||||
Element, Task,
|
||||
};
|
||||
|
||||
pub struct WeatherModule {
|
||||
text: String,
|
||||
}
|
||||
|
||||
impl Default for WeatherModule {
|
||||
fn default() -> Self {
|
||||
Self { text: "hi".into() }
|
||||
}
|
||||
}
|
||||
|
||||
impl BarModule for WeatherModule {
|
||||
fn id(&self) -> &'static str {
|
||||
"weather"
|
||||
}
|
||||
|
||||
fn view(&self, _window_id: Option<iced::window::Id>) -> Element<'_, Wire> {
|
||||
let me = Endpoint::module(self.id());
|
||||
container(mouse_area(text(&self.text).size(16)).on_press(Wire::module(
|
||||
me,
|
||||
self.id(),
|
||||
WeatherKind::Poke,
|
||||
)))
|
||||
.into()
|
||||
}
|
||||
|
||||
fn update(&mut self, msg: Wire) -> Task<ModuleEffect> {
|
||||
match msg.downcast::<WeatherKind>() {
|
||||
Some(WeatherKind::Poke) => {
|
||||
self.text = "poked".into();
|
||||
Task::none()
|
||||
}
|
||||
None => Task::none(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Route keys this module subscribes to.
|
||||
fn services(&self) -> Vec<Service> {
|
||||
vec![]
|
||||
}
|
||||
|
||||
/// Optional: read `module.weather` from the config table.
|
||||
fn config(&mut self, _config: toml::Table) -> Result<(), Box<dyn Error>> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user