Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Impl operate for Component widget #1402

Merged
merged 1 commit into from
Aug 9, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions lazy/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use iced_native::layout::{self, Layout};
use iced_native::mouse;
use iced_native::overlay;
use iced_native::renderer;
use iced_native::widget;
use iced_native::widget::tree::{self, Tree};
use iced_native::{
Clipboard, Element, Length, Point, Rectangle, Shell, Size, Widget,
Expand Down Expand Up @@ -229,6 +230,47 @@ where
event_status
}

fn operate(
&self,
tree: &mut Tree,
layout: Layout<'_>,
operation: &mut dyn widget::Operation<Message>,
) {
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::operation::Focusable,
id: Option<&widget::Id>,
) {
self.operation.focusable(state, id);
}
}

self.with_element(|element| {
element.as_widget().operate(
&mut tree.children[0],
layout,
&mut MapOperation { operation },
);
});
}

fn draw(
&self,
tree: &Tree,
Expand Down