pub enum Align {
    Min,
    Center,
    Max,
}
Expand description

left/center/right or top/center/bottom alignment for e.g. anchors and layouts.

Variants

Min

Left or top.

Center

Horizontal or vertical center.

Max

Right or bottom.

Implementations

Convenience for Self::Min

Convenience for Self::Max

Convenience for Self::Min

Convenience for Self::Max

Convert Min => 0.0, Center => 0.5 or Max => 1.0.

Convert Min => -1.0, Center => 0.0 or Max => 1.0.

Returns a range of given size within a specified range.

If the requested size is bigger than the size of range, then the returned range will not fit into the available range. The extra space will be allocated from:

AlignSide
Minright (end)
Centerboth
Maxleft (start)
Examples
use std::f32::{INFINITY, NEG_INFINITY};
use emath::Align::*;

// The size is smaller than a range
assert_eq!(Min   .align_size_within_range(2.0, 10.0..=20.0), 10.0..=12.0);
assert_eq!(Center.align_size_within_range(2.0, 10.0..=20.0), 14.0..=16.0);
assert_eq!(Max   .align_size_within_range(2.0, 10.0..=20.0), 18.0..=20.0);

// The size is bigger than a range
assert_eq!(Min   .align_size_within_range(20.0, 10.0..=20.0), 10.0..=30.0);
assert_eq!(Center.align_size_within_range(20.0, 10.0..=20.0),  5.0..=25.0);
assert_eq!(Max   .align_size_within_range(20.0, 10.0..=20.0),  0.0..=20.0);

// The size is infinity, but range is finite - a special case of a previous example
assert_eq!(Min   .align_size_within_range(INFINITY, 10.0..=20.0),         10.0..=INFINITY);
assert_eq!(Center.align_size_within_range(INFINITY, 10.0..=20.0), NEG_INFINITY..=INFINITY);
assert_eq!(Max   .align_size_within_range(INFINITY, 10.0..=20.0), NEG_INFINITY..=20.0);

The infinity-sized ranges can produce a surprising results, if the size is also infinity, use such ranges with carefully!

use std::f32::{INFINITY, NEG_INFINITY};
use emath::Align::*;

// Allocating a size aligned for infinity bound will lead to empty ranges!
assert_eq!(Min   .align_size_within_range(2.0, 10.0..=INFINITY),     10.0..=12.0);
assert_eq!(Center.align_size_within_range(2.0, 10.0..=INFINITY), INFINITY..=INFINITY);// (!)
assert_eq!(Max   .align_size_within_range(2.0, 10.0..=INFINITY), INFINITY..=INFINITY);// (!)

assert_eq!(Min   .align_size_within_range(2.0, NEG_INFINITY..=20.0), NEG_INFINITY..=NEG_INFINITY);// (!)
assert_eq!(Center.align_size_within_range(2.0, NEG_INFINITY..=20.0), NEG_INFINITY..=NEG_INFINITY);// (!)
assert_eq!(Max   .align_size_within_range(2.0, NEG_INFINITY..=20.0),         18.0..=20.0);


// The infinity size will always return the given range if it has at least one infinity bound
assert_eq!(Min   .align_size_within_range(INFINITY, 10.0..=INFINITY), 10.0..=INFINITY);
assert_eq!(Center.align_size_within_range(INFINITY, 10.0..=INFINITY), 10.0..=INFINITY);
assert_eq!(Max   .align_size_within_range(INFINITY, 10.0..=INFINITY), 10.0..=INFINITY);

assert_eq!(Min   .align_size_within_range(INFINITY, NEG_INFINITY..=20.0), NEG_INFINITY..=20.0);
assert_eq!(Center.align_size_within_range(INFINITY, NEG_INFINITY..=20.0), NEG_INFINITY..=20.0);
assert_eq!(Max   .align_size_within_range(INFINITY, NEG_INFINITY..=20.0), NEG_INFINITY..=20.0);

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Deserialize this value from the given Serde deserializer. Read more

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.