[collapsing header] add id_source to builder
This commit is contained in:
parent
916e667aa2
commit
5c2a0a59ac
1 changed files with 14 additions and 1 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
use std::hash::Hash;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
layout::Direction,
|
layout::Direction,
|
||||||
paint::{LineStyle, PaintCmd, Path, TextStyle},
|
paint::{LineStyle, PaintCmd, Path, TextStyle},
|
||||||
|
@ -142,6 +144,7 @@ impl State {
|
||||||
pub struct CollapsingHeader {
|
pub struct CollapsingHeader {
|
||||||
label: Label,
|
label: Label,
|
||||||
default_open: bool,
|
default_open: bool,
|
||||||
|
id_source: Option<Id>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CollapsingHeader {
|
impl CollapsingHeader {
|
||||||
|
@ -151,6 +154,7 @@ impl CollapsingHeader {
|
||||||
.text_style(TextStyle::Button)
|
.text_style(TextStyle::Button)
|
||||||
.multiline(false),
|
.multiline(false),
|
||||||
default_open: false,
|
default_open: false,
|
||||||
|
id_source : None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,6 +162,13 @@ impl CollapsingHeader {
|
||||||
self.default_open = open;
|
self.default_open = open;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Explicitly set the source of the `Id` of this widget, instead of using title label.
|
||||||
|
/// This is useful if the title label is dynamics.
|
||||||
|
pub fn id_source(mut self, id_source: impl Hash) -> Self {
|
||||||
|
self.id_source = Some(Id::new(id_source));
|
||||||
|
self
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Prepared {
|
struct Prepared {
|
||||||
|
@ -174,12 +185,14 @@ impl CollapsingHeader {
|
||||||
let Self {
|
let Self {
|
||||||
label,
|
label,
|
||||||
default_open,
|
default_open,
|
||||||
|
id_source,
|
||||||
} = self;
|
} = self;
|
||||||
|
|
||||||
// TODO: horizontal layout, with icon and text as labels. Insert background behind using Frame.
|
// TODO: horizontal layout, with icon and text as labels. Insert background behind using Frame.
|
||||||
|
|
||||||
let title = label.text();
|
let title = label.text();
|
||||||
let id = ui.make_unique_child_id(title);
|
let id_source = id_source.unwrap_or_else(|| Id::new(title));
|
||||||
|
let id = ui.make_unique_child_id(id_source);
|
||||||
|
|
||||||
let available = ui.available_finite();
|
let available = ui.available_finite();
|
||||||
let text_pos = available.min + vec2(ui.style().indent, 0.0);
|
let text_pos = available.min + vec2(ui.style().indent, 0.0);
|
||||||
|
|
Loading…
Reference in a new issue