1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//! Types related to defining the notification area.
use std::fmt;
use crate::{AreaId, IconId, ModifyArea, PopupMenu};
/// A notification area.
///
/// This is what occupies space in the notification area.
///
/// It can have an icon, a tooltip, and a popup menu associated with it.
///
/// Note that if an area doesn't have the icon, it will still be added to the
/// notification tray but with an empty space.
pub struct Area {
pub(super) id: AreaId,
pub(super) popup_menu: Option<PopupMenu>,
pub(super) initial: ModifyArea,
}
impl Area {
/// Construct a new empty notification area.
///
/// Without any configuration this will just occupy a blank space in the
/// notification area.
///
/// To set an icon or a popup menu, use the relevant builder methods.
pub(super) fn new(area_id: AreaId) -> Self {
Self {
id: area_id,
popup_menu: None,
initial: ModifyArea::default(),
}
}
/// Get the identifier for this area.
pub fn id(&self) -> AreaId {
self.id
}
/// Set the icon of the notification area.
#[inline]
pub fn icon(&mut self, icon: IconId) -> &mut Self {
self.initial.icon(icon);
self
}
/// Set the tooltip of the notification area.
#[inline]
pub fn tooltip<T>(&mut self, tooltip: T) -> &mut Self
where
T: fmt::Display,
{
self.initial.tooltip(tooltip);
self
}
/// Set that a popup menu should be used and return a handle to populate it.
#[inline]
pub fn popup_menu(&mut self) -> &mut PopupMenu {
if self.popup_menu.is_none() {
self.popup_menu = Some(PopupMenu::new(self.id));
}
self.popup_menu.as_mut().unwrap()
}
}