Enum AtomKind

Source
pub enum AtomKind<'a> {
    Empty,
    Text(WidgetText),
    Image(Image<'a>),
    Custom(Id),
}
Expand description

The different kinds of crate::Atoms.

Variants§

§

Empty

Empty, that can be used with crate::AtomExt::atom_grow to reserve space.

§

Text(WidgetText)

Text atom.

§Truncation within crate::AtomLayout works like this:
  • if wrap_mode is not Extend
    • if no atom is shrink
      • the first text atom is selected and will be marked as shrink
    • the atom marked as shrink will shrink / wrap based on the selected wrap mode
    • any other text atoms will have wrap_mode extend
  • if wrap_mode is extend, Text will extend as expected.

Unless crate::AtomExt::atom_max_width is set, wrap_mode should only be set via crate::Style or crate::AtomLayout::wrap_mode, as setting a wrap mode on a WidgetText atom that is not shrink will have unexpected results.

The size is determined by converting the WidgetText into a galley and using the galleys size. You can use crate::AtomExt::atom_size to override this, and crate::AtomExt::atom_max_width to limit the width (Causing the text to wrap or truncate, depending on the wrap_mode. crate::AtomExt::atom_max_height has no effect on text.

§

Image(Image<'a>)

Image atom.

By default the size is determined via Image::calc_size. You can use crate::AtomExt::atom_max_size or crate::AtomExt::atom_size to customize the size. There is also a helper crate::AtomExt::atom_max_height_font_size to set the max height to the default font height, which is convenient for icons.

§

Custom(Id)

For custom rendering.

You can get the crate::Rect with the Id from crate::AtomLayoutResponse and use a crate::Painter or Ui::put to add/draw some custom content.

Example:

let id = Id::new("my_button");
let response = Button::new(("Hi!", Atom::custom(id, Vec2::splat(18.0)))).atom_ui(ui);

let rect = response.rect(id);
if let Some(rect) = rect {
    ui.put(rect, Button::new("⏵"));
}

Implementations§

Source§

impl<'a> AtomKind<'a>

Source

pub fn text(text: impl Into<WidgetText>) -> Self

Source

pub fn image(image: impl Into<Image<'a>>) -> Self

Source

pub fn into_sized( self, ui: &Ui, available_size: Vec2, wrap_mode: Option<TextWrapMode>, ) -> (Vec2, SizedAtomKind<'a>)

Turn this AtomKind into a SizedAtomKind.

This converts WidgetText into crate::Galley and tries to load and size Image. The first returned argument is the preferred size.

Trait Implementations§

Source§

impl<'a> Clone for AtomKind<'a>

Source§

fn clone(&self) -> AtomKind<'a>

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
Source§

impl<'a> Debug for AtomKind<'a>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'a> Default for AtomKind<'a>

Source§

fn default() -> AtomKind<'a>

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

impl<'a> From<Image<'a>> for AtomKind<'a>

Source§

fn from(value: Image<'a>) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<ImageSource<'a>> for AtomKind<'a>

Source§

fn from(value: ImageSource<'a>) -> Self

Converts to this type from the input type.
Source§

impl<T> From<T> for AtomKind<'_>
where T: Into<WidgetText>,

Source§

fn from(value: T) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<'a> Freeze for AtomKind<'a>

§

impl<'a> RefUnwindSafe for AtomKind<'a>

§

impl<'a> Send for AtomKind<'a>

§

impl<'a> Sync for AtomKind<'a>

§

impl<'a> Unpin for AtomKind<'a>

§

impl<'a> UnwindSafe for AtomKind<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<'a, T> AtomExt<'a> for T
where T: Into<Atom<'a>>,

Source§

fn atom_size(self, size: Vec2) -> Atom<'a>

Set the atom to a fixed size. Read more
Source§

fn atom_grow(self, grow: bool) -> Atom<'a>

Grow this atom to the available space. Read more
Source§

fn atom_shrink(self, shrink: bool) -> Atom<'a>

Shrink this atom if there isn’t enough space. Read more
Source§

fn atom_max_size(self, max_size: Vec2) -> Atom<'a>

Set the maximum size of this atom. Read more
Source§

fn atom_max_width(self, max_width: f32) -> Atom<'a>

Set the maximum width of this atom. Read more
Source§

fn atom_max_height(self, max_height: f32) -> Atom<'a>

Set the maximum height of this atom.
Source§

fn atom_max_height_font_size(self, ui: &Ui) -> Atom<'a>
where Self: Sized,

Set the max height of this atom to match the font size. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

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<'a, T> IntoAtoms<'a> for T
where T: Into<Atom<'a>>,

Source§

fn collect(self, atoms: &mut Atoms<'a>)

Source§

fn into_atoms(self) -> Atoms<'a>
where Self: Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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 T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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