pub struct Atom<'a> {
pub id: Option<IdSalt>,
pub size: Option<Vec2>,
pub max_size: Vec2,
pub grow: bool,
pub shrink: bool,
pub align: Align2,
pub kind: AtomKind<'a>,
}egui only.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<IdSalt>§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() -> Atom<'a>
pub fn grow() -> Atom<'a>
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: IdSalt, size: impl Into<Vec2>) -> Atom<'a>
pub fn custom(id: IdSalt, size: impl Into<Vec2>) -> Atom<'a>
Create an AtomKind::Empty with a specific size.
Example:
let id = IdSalt::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 paint(
size: impl Into<Vec2>,
func: impl Fn(&Ui, AtomPaintArgs) + 'a,
) -> Atom<'a>
pub fn paint( size: impl Into<Vec2>, func: impl Fn(&Ui, AtomPaintArgs) + 'a, ) -> Atom<'a>
Create an AtomKind::Paint with a specific size.
The closure paints the atom at the AtomPaintArgs::rect the layout gives it.
Example:
let dot = Atom::paint(Vec2::splat(8.0), |ui, args| {
ui.painter()
.rect_filled(args.rect, CornerRadius::same(4), Color32::RED);
});
ui.add(Button::new((dot, "Recording")));Sourcepub fn widget(widget: WidgetAtom<'a>) -> Atom<'a>
pub fn widget(widget: WidgetAtom<'a>) -> Atom<'a>
Nest a WidgetAtom (interactive and requests a response) as a single atom.
The nested widget is sized when the parent is sized and painted (and interacted with)
at the cell the parent computes for it. See AtomKind::Widget.
You can get the response by setting an explicit crate::Id and using crate::Context::read_response
Sourcepub fn container(container: ContainerAtom<'a>) -> Atom<'a>
pub fn container(container: ContainerAtom<'a>) -> Atom<'a>
Nest a ContainerAtom (a non-interactive atom-based layout) as a single atom.
Like Self::widget, the nested layout is sized when the parent is sized and painted at
the cell the parent computes for it. Unlike Self::widget, a ContainerAtom has no
id or sense, so it is painted but not interacted with. See AtomKind::Container.
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> !RefUnwindSafe for Atom<'a>
impl<'a> !Send for Atom<'a>
impl<'a> !Sync for Atom<'a>
impl<'a> !UnwindSafe for Atom<'a>
impl<'a> Forget for Atom<'a>
impl<'a> Freeze for Atom<'a>where
NonZero<u64>: Freeze,
*const u8 is !null: Freeze,
PhantomData<u8>: Freeze,
*const ArcInner<RichText> is !null: Freeze,
PhantomData<ArcInner<RichText>>: Freeze,
*const ArcInner<LayoutJob> is !null: Freeze,
PhantomData<ArcInner<LayoutJob>>: Freeze,
*const ArcInner<Galley> is !null: Freeze,
PhantomData<ArcInner<Galley>>: Freeze,
&'a str: Freeze,
String: Freeze,
&'static str: Freeze,
&'static [u8]: Freeze,
*const ArcInner<[u8]> is !null: Freeze,
PhantomData<ArcInner<[u8]>>: Freeze,
*const dyn FnOnce(&Ui, IntoSizedArgs) -> IntoSizedResult<'static> + 'a is !null: Freeze,
PhantomData<dyn FnOnce(&Ui, IntoSizedArgs) -> IntoSizedResult<'static> + 'a>: Freeze,
*const ArcInner<dyn Fn(&Ui, AtomPaintArgs) + 'a> is !null: Freeze,
PhantomData<ArcInner<dyn Fn(&Ui, AtomPaintArgs) + 'a>>: Freeze,
*const WidgetAtom<'a> is !null: Freeze,
PhantomData<WidgetAtom<'a>>: Freeze,
*const ContainerAtom<'a> is !null: Freeze,
PhantomData<ContainerAtom<'a>>: Freeze,
impl<'a> Move for Atom<'a>
impl<'a> Unpin for Atom<'a>where
NonZero<u64>: Unpin,
*const u8 is !null: Unpin,
Arc<RichText>: Unpin,
Arc<LayoutJob>: Unpin,
Arc<Galley>: Unpin,
&'a str: Unpin,
String: Unpin,
&'static str: Unpin,
&'static [u8]: Unpin,
Arc<[u8]>: Unpin,
Box<dyn FnOnce(&Ui, IntoSizedArgs) -> IntoSizedResult<'static> + 'a>: Unpin,
Arc<dyn Fn(&Ui, AtomPaintArgs) + 'a>: Unpin,
Box<WidgetAtom<'a>>: Unpin,
Box<ContainerAtom<'a>>: Unpin,
impl<'a> UnsafeUnpin for Atom<'a>where
NonZeroU64Inner: UnsafeUnpin,
*const u8 is !null: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
*const ArcInner<RichText> is !null: UnsafeUnpin,
PhantomData<ArcInner<RichText>>: UnsafeUnpin,
*const ArcInner<LayoutJob> is !null: UnsafeUnpin,
PhantomData<ArcInner<LayoutJob>>: UnsafeUnpin,
*const ArcInner<Galley> is !null: UnsafeUnpin,
PhantomData<ArcInner<Galley>>: UnsafeUnpin,
&'a str: UnsafeUnpin,
String: UnsafeUnpin,
&'static str: UnsafeUnpin,
&'static [u8]: UnsafeUnpin,
*const ArcInner<[u8]> is !null: UnsafeUnpin,
PhantomData<ArcInner<[u8]>>: UnsafeUnpin,
*const dyn FnOnce(&Ui, IntoSizedArgs) -> IntoSizedResult<'static> + 'a is !null: UnsafeUnpin,
PhantomData<dyn FnOnce(&Ui, IntoSizedArgs) -> IntoSizedResult<'static> + 'a>: UnsafeUnpin,
*const ArcInner<dyn Fn(&Ui, AtomPaintArgs) + 'a> is !null: UnsafeUnpin,
PhantomData<ArcInner<dyn Fn(&Ui, AtomPaintArgs) + 'a>>: UnsafeUnpin,
*const WidgetAtom<'a> is !null: UnsafeUnpin,
PhantomData<WidgetAtom<'a>>: UnsafeUnpin,
*const ContainerAtom<'a> is !null: UnsafeUnpin,
PhantomData<ContainerAtom<'a>>: UnsafeUnpin,
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>
Source§fn atom_max_size(self, max_size: Vec2) -> Atom<'a>
fn atom_max_size(self, max_size: Vec2) -> Atom<'a>
Source§fn atom_max_width(self, max_width: f32) -> Atom<'a>
fn atom_max_width(self, max_width: f32) -> Atom<'a>
Source§fn atom_max_height(self, max_height: f32) -> Atom<'a>
fn atom_max_height(self, max_height: f32) -> Atom<'a>
Source§fn atom_align(self, align: Align2) -> Atom<'a>
fn atom_align(self, align: Align2) -> Atom<'a>
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
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> ⓘ
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> ⓘ
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