pub enum Align {
Min,
Center,
Max,
}
Expand description
left/center/right or top/center/bottom alignment for e.g. anchors and layouts.
Variants§
Implementations§
source§impl Align
impl Align
sourcepub fn align_size_within_range(
self,
size: f32,
range: impl Into<Rangef>,
) -> Rangef
pub fn align_size_within_range( self, size: f32, range: impl Into<Rangef>, ) -> Rangef
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:
Align | Side |
---|---|
Min | right (end) |
Center | both |
Max | left (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§
source§impl<'de> Deserialize<'de> for Align
impl<'de> Deserialize<'de> for Align
source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Align, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Align, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
source§impl Serialize for Align
impl Serialize for Align
source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Serialize this value into the given Serde serializer. Read more
impl Copy for Align
impl Eq for Align
impl StructuralPartialEq for Align
Auto Trait Implementations§
impl Freeze for Align
impl RefUnwindSafe for Align
impl Send for Align
impl Sync for Align
impl Unpin for Align
impl UnwindSafe for Align
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more