[−][src]Struct kas::layout::SizeRules
Widget sizing information
This is the return value of kas::Layout::size_rules
and is used to
describe size and margin requirements for widgets. This type only concerns
size requirements along a single axis.
All units are in pixels. Sizes usually come directly from SizeHandle
or from a fixed quantity multiplied by SizeHandle::scale_factor
.
Sizes
The widget size model is simple: a rectangular box, plus a margin on each
side. Widget sizes are calculated from available space and the SizeRules
;
these rules currently include:
- the minimum size required for correct operation
- the preferred / ideal size
- a
StretchPolicy
Available space is distributed between widgets depending on whether the
space is below the minimum, between the minimum and preferred, or above
the preferred size, with widgets with the highest StretchPolicy
being
prioritised extra space. Usually rows/columns will be stretched to use all
available space, the exception being when none have a policy higher than
StretchPolicy::Fixed
. When expanding a row/column, the highest stretch
policy of all contents will be used.
Margins
Required margin sizes are handled separately for each side of a widget.
Since SizeRules
concerns only one axis, it stores only two margin sizes:
"pre" (left/top) and "post" (right/bottom). These are stored as u16
values
on the assumption that no margin need exceed 65536.
When widgets are placed next to each other, their margins may be combined; e.g. if a widget with margin of 6px is followed by another with margin 2px, the required margin between the two is the maximum, 6px.
Only the layout engine and parent widgets need consider margins (beyond
their specification). For these cases, one needs to be aware that due to
margin-merging behaviour, one cannot simply "add" two SizeRules
. Instead,
when placing one widget next to another, use SizeRules::append
or
SizeRules::appended
; when placing a widget within a frame, use
SizeRules::surrounded_by
. When calculating the size of a sequence of
widgets, one may use the Sum
implementation (this assumes that the
sequence is in left-to-right or top-to-bottom order).
Alignment
SizeRules
concerns calculations of size requirements, which the layout
engine uses to assign each widget a Rect
; it is up to the widget itself
to either fill this rect or align itself within the given space.
See kas::Layout::set_rect
for more information.
For widgets with a stretch policy of StretchPolicy::Fixed
, it is still
possible for layout code to assign a size larger than the preference. It is
up to the widget to align itself within this space: see
kas::Layout::set_rect
and kas::AlignHints
.
Methods
impl SizeRules
[src]
pub const EMPTY: Self
[src]
Empty (zero size) widget
Warning: appending another size to EMPTY
does include margins
even though EMPTY
itself has zero size. However, EMPTY
itself has
zero-size margins, so this only affects appending an EMPTY
with a
non-empty SizeRules
.
pub const fn empty(stretch: StretchPolicy) -> Self
[src]
Empty space with the given stretch policy
See warning on SizeRules::EMPTY
.
pub fn fixed(size: u32, margins: (u16, u16)) -> Self
[src]
A fixed size with given (pre, post)
margins
pub fn extract_fixed(vertical: bool, size: Size, margin: Margins) -> Self
[src]
Construct fixed-size rules from given data
pub fn new(
min: u32,
ideal: u32,
margins: (u16, u16),
stretch: StretchPolicy
) -> Self
[src]
min: u32,
ideal: u32,
margins: (u16, u16),
stretch: StretchPolicy
) -> Self
Construct with custom rules
Region size should meet the given min
-imum size and has a given
ideal
size, plus a given stretch
policy.
Required: ideal >= min
(if not, ideal is clamped to min).
pub fn min_size(self) -> u32
[src]
Get the minimum size
pub fn ideal_size(self) -> u32
[src]
Get the ideal size
pub fn margins(self) -> (u16, u16)
[src]
Get the (pre, post)
margin sizes
pub fn include_margins(&mut self, margins: (u16, u16))
[src]
Set margins to max of own margins and given margins
pub fn max(self, rhs: Self) -> SizeRules
[src]
Use the maximum size of self
and rhs
.
pub fn max_with(&mut self, rhs: Self)
[src]
Set self = self.max(rhs);
pub fn append(&mut self, rhs: SizeRules)
[src]
Append the rules for rhs
to self
This implies that rhs
rules concern an element to the right of or
below self. Note that order matters since margins may be combined.
Note also that appending SizeRules::EMPTY
does include interior
margins (those between EMPTY
and the other rules) within the result.
pub fn appended(self, rhs: SizeRules) -> Self
[src]
Return the rules for self appended by rhs
This implies that rhs
rules concern an element to the right of or
below self. Note that order matters since margins may be combined.
Note also that appending SizeRules::EMPTY
does include interior
margins (those between EMPTY
and the other rules) within the result.
pub fn surrounded_by(self, frame: SizeRules, internal_margins: bool) -> Self
[src]
Return the rules for self surrounded by frame
If internal_margins
are true, then space is allocated for self
's
margins inside the frame; if not, then self
's margins are merged with
the frame's margins.
pub fn sum(range: &[SizeRules]) -> SizeRules
[src]
Return the result of appending all given ranges
pub fn min_sum(range: &[SizeRules]) -> SizeRules
[src]
Return the result of appending all given ranges (min only)
This is a specialised version of sum: only the minimum is calculated
pub fn sub_add(&mut self, x: Self, y: Self)
[src]
Set self to self - x + y
pub fn reduce_min_to(&mut self, min: u32)
[src]
Reduce the minimum size
If min
is greater than the current minimum size, this has no effect.
pub fn distribute_span_over(self, rules: &mut [Self])
[src]
Adjust a sequence of rules
to ensure that the total is at least self
This is used by grids to ensure that cell spans are sufficiently large.
Trait Implementations
impl Clone for SizeRules
[src]
impl Copy for SizeRules
[src]
impl Debug for SizeRules
[src]
impl Default for SizeRules
[src]
impl Eq for SizeRules
[src]
impl PartialEq<SizeRules> for SizeRules
[src]
impl StructuralEq for SizeRules
[src]
impl StructuralPartialEq for SizeRules
[src]
impl<'a> Sum<&'a SizeRules> for SizeRules
[src]
Return the sum over a sequence of rules, assuming these are ordered
Uses SizeRules::appended
on all rules in sequence.
impl Sum<SizeRules> for SizeRules
[src]
Return the sum over a sequence of rules, assuming these are ordered
Uses SizeRules::appended
on all rules in sequence.
Auto Trait Implementations
impl RefUnwindSafe for SizeRules
impl Send for SizeRules
impl Sync for SizeRules
impl Unpin for SizeRules
impl UnwindSafe for SizeRules
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<Src, Scheme> ApproxFrom<Src, Scheme> for Src where
Scheme: ApproxScheme,
[src]
Scheme: ApproxScheme,
type Err = NoError
The error type produced by a failed conversion.
fn approx_from(src: Src) -> Result<Src, <Src as ApproxFrom<Src, Scheme>>::Err>
[src]
impl<Dst, Src, Scheme> ApproxInto<Dst, Scheme> for Src where
Dst: ApproxFrom<Src, Scheme>,
Scheme: ApproxScheme,
[src]
Dst: ApproxFrom<Src, Scheme>,
Scheme: ApproxScheme,
type Err = <Dst as ApproxFrom<Src, Scheme>>::Err
The error type produced by a failed conversion.
fn approx_into(self) -> Result<Dst, <Src as ApproxInto<Dst, Scheme>>::Err>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, Dst> ConvAsUtil<Dst> for T
[src]
fn approx(self) -> Result<Dst, Self::Err> where
Self: ApproxInto<Dst, DefaultApprox>,
[src]
Self: ApproxInto<Dst, DefaultApprox>,
fn approx_by<Scheme>(self) -> Result<Dst, Self::Err> where
Scheme: ApproxScheme,
Self: ApproxInto<Dst, Scheme>,
[src]
Scheme: ApproxScheme,
Self: ApproxInto<Dst, Scheme>,
impl<T> ConvUtil for T
[src]
fn approx_as<Dst>(self) -> Result<Dst, Self::Err> where
Self: ApproxInto<Dst, DefaultApprox>,
[src]
Self: ApproxInto<Dst, DefaultApprox>,
fn approx_as_by<Dst, Scheme>(self) -> Result<Dst, Self::Err> where
Scheme: ApproxScheme,
Self: ApproxInto<Dst, Scheme>,
[src]
Scheme: ApproxScheme,
Self: ApproxInto<Dst, Scheme>,
fn into_as<Dst>(self) -> Dst where
Self: Into<Dst>,
[src]
Self: Into<Dst>,
fn try_as<Dst>(self) -> Result<Dst, Self::Err> where
Self: TryInto<Dst>,
[src]
Self: TryInto<Dst>,
fn value_as<Dst>(self) -> Result<Dst, Self::Err> where
Self: ValueInto<Dst>,
[src]
Self: ValueInto<Dst>,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<Src> TryFrom<Src> for Src
[src]
type Err = NoError
The error type produced by a failed conversion.
fn try_from(src: Src) -> Result<Src, <Src as TryFrom<Src>>::Err>
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<Src, Dst> TryInto<Dst> for Src where
Dst: TryFrom<Src>,
[src]
Dst: TryFrom<Src>,
type Err = <Dst as TryFrom<Src>>::Err
The error type produced by a failed conversion.
fn try_into(self) -> Result<Dst, <Src as TryInto<Dst>>::Err>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<Src> ValueFrom<Src> for Src
[src]
type Err = NoError
The error type produced by a failed conversion.
fn value_from(src: Src) -> Result<Src, <Src as ValueFrom<Src>>::Err>
[src]
impl<Src, Dst> ValueInto<Dst> for Src where
Dst: ValueFrom<Src>,
[src]
Dst: ValueFrom<Src>,