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

Fix operations for Responsive widget #1615

Merged
merged 2 commits into from
Dec 22, 2022
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions examples/modal/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,11 +325,13 @@ mod modal {
&self,
state: &mut Tree,
layout: Layout<'_>,
renderer: &Renderer,
operation: &mut dyn widget::Operation<Message>,
) {
self.base.as_widget().operate(
&mut state.children[0],
layout,
renderer,
operation,
);
}
Expand Down Expand Up @@ -436,11 +438,13 @@ mod modal {
fn operate(
&mut self,
layout: Layout<'_>,
renderer: &Renderer,
operation: &mut dyn widget::Operation<Message>,
) {
self.content.as_widget().operate(
self.tree,
layout.children().next().unwrap(),
renderer,
operation,
);
}
Expand Down
2 changes: 2 additions & 0 deletions lazy/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ where
&self,
tree: &mut Tree,
layout: Layout<'_>,
renderer: &Renderer,
operation: &mut dyn widget::Operation<Message>,
) {
struct MapOperation<'a, B> {
Expand Down Expand Up @@ -274,6 +275,7 @@ where
element.as_widget().operate(
&mut tree.children[0],
layout,
renderer,
&mut MapOperation { operation },
);
});
Expand Down
2 changes: 2 additions & 0 deletions lazy/src/lazy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,14 @@ where
&self,
tree: &mut Tree,
layout: Layout<'_>,
renderer: &Renderer,
operation: &mut dyn widget::Operation<Message>,
) {
self.with_element(|element| {
element.as_widget().operate(
&mut tree.children[0],
layout,
renderer,
operation,
);
});
Expand Down
25 changes: 24 additions & 1 deletion lazy/src/responsive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use iced_native::layout::{self, Layout};
use iced_native::mouse;
use iced_native::overlay;
use iced_native::renderer;
use iced_native::widget::horizontal_space;
use iced_native::widget::tree::{self, Tree};
use iced_native::widget::{self, horizontal_space};
use iced_native::{
Clipboard, Element, Length, Point, Rectangle, Shell, Size, Widget,
};
Expand Down Expand Up @@ -142,6 +142,29 @@ where
layout::Node::new(limits.max())
}

fn operate(
&self,
tree: &mut Tree,
layout: Layout<'_>,
renderer: &Renderer,
operation: &mut dyn widget::Operation<Message>,
) {
let state = tree.state.downcast_mut::<State>();
let mut content = self.content.borrow_mut();

content.resolve(
&mut state.tree.borrow_mut(),
renderer,
layout,
&self.view,
|tree, renderer, layout, element| {
element
.as_widget()
.operate(tree, layout, renderer, operation);
},
);
}

fn on_event(
&mut self,
tree: &mut Tree,
Expand Down
14 changes: 11 additions & 3 deletions native/src/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ where
&self,
tree: &mut Tree,
layout: Layout<'_>,
renderer: &Renderer,
operation: &mut dyn widget::Operation<B>,
) {
struct MapOperation<'a, B> {
Expand Down Expand Up @@ -334,8 +335,12 @@ where
}
}

self.widget
.operate(tree, layout, &mut MapOperation { operation });
self.widget.operate(
tree,
layout,
renderer,
&mut MapOperation { operation },
);
}

fn on_event(
Expand Down Expand Up @@ -473,9 +478,12 @@ where
&self,
state: &mut Tree,
layout: Layout<'_>,
renderer: &Renderer,
operation: &mut dyn widget::Operation<Message>,
) {
self.element.widget.operate(state, layout, operation)
self.element
.widget
.operate(state, layout, renderer, operation)
}

fn on_event(
Expand Down
1 change: 1 addition & 0 deletions native/src/overlay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ where
fn operate(
&mut self,
_layout: Layout<'_>,
_renderer: &Renderer,
_operation: &mut dyn widget::Operation<Message>,
) {
}
Expand Down
6 changes: 4 additions & 2 deletions native/src/overlay/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,10 @@ where
pub fn operate(
&mut self,
layout: Layout<'_>,
renderer: &Renderer,
operation: &mut dyn widget::Operation<Message>,
) {
self.overlay.operate(layout, operation);
self.overlay.operate(layout, renderer, operation);
}
}

Expand Down Expand Up @@ -144,6 +145,7 @@ where
fn operate(
&mut self,
layout: Layout<'_>,
renderer: &Renderer,
operation: &mut dyn widget::Operation<B>,
) {
struct MapOperation<'a, B> {
Expand Down Expand Up @@ -189,7 +191,7 @@ where
}

self.content
.operate(layout, &mut MapOperation { operation });
.operate(layout, renderer, &mut MapOperation { operation });
}

