pub trait MinSize {
// Required method
fn min_size(&self, density: Density) -> Size;
}Expand description
A widget that can report the smallest size its content and Density allow, before ever
being rendered.
This is a different question from Measure::height_for: height_for answers “how tall are
you, given this width” (content wrapped into a fixed width); min_size answers “how small
can you be at all” (a floor driven by both content and the Density a caller is targeting).
Conflating the two into one trait/method would force every Measure impl to also take a
Density it doesn’t need, and every MinSize impl to accept a width it can’t use to answer
“how small can you get”. Kept separate on purpose; a widget can implement either, both, or
neither.
Interactive widgets (Button, Tabs, Scrollbar, TextInput) are the intended
implementors: Density::min_target_size exists specifically so a caller sizing a
clickable/tappable control doesn’t have to invent its own touch-target floor, and min_size
is how a widget applies that floor to its own content.
§Examples
use retroglyph_core::grid::Size;
use retroglyph_ui::interact::Density;
use retroglyph_ui::widget::MinSize;
struct FixedSize(Size);
impl MinSize for FixedSize {
fn min_size(&self, density: Density) -> Size {
self.0.max(density.min_target_size())
}
}
let small = FixedSize(Size::new(1, 1));
assert_eq!(small.min_size(Density::Mouse), Density::Mouse.min_target_size());Required Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".