Introduce Widget::size_hint and fix further layout inconsistencies

This commit is contained in:
Héctor Ramón Jiménez 2024-01-05 17:24:43 +01:00
parent 0322e820eb
commit 22226394f7
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
17 changed files with 210 additions and 123 deletions

View file

@ -15,7 +15,7 @@ use crate::layout::{self, Layout};
use crate::mouse;
use crate::overlay;
use crate::renderer;
use crate::{Clipboard, Length, Rectangle, Shell};
use crate::{Clipboard, Length, Rectangle, Shell, Size};
/// A component that displays information and allows interaction.
///
@ -49,6 +49,14 @@ where
/// Returns the height of the [`Widget`].
fn height(&self) -> Length;
/// Returns a [`Size`] hint for laying out the [`Widget`].
///
/// This hint may be used by some widget containers to adjust their sizing strategy
/// during construction.
fn size_hint(&self) -> Size<Length> {
Size::new(self.width(), self.height())
}
/// Returns the [`layout::Node`] of the [`Widget`].
///
/// This [`layout::Node`] is used by the runtime to compute the [`Layout`] of the