fn on_event(
Expand Down
2 changes: 2 additions & 0 deletions native/src/user_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,7 @@ where
self.root.as_widget().operate(
&mut self.state,
Layout::new(&self.base),
renderer,
operation,
);

Expand All @@ -507,6 +508,7 @@ where

overlay.operate(
Layout::new(self.overlay.as_ref().unwrap()),
renderer,
operation,
);
}
Expand Down
1 change: 1 addition & 0 deletions native/src/widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ where
&self,
_state: &mut Tree,
_layout: Layout<'_>,
_renderer: &Renderer,
_operation: &mut dyn Operation<Message>,
) {
}
Expand Down
2 changes: 2 additions & 0 deletions native/src/widget/button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,14 @@ where
&self,
tree: &mut Tree,
layout: Layout<'_>,
renderer: &Renderer,
operation: &mut dyn Operation<Message>,
) {
operation.container(None, &mut |operation| {
self.content.as_widget().operate(
&mut tree.children[0],
layout.children().next().unwrap(),
renderer,
operation,
);
});
Expand Down
5 changes: 4 additions & 1 deletion native/src/widget/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ where
&self,
tree: &mut Tree,
layout: Layout<'_>,
renderer: &Renderer,
operation: &mut dyn Operation<Message>,
) {
operation.container(None, &mut |operation| {
Expand All @@ -155,7 +156,9 @@ where
.zip(&mut tree.children)
.zip(layout.children())
.for_each(|((child, state), layout)| {
child.as_widget().operate(state, layout, operation);
child
.as_widget()
.operate(state, layout, renderer, operation);
})
});
}
Expand Down
2 changes: 2 additions & 0 deletions native/src/widget/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,14 @@ where
&self,
tree: &mut Tree,
layout: Layout<'_>,
renderer: &Renderer,
operation: &mut dyn Operation<Message>,
) {
operation.container(None, &mut |operation| {
self.content.as_widget().operate(
&mut tree.children[0],
layout.children().next().unwrap(),
renderer,
operation,
);
});
Expand Down
3 changes: 2 additions & 1 deletion native/src/widget/pane_grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ where
&self,
tree: &mut Tree,
layout: Layout<'_>,
renderer: &Renderer,
operation: &mut dyn widget::Operation<Message>,
) {
operation.container(None, &mut |operation| {
Expand All @@ -302,7 +303,7 @@ where
.zip(&mut tree.children)
.zip(layout.children())
.for_each(|(((_pane, content), state), layout)| {
content.operate(state, layout, operation);
content.operate(state, layout, renderer, operation);
})
});
}
Expand Down
3 changes: 3 additions & 0 deletions native/src/widget/pane_grid/content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ where
&self,
tree: &mut Tree,
layout: Layout<'_>,
renderer: &Renderer,
operation: &mut dyn widget::Operation<Message>,
) {
let body_layout = if let Some(title_bar) = &self.title_bar {
Expand All @@ -195,6 +196,7 @@ where
title_bar.operate(
&mut tree.children[1],
children.next().unwrap(),
renderer,
operation,
);

Expand All @@ -206,6 +208,7 @@ where
self.body.as_widget().operate(
&mut tree.children[0],
body_layout,
renderer,
operation,
);
}
Expand Down
3 changes: 3 additions & 0 deletions native/src/widget/pane_grid/title_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ where
&self,
tree: &mut Tree,
layout: Layout<'_>,
renderer: &Renderer,
operation: &mut dyn widget::Operation<Message>,
) {
let mut children = layout.children();
Expand All @@ -282,6 +283,7 @@ where
controls.as_widget().operate(
&mut tree.children[1],
controls_layout,
renderer,
operation,
)
};
Expand All @@ -290,6 +292,7 @@ where
self.content.as_widget().operate(
&mut tree.children[0],
title_layout,
renderer,
operation,
)
}
Expand Down
5 changes: 4 additions & 1 deletion native/src/widget/row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ where
&self,
tree: &mut Tree,
layout: Layout<'_>,
renderer: &Renderer,
operation: &mut dyn Operation<Message>,
) {
operation.container(None, &mut |operation| {
Expand All @@ -142,7 +143,9 @@ where
.zip(&mut tree.children)
.zip(layout.children())
.for_each(|((child, state), layout)| {
child.as_widget().operate(state, layout, operation);
child
.as_widget()
.operate(state, layout, renderer, operation);
})
});
}
Expand Down
2 changes: 2 additions & 0 deletions native/src/widget/scrollable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ where
&self,
tree: &mut Tree,
layout: Layout<'_>,
renderer: &Renderer,
operation: &mut dyn Operation<Message>,
) {
let state = tree.state.downcast_mut::<State>();
Expand All @@ -174,6 +175,7 @@ where
self.content.as_widget().operate(
&mut tree.children[0],
layout.children().next().unwrap(),
renderer,
operation,
);
});
Expand Down
1 change: 1 addition & 0 deletions native/src/widget/text_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ where
&self,
tree: &mut Tree,
_layout: Layout<'_>,
_renderer: &Renderer,
operation: &mut dyn Operation<Message>,
) {
let state = tree.state.downcast_mut::<State>();
Expand Down