agg_gui/widgets/text_field/binding.rs
1use super::*;
2
3impl TextField {
4 /// Bind the field to external text state.
5 ///
6 /// `layout` picks up external writes (e.g. a Clear button) and
7 /// `on_change` writes user edits back into the cell.
8 pub fn with_text_cell(mut self, cell: Rc<RefCell<String>>) -> Self {
9 let text = cell.borrow().clone();
10 self.set_text(text);
11 self.text_cell = Some(cell);
12 self
13 }
14
15 pub(crate) fn sync_from_text_cell(&mut self) {
16 let Some(cell) = &self.text_cell else {
17 return;
18 };
19 let external = cell.borrow().clone();
20 if external != self.edit.borrow().text {
21 self.set_text(external);
22 }
23 }
24}