libnotcurses_sys/widgets/menu/methods/
options.rs

1use crate::{
2    widgets::{NcMenuOptions, NcMenuSection},
3    NcChannels,
4};
5
6#[allow(unused_imports)] // for doc comments
7use crate::widgets::NcMenu;
8
9/// # `NcMenuOptions` constructors
10impl NcMenuOptions {
11    /// New NcMenuOptions for [`NcMenu`].
12    ///
13    /// `sections` must contain at least 1 [`NcMenuSection`].
14    pub fn new(sections: &mut [NcMenuSection]) -> Self {
15        Self::with_all_args(sections, 0, 0, 0)
16    }
17
18    /// New NcMenuOptions for [`NcMenu`], with all args.
19    ///
20    /// `sections` must contain at least 1 [`NcMenuSection`].
21    pub fn with_all_args<CHS1, CHS2>(
22        sections: &mut [NcMenuSection],
23        style_header: CHS1,
24        style_sections: CHS2,
25        flags: u64,
26    ) -> Self
27    where
28        CHS1: Into<NcChannels>,
29        CHS2: Into<NcChannels>,
30    {
31        assert![!sections.is_empty()];
32        Self {
33            // array of 'sectioncount' `MenuSection`s
34            sections: sections.as_mut_ptr(),
35
36            //
37            sectioncount: sections.len() as i32,
38
39            // styling for header
40            headerchannels: style_header.into().into(),
41
42            // styling for sections
43            sectionchannels: style_sections.into().into(),
44
45            // flag word of NCMENU_OPTION_*
46            flags,
47        }
48    }
49}
50
51/// # `NcMenuOptions` methods
52// RETHINK
53impl NcMenuOptions {
54    /// Returns the styling for the header.
55    ///
56    /// *(No equivalent C style function)*
57    pub fn header_channels(&self) -> NcChannels {
58        self.headerchannels.into()
59    }
60
61    /// Returns a mutable reference of the styling for the sections.
62    ///
63    /// *(No equivalent C style function)*
64    pub fn header_channels_mut(&mut self) -> &mut crate::c_api::NcChannels_u64 {
65        &mut self.headerchannels
66    }
67
68    /// Returns the styling for the sections.
69    ///
70    /// *(No equivalent C style function)*
71    pub fn section_channels(&self) -> NcChannels {
72        self.sectionchannels.into()
73    }
74
75    /// Returns a mutable reference of the styling for the sections.
76    ///
77    /// *(No equivalent C style function)*
78    pub fn section_channels_mut(&mut self) -> &mut crate::c_api::NcChannels_u64 {
79        &mut self.sectionchannels
80    }
81}