use super::NotificationItem;
use super::NotificationService;
#[derive(Debug)]
pub struct NotificationState
{
pub(crate) area_width: u16,
pub(crate) items: Vec<NotificationItem>,
}
impl std::default::Default for NotificationState
{
fn default() -> Self
{
Self::new()
}
}
impl NotificationState
{
pub fn new() -> Self
{
Self {
area_width: 40,
items: Vec::new(),
}
}
pub fn with_area_width(
mut self,
width: u16,
) -> Self
{
self.area_width = width;
self
}
pub fn update_from(
&mut self,
service: &mut NotificationService,
)
{
self.items
.append(&mut service.items);
}
pub fn push(
&mut self,
item: NotificationItem,
)
{
self.items
.push(item)
}
pub fn append(
&mut self,
items: &mut Vec<NotificationItem>,
)
{
self.items
.append(items)
}
pub fn tick(&mut self)
{
for item in self
.items
.iter_mut()
{
item.timer -= 1;
}
self.items
.retain_mut(|i| i.timer != 0);
}
}