Skip to content

Commit 745d1ee

Browse files
committed
Explain layout invalidation in Component
1 parent 9c71f8a commit 745d1ee

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

widget/src/component.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,18 @@ where
291291

292292
let new_size_hint = self.component.size_hint();
293293

294+
// We must invalidate application layout in 3 instances:
295+
//
296+
// 1. The size hint of the component changes. Other widgets
297+
// may change layout behavior.
298+
//
299+
// 2. The size hint of the component is shrink for any axis
300+
// and the component has changed size. The new size may
301+
// push other widgets around.
302+
//
303+
// 3. The overlay status of the component changes. The
304+
// runtime will only call `overlay` again if the layout
305+
// is invalidated.
294306
if new_size_hint != self.size_hint {
295307
self.size_hint = new_size_hint;
296308
shell.invalidate_layout();
@@ -407,7 +419,7 @@ where
407419
layout: Layout<'b>,
408420
renderer: &Renderer,
409421
viewport: &Rectangle,
410-
translation: core::Vector,
422+
translation: Vector,
411423
) -> Option<overlay::Element<'b, Message, Theme, Renderer>> {
412424
let overlay = self.view.as_widget_mut().overlay(
413425
&mut tree.children[0],
@@ -422,11 +434,9 @@ where
422434

423435
self.has_overlay = true;
424436

425-
let state = tree.state.downcast_mut();
426-
427437
Some(overlay::Element::new(Box::new(Overlay {
428438
component: &mut self.component,
429-
state,
439+
state: tree.state.downcast_mut(),
430440
raw: overlay,
431441
is_outdated: &mut self.is_outdated,
432442
})))

0 commit comments

Comments
 (0)