Implement Widget::operate for TextInput

This commit is contained in:
Héctor Ramón Jiménez 2022-07-28 03:53:47 +02:00
parent 80688689aa
commit 52f84e51e9
No known key found for this signature in database
GPG key ID: 140CC052C94F138E
12 changed files with 178 additions and 22 deletions

View file

@ -3,6 +3,7 @@ use crate::layout;
use crate::mouse;
use crate::overlay;
use crate::renderer;
use crate::widget;
use crate::widget::tree::{self, Tree};
use crate::{Clipboard, Layout, Length, Point, Rectangle, Shell, Widget};
@ -248,6 +249,42 @@ where
self.widget.layout(renderer, limits)
}
fn operate(
&self,
tree: &mut Tree,
layout: Layout<'_>,
operation: &mut dyn widget::Operation<B>,
) {
struct MapOperation<'a, B> {
operation: &'a mut dyn widget::Operation<B>,
}
impl<'a, T, B> widget::Operation<T> for MapOperation<'a, B> {
fn container(
&mut self,
id: Option<&widget::Id>,
operate_on_children: &mut dyn FnMut(
&mut dyn widget::Operation<T>,
),
) {
self.operation.container(id, &mut |operation| {
operate_on_children(&mut MapOperation { operation });
});
}
fn focusable(
&mut self,
state: &mut dyn widget::state::Focusable,
id: Option<&widget::Id>,
) {
self.operation.focusable(state, id);
}
}
self.widget
.operate(tree, layout, &mut MapOperation { operation });
}
fn on_event(
&mut self,
tree: &mut Tree,