Allow segmented buttons to be indented
This commit is contained in:
parent
bad4400779
commit
2df8cb8862
3 changed files with 40 additions and 0 deletions
|
|
@ -104,6 +104,12 @@ where
|
|||
self.id
|
||||
}
|
||||
|
||||
#[allow(clippy::must_use_candidate, clippy::return_self_not_must_use)]
|
||||
pub fn indent(self, indent: u16) -> Self {
|
||||
self.model.indent_set(self.id, indent);
|
||||
self
|
||||
}
|
||||
|
||||
/// Define the position of the item.
|
||||
#[allow(clippy::must_use_candidate, clippy::return_self_not_must_use)]
|
||||
pub fn position(self, position: u16) -> Self {
|
||||
|
|
|
|||
|
|
@ -61,6 +61,9 @@ pub struct Model<SelectionMode: Default> {
|
|||
/// Icons optionally-defined for each item.
|
||||
pub(super) icons: SecondaryMap<Entity, Icon>,
|
||||
|
||||
/// Indent optionally-defined for each item.
|
||||
pub(super) indents: SecondaryMap<Entity, u16>,
|
||||
|
||||
/// Text optionally-defined for each item.
|
||||
pub(super) text: SecondaryMap<Entity, Cow<'static, str>>,
|
||||
|
||||
|
|
@ -293,6 +296,22 @@ where
|
|||
self.order.iter().copied()
|
||||
}
|
||||
|
||||
pub fn indent(&self, id: Entity) -> Option<u16> {
|
||||
self.indents.get(id).map(|indent| *indent)
|
||||
}
|
||||
|
||||
pub fn indent_set(&mut self, id: Entity, indent: u16) -> Option<u16> {
|
||||
if !self.contains_item(id) {
|
||||
return None;
|
||||
}
|
||||
|
||||
self.indents.insert(id, indent)
|
||||
}
|
||||
|
||||
pub fn indent_remove(&mut self, id: Entity) -> Option<u16> {
|
||||
self.indents.remove(id)
|
||||
}
|
||||
|
||||
/// The position of the item in the model.
|
||||
///
|
||||
/// ```ignore
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue