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

Migrate layout pass #529

Merged
merged 5 commits into from
Sep 9, 2024
Merged

Migrate layout pass #529

merged 5 commits into from
Sep 9, 2024

Conversation

PoignardAzur
Copy link
Contributor

No description provided.

masonry/src/passes/layout.rs Outdated Show resolved Hide resolved
masonry/src/passes/layout.rs Show resolved Hide resolved
@@ -504,26 +505,12 @@ impl<W: Widget> WidgetPod<W> {
///
/// [`layout`]: Widget::layout
pub fn layout(&mut self, parent_ctx: &mut LayoutCtx, bc: &BoxConstraints) -> Size {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this still here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To keep the diff small. We can change all the widgets in a follow-up PR. I'll include a comment to that effect.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of the widgets already appear to be translated in this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, you're right. Well I removed the WidgetPod method and converted the last users.

/// their [`layout`] method.
///
/// [`layout`]: Widget::layout
pub fn run_layout<W: Widget>(&mut self, child: &mut WidgetPod<W>, bc: &BoxConstraints) -> Size {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should ensure that this method is clearly pointed to in the docs for Widget::layout.

I'd also encourage moving this method higher up in this impl block, because it is among the most important methods on LayoutCtx

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@PoignardAzur PoignardAzur marked this pull request as ready for review August 30, 2024 12:17

// TODO - negative rects?
/// Return `true` if all of `smaller` is within `larger`.
fn rect_contains(larger: &Rect, smaller: &Rect) -> bool {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parent_ctx: &mut LayoutCtx<'_>,
pod: &mut WidgetPod<W>,
bc: &BoxConstraints,
) -> bool {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The semantics of this bool return value are very unclear. I can see through digging through the code it's called_widget, i.e. whether the widget's method was actually called and therefore whether the checks need to be ran?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this pattern pulled more weight when every WidgetPod method used it and call_widget_method_with_checks was used everywhere. We'll probably refactor it away soon. In the meantime, I added a comment for clarity.

state.needs_compose = true;
state.is_expecting_place_child_call = true;
// TODO - Not everything that has been re-laid out needs to be repainted.
state.needs_paint = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why no request_paint/request_compose?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I wrote this code before I renamed those flags. Will fix.

mouse_pos: parent_ctx.mouse_pos,
};

widget.layout(&mut inner_ctx, bc)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this be the case to evaluate a potentially cached layout result? I guess that would be what request_layout would be needed for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True. I'm adding a comment and leaving it for a future PR.


state.local_paint_rect = state
.local_paint_rect
.union(new_size.to_rect() + state.paint_insets);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a huge fan of using Add for Insets, but that's a Kurbo thing - this is an idiomatic usage thereof


fn log_layout_issues(type_name: &str, size: Size) {
if size.width.is_infinite() {
warn!("Widget `{type_name}` has an infinite width.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we log the id here as well?

}
}

pub(crate) fn run_layout_on<W: Widget>(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should have a small doc comment here. E.g.:

Suggested change
pub(crate) fn run_layout_on<W: Widget>(
/// Run [`Widget::layout`] method on the widget contained in `pod`.
/// This will be called by [`LayoutCtx::run_layout`], which is itself called in the parent widget's `layout`.
pub(crate) fn run_layout_on<W: Widget>(

@@ -504,26 +505,12 @@ impl<W: Widget> WidgetPod<W> {
///
/// [`layout`]: Widget::layout
pub fn layout(&mut self, parent_ctx: &mut LayoutCtx, bc: &BoxConstraints) -> Size {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of the widgets already appear to be translated in this PR?

@PoignardAzur
Copy link
Contributor Author

Will merge before this evening unless a blocker comes up.

);
}

state.needs_layout = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a little bit of knowledge encoded in this line, so it could be worth having a comment here.

Not going to block on that, though

@PoignardAzur PoignardAzur added this pull request to the merge queue Sep 9, 2024
Merged via the queue into main with commit dcea01a Sep 9, 2024
17 checks passed
@PoignardAzur PoignardAzur deleted the implement_pass_spec_layout branch September 9, 2024 12:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants