mirror of
https://github.com/emilk/egui.git
synced 2026-08-29 04:40:03 -04:00
Add some example docs to atoms (#7997)
This commit is contained in:
@@ -4,7 +4,21 @@ use epaint::text::TextWrapMode;
|
|||||||
|
|
||||||
/// A low-level ui building block.
|
/// A low-level ui building block.
|
||||||
///
|
///
|
||||||
/// Implements [`From`] for [`String`], [`str`], [`crate::Image`] and much more for convenience.
|
/// 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:
|
||||||
|
/// ```
|
||||||
|
/// # use egui::{Vec2, AtomExt, AtomKind, Atom, Image, Id};
|
||||||
|
/// # egui::__run_test_ui(|ui| {
|
||||||
|
/// 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>`.
|
/// You can directly call the `atom_*` methods on anything that implements `Into<Atom>`.
|
||||||
/// ```
|
/// ```
|
||||||
/// # use egui::{Image, emath::Vec2};
|
/// # use egui::{Image, emath::Vec2};
|
||||||
|
|||||||
@@ -8,6 +8,15 @@ use std::ops::{Deref, DerefMut};
|
|||||||
pub(crate) const ATOMS_SMALL_VEC_SIZE: usize = 2;
|
pub(crate) const ATOMS_SMALL_VEC_SIZE: usize = 2;
|
||||||
|
|
||||||
/// A list of [`Atom`]s.
|
/// A list of [`Atom`]s.
|
||||||
|
///
|
||||||
|
/// Many widgets take an `impl` [`IntoAtoms`] parameter,
|
||||||
|
/// which allows you to easily create atoms from tuples of text, images, and other atoms:
|
||||||
|
/// ```
|
||||||
|
/// # use egui::{AtomExt, AtomKind, Atom, Image, Id, Vec2};
|
||||||
|
/// # egui::__run_test_ui(|ui| {
|
||||||
|
/// let image = egui::include_image!("../../../eframe/data/icon.png");
|
||||||
|
/// ui.button((image, "Click me!"));
|
||||||
|
/// # });
|
||||||
#[derive(Clone, Debug, Default)]
|
#[derive(Clone, Debug, Default)]
|
||||||
pub struct Atoms<'a>(SmallVec<[Atom<'a>; ATOMS_SMALL_VEC_SIZE]>);
|
pub struct Atoms<'a>(SmallVec<[Atom<'a>; ATOMS_SMALL_VEC_SIZE]>);
|
||||||
|
|
||||||
@@ -192,6 +201,16 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Trait for turning a tuple of [`Atom`]s into [`Atoms`].
|
/// Trait for turning a tuple of [`Atom`]s into [`Atoms`].
|
||||||
|
///
|
||||||
|
/// Many widgets take an `impl` [`IntoAtoms`] parameter,
|
||||||
|
/// which allows you to easily create atoms from tuples of text, images, and other atoms:
|
||||||
|
/// ```
|
||||||
|
/// # use egui::{AtomExt, AtomKind, Atom, Image, Id, Vec2};
|
||||||
|
/// # egui::__run_test_ui(|ui| {
|
||||||
|
/// let image = egui::include_image!("../../../eframe/data/icon.png");
|
||||||
|
/// ui.button((image, "Click me!"));
|
||||||
|
/// # });
|
||||||
|
/// ```
|
||||||
pub trait IntoAtoms<'a> {
|
pub trait IntoAtoms<'a> {
|
||||||
fn collect(self, atoms: &mut Atoms<'a>);
|
fn collect(self, atoms: &mut Atoms<'a>);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user