summaryrefslogtreecommitdiff
path: root/schist_desktop_gui/src/gui/components/navigation/view_navigation.rs
blob: 3f1da18afc1dc3b746846bcf0fbb8392c2a092d8 (plain)
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
use iced::{widget::column, Element};

use crate::traits::Viewable;

use super::{Message, Navigation};

impl<'a, TOption> Viewable<'a, Message<TOption>> for Navigation<TOption>
where
    TOption: Clone + PartialEq + 'a,
    Element<'a, Message<TOption>>: From<&'a TOption>,
{
    fn view(&'a self) -> iced::Element<'a, Message<TOption>> {
        let mut options = Vec::new();
        self.options_before_active
            .iter()
            .map(|option| self.view_navigation_button(&option))
            .for_each(|option| options.push(option));
        if let Some(active_option) = self.active_option.as_ref() {
            options.push(self.view_navigation_button(&active_option));
        }
        self.options_after_active
            .iter()
            .map(|option| self.view_navigation_button(&option))
            .for_each(|option| options.push(option));
        column(options).into()
    }
}