From 7bcaa341b8685ba411d206c1a89dc3ca77aa71bb Mon Sep 17 00:00:00 2001 From: Max Verevkin Date: Fri, 1 Apr 2022 21:50:19 +0300 Subject: initial commit --- src/tags.rs | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/tags.rs (limited to 'src/tags.rs') diff --git a/src/tags.rs b/src/tags.rs new file mode 100644 index 0000000..8114a74 --- /dev/null +++ b/src/tags.rs @@ -0,0 +1,44 @@ +use crate::text::{Attributes, ComputedText, Text}; +use cairo::Context; +use pango::FontDescription; +use pangocairo::{cairo, pango}; + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum TagState { + Focused, + Inactive, + Urgent, +} + +#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)] +pub struct TagsInfo { + pub focused: u32, + pub urgent: u32, +} + +impl TagsInfo { + pub fn get_state(self, tag: usize) -> TagState { + if self.urgent >> tag & 1 == 1 { + TagState::Urgent + } else if self.focused >> tag & 1 == 1 { + TagState::Focused + } else { + TagState::Inactive + } + } +} + +pub fn compute_tag_label(label: String, font: FontDescription, context: &Context) -> ComputedText { + let text = Text { + attr: Attributes { + font, + padding_left: 25.0, + padding_right: 25.0, + min_width: None, + align: Default::default(), + markup: false, + }, + text: label, + }; + text.compute(context) +} -- cgit v1.3.1