pub struct Atom<'a> {
pub id: Option<Id>,
pub size: Option<Vec2>,
pub max_size: Vec2,
pub grow: bool,
pub shrink: bool,
pub align: Align2,
pub kind: AtomKind<'a>,
}Expand description
A low-level ui building block.
This can be a piece of text, an image, or even a custom widget.
It can be decorated with various layout hints, such as grow, shrink, align, and more.
Atom implements From for String, str, crate::Image and much more for convenience.
Many widgets take an impl crate::IntoAtoms parameter,
which allows you to easily create atoms from tuples of text, images, and other atoms:
let image = egui::include_image!("../../../eframe/data/icon.png");
ui.button((image, "Click me!"));You can directly call the atom_* methods on anything that implements Into<Atom>.
use egui::AtomExt as _;
let string_atom = "Hello".atom_grow(true);
let image_atom = Image::new("some_image_url").atom_size(Vec2::splat(20.0));Fields§
§id: Option<Id>§size: Option<Vec2>§max_size: Vec2§grow: bool§shrink: bool§align: Align2§kind: AtomKind<'a>The atom type / content
Implementations§
Source§impl<'a> Atom<'a>
impl<'a> Atom<'a>
Sourcepub fn grow() -> Self
pub fn grow() -> Self
Create an empty Atom marked as grow.
This will expand in size, allowing all preceding atoms to be left-aligned, and all following atoms to be right-aligned
Sourcepub fn custom(id: Id, size: impl Into<Vec2>) -> Self
pub fn custom(id: Id, size: impl Into<Vec2>) -> Self
Create an AtomKind::Empty with a specific size.
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.place(rect, Button::new("⏵"));
}Sourcepub fn into_sized(
self,
ui: &Ui,
available_size: Vec2,
wrap_mode: Option<TextWrapMode>,
fallback_font: FontSelection,
) -> SizedAtom<'a>
pub fn into_sized( self, ui: &Ui, available_size: Vec2, wrap_mode: Option<TextWrapMode>, fallback_font: FontSelection, ) -> SizedAtom<'a>
Turn this into a SizedAtom.
Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for Atom<'a>
impl<'a> !RefUnwindSafe for Atom<'a>
impl<'a> !Send for Atom<'a>
impl<'a> !Sync for Atom<'a>
impl<'a> Unpin for Atom<'a>
impl<'a> !UnwindSafe for Atom<'a>
Blanket Implementations§
Source§impl<'a, T> AtomExt<'a> for T
impl<'a, T> AtomExt<'a> for T
Source§fn atom_shrink(self, shrink: bool) -> Atom<'a>
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>
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>
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>
fn atom_max_height(self, max_height: f32) -> Atom<'a>
Set the maximum height of this atom.
Source§fn atom_align(self, align: Align2) -> Atom<'a>
fn atom_align(self, align: Align2) -> Atom<'a>
Sets the
emath::Align2 of a single atom within its available space. Read moreSource§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