1
0
Fork 0
mirror of https://github.com/Zedfrigg/ironbar.git synced 2025-07-01 18:51:04 +02:00

feat: new label module

Takes a text label, with the ability to include embedded scripts.

Resolves #80.
This commit is contained in:
Jake Stanger 2023-04-07 14:27:16 +01:00
parent 55c06c4766
commit 6c622864b3
No known key found for this signature in database
GPG key ID: C51FC8F9CB0BEA61
11 changed files with 153 additions and 1 deletions

62
src/modules/label.rs Normal file
View file

@ -0,0 +1,62 @@
use crate::config::CommonConfig;
use crate::dynamic_string::DynamicString;
use crate::modules::{Module, ModuleInfo, ModuleUpdateEvent, ModuleWidget, WidgetContext};
use crate::try_send;
use color_eyre::Result;
use glib::Continue;
use gtk::prelude::*;
use gtk::Label;
use serde::Deserialize;
use tokio::sync::mpsc;
#[derive(Debug, Deserialize, Clone)]
pub struct LabelModule {
label: String,
#[serde(flatten)]
pub common: Option<CommonConfig>,
}
impl Module<Label> for LabelModule {
type SendMessage = String;
type ReceiveMessage = ();
fn name() -> &'static str {
"label"
}
fn spawn_controller(
&self,
_info: &ModuleInfo,
tx: mpsc::Sender<ModuleUpdateEvent<Self::SendMessage>>,
_rx: mpsc::Receiver<Self::ReceiveMessage>,
) -> Result<()> {
DynamicString::new(&self.label, move |string| {
try_send!(tx, ModuleUpdateEvent::Update(string));
Continue(true)
});
Ok(())
}
fn into_widget(
self,
context: WidgetContext<Self::SendMessage, Self::ReceiveMessage>,
_info: &ModuleInfo,
) -> Result<ModuleWidget<Label>> {
let label = Label::new(None);
{
let label = label.clone();
context.widget_rx.attach(None, move |string| {
label.set_label(&string);
Continue(true)
});
}
Ok(ModuleWidget {
widget: label,
popup: None,
})
}
}

View file

@ -10,6 +10,7 @@ pub mod clipboard;
pub mod clock;
pub mod custom;
pub mod focused;
pub mod label;
pub mod launcher;
#[cfg(feature = "music")]
pub mod music;