mirror of
https://github.com/emilk/egui.git
synced 2026-06-26 14:49:06 -04:00
Add atoms() helpers to get Atoms from widgets (#8128)
A get atoms trait for Button, checkbox etc. I made it because I had time to kill after I tried sorting buttons in a Vec by the image in their atoms, but couldn't get to it because it was private. --------- Co-authored-by: Lucas Meurer <hi@lucasmerlin.me> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
use epaint::Margin;
|
||||
|
||||
use crate::{
|
||||
Atom, AtomExt as _, AtomKind, AtomLayout, AtomLayoutResponse, Color32, CornerRadius, Frame,
|
||||
Image, IntoAtoms, NumExt as _, Response, Sense, Stroke, TextStyle, TextWrapMode, Ui, Vec2,
|
||||
Widget, WidgetInfo, WidgetText, WidgetType,
|
||||
Atom, AtomExt as _, AtomKind, AtomLayout, AtomLayoutResponse, Atoms, Color32, CornerRadius,
|
||||
Frame, Image, IntoAtoms, NumExt as _, Response, Sense, Stroke, TextStyle, TextWrapMode, Ui,
|
||||
Vec2, Widget, WidgetInfo, WidgetText, WidgetType,
|
||||
widget_style::{ButtonStyle, Classes, HasClasses, SELECTED_CLASS, WidgetState},
|
||||
};
|
||||
|
||||
@@ -279,6 +279,13 @@ impl<'a> Button<'a> {
|
||||
self
|
||||
}
|
||||
|
||||
/// Output the button's [`Atoms`].
|
||||
///
|
||||
/// This includes any images you have on the button.
|
||||
pub fn atoms(&self) -> &Atoms<'a> {
|
||||
&self.layout.atoms
|
||||
}
|
||||
|
||||
/// Show the button and return a [`AtomLayoutResponse`] for painting custom contents.
|
||||
pub fn atom_ui(self, ui: &mut Ui) -> AtomLayoutResponse {
|
||||
let Button {
|
||||
|
||||
@@ -41,6 +41,13 @@ impl<'a> Checkbox<'a> {
|
||||
Self::new(checked, ())
|
||||
}
|
||||
|
||||
/// Output the checkbox's [`Atoms`].
|
||||
///
|
||||
/// This includes any images you have on the checkbox.
|
||||
pub fn atoms(&self) -> &Atoms<'a> {
|
||||
&self.atoms
|
||||
}
|
||||
|
||||
/// Display an indeterminate state (neither checked nor unchecked)
|
||||
///
|
||||
/// This only affects the checkbox's appearance. It will still toggle its boolean value when
|
||||
|
||||
@@ -409,6 +409,13 @@ impl<'a> DragValue<'a> {
|
||||
self.update_while_editing = update;
|
||||
self
|
||||
}
|
||||
|
||||
/// Output the [`DragValue`]'s [`Atoms`].
|
||||
///
|
||||
/// This includes any images you have on the [`DragValue`].
|
||||
pub fn atoms(&self) -> &Atoms<'a> {
|
||||
&self.atoms
|
||||
}
|
||||
}
|
||||
|
||||
impl Widget for DragValue<'_> {
|
||||
|
||||
@@ -35,6 +35,13 @@ impl<'a> RadioButton<'a> {
|
||||
atoms: atoms.into_atoms(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Output the [`RadioButton`]'s [`Atoms`].
|
||||
///
|
||||
/// This includes any images you have on the [`RadioButton`].
|
||||
pub fn atoms(&self) -> &Atoms<'a> {
|
||||
&self.atoms
|
||||
}
|
||||
}
|
||||
|
||||
impl Widget for RadioButton<'_> {
|
||||
|
||||
Reference in New Issue
Block a user