GPU-accelerated UI toolkit (Vulkan)
git clone https://git.lucas.co/cce-ui.git
Added update_on_type to TextBox to support real-time character-by-character search updates in TreeList
src/widget/container/treelist.rs | 2 +-
src/widget/input/text_box.rs | 13 +++++++++++++
2 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/src/widget/container/treelist.rs b/src/widget/container/treelist.rs
index a240fd4..c877c75 100644
--- a/src/widget/container/treelist.rs
+++ b/src/widget/container/treelist.rs
@@ -188,7 +188,7 @@ impl TreeList {
Self {
base: Widget::new(),
scroll_box,
- search_box: TextBox::new(String::new()).with_placeholder("Search..."),
+ search_box: TextBox::new(String::new()).with_placeholder("Search...").with_update_on_type(true),
flat_keys: Vec::new(),
annotations: Vec::new(),
collapsed_sections: HashSet::new(),
diff --git a/src/widget/input/text_box.rs b/src/widget/input/text_box.rs
index 4099d6a..deba499 100644
--- a/src/widget/input/text_box.rs
+++ b/src/widget/input/text_box.rs
@@ -45,6 +45,7 @@ pub struct TextBox {
pub cursor_x_offset: f32,
pub glyph_positions: Vec<f32>,
pub total_text_width: f32,
+ pub update_on_type: bool,
}
impl TextBox {
@@ -83,9 +84,15 @@ impl TextBox {
cursor_x_offset: 0.0,
glyph_positions: Vec::new(),
total_text_width: 0.0,
+ update_on_type: false,
}
}
+ pub fn with_update_on_type(mut self, update: bool) -> Self {
+ self.update_on_type = update;
+ self
+ }
+
pub fn with_multiline(mut self, multiline: bool) -> Self {
self.multiline = multiline;
self
@@ -273,6 +280,12 @@ impl TextBox {
}
pub fn take_change(&mut self) -> bool {
+ if self.update_on_type {
+ if self.text != self.edit_buffer {
+ self.text = self.edit_buffer.clone();
+ self.just_changed = true;
+ }
+ }
let changed = self.just_changed;
self.just_changed = false;
changed