Enum egui::Align

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§

§

impl Align

pub const LEFT: Align = Self::Min

Convenience for Self::Min

pub const RIGHT: Align = Self::Max

Convenience for Self::Max

pub const TOP: Align = Self::Min

Convenience for Self::Min

pub const BOTTOM: Align = Self::Max

Convenience for Self::Max

pub fn to_factor(self) -> f32

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

pub fn to_sign(self) -> f32

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

pub fn align_size_within_range(
self,
size: f32,
range: RangeInclusive<f32>
) -> RangeInclusive<f32>

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§

§

impl Clone for Align

§

fn clone(&self) -> Align

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Debug for Align

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl Default for Align

§

fn default() -> Align

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

impl<'de> Deserialize<'de> for Align

§

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
§

impl Hash for Align

§

fn hash<__H>(&self, state: &mut __H)where
__H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where
H: Hasher,
Self: Sized,

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

impl PartialEq<Align> for Align

§

fn eq(&self, other: &Align) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

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

impl Serialize for Align

§

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 StructuralEq for Align

§

impl StructuralPartialEq for Align

Auto Trait Implementations§

§

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> Any for Twhere
T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere
T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere
T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere
U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T> ToOwned for Twhere
T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for Twhere
U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere
U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where
S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,

source§

impl<T> SerializableAny for Twhere
T: 'static + Any + Clone + Serialize + for<'a> Deserialize<'a> + Send + Sync,