pub struct ComboBox<'a> { /* private fields */ }egui only.Expand description
A drop-down selection menu with a descriptive label.
let before = selected;
egui::ComboBox::from_label("Select one!")
.selected_text(format!("{:?}", selected))
.show_ui(ui, |ui| {
ui.selectable_value(&mut selected, Enum::First, "First");
ui.selectable_value(&mut selected, Enum::Second, "Second");
ui.selectable_value(&mut selected, Enum::Third, "Third");
}
);
if selected != before {
// Handle selection change
}Implementations§
Source§impl<'a> ComboBox<'a>
impl<'a> ComboBox<'a>
Sourcepub const CLASS_OPEN: ClassName
pub const CLASS_OPEN: ClassName
Present on the button of a ComboBox while its popup is open.
Sourcepub fn new(id_salt: impl AsIdSalt, label: impl IntoAtoms<'a>) -> ComboBox<'a>
pub fn new(id_salt: impl AsIdSalt, label: impl IntoAtoms<'a>) -> ComboBox<'a>
Create new ComboBox with id and label
Sourcepub fn from_label(label: impl IntoAtoms<'a>) -> ComboBox<'a>
pub fn from_label(label: impl IntoAtoms<'a>) -> ComboBox<'a>
Label shown next to the combo box.
The contents of the label is used as the id salt (see Atoms::salt).
Sourcepub fn from_id_salt(id_salt: impl AsIdSalt) -> ComboBox<'a>
pub fn from_id_salt(id_salt: impl AsIdSalt) -> ComboBox<'a>
Without label.
Sourcepub fn width(self, width: f32) -> ComboBox<'a>
pub fn width(self, width: f32) -> ComboBox<'a>
Set the outer width of the button and menu.
Default is Spacing::combo_width.
Sourcepub fn height(self, height: f32) -> ComboBox<'a>
pub fn height(self, height: f32) -> ComboBox<'a>
Set the maximum outer height of the menu.
Default is Spacing::combo_height.
Sourcepub fn selected_text(self, selected_text: impl IntoAtoms<'a>) -> ComboBox<'a>
pub fn selected_text(self, selected_text: impl IntoAtoms<'a>) -> ComboBox<'a>
What we show as the currently selected value.
This can be any IntoAtoms, e.g. an image next to some text:
let ferris = egui::include_image!("../../assets/ferris.png");
egui::ComboBox::from_label("Crab")
.selected_text((egui::Image::new(ferris.clone()).max_height(16.0), "Ferris"))
.show_ui(ui, |ui| {
let _ = ui.selectable_label(true, (egui::Image::new(ferris).max_height(16.0), "Ferris"));
});Sourcepub fn icon(
self,
icon_fn: impl FnOnce(&Ui, Rect, &WidgetVisuals, bool) + 'static,
) -> ComboBox<'a>
pub fn icon( self, icon_fn: impl FnOnce(&Ui, Rect, &WidgetVisuals, bool) + 'static, ) -> ComboBox<'a>
Use the provided function to render a different ComboBox icon.
Defaults to a triangle that expands when the cursor is hovering over the ComboBox.
For example:
pub fn filled_triangle(
ui: &egui::Ui,
rect: egui::Rect,
visuals: &egui::style::WidgetVisuals,
_is_open: bool,
) {
let rect = egui::Rect::from_center_size(
rect.center(),
egui::vec2(rect.width() * 0.6, rect.height() * 0.4),
);
ui.painter().add(egui::Shape::convex_polygon(
vec![rect.left_top(), rect.right_top(), rect.center_bottom()],
visuals.fg_stroke.color,
visuals.fg_stroke,
));
}
egui::ComboBox::from_id_salt("my-combobox")
.selected_text(text)
.icon(filled_triangle)
.show_ui(ui, |_ui| {});Sourcepub fn wrap_mode(self, wrap_mode: TextWrapMode) -> ComboBox<'a>
pub fn wrap_mode(self, wrap_mode: TextWrapMode) -> ComboBox<'a>
Controls the wrap mode used for the selected text.
By default, Ui::wrap_mode will be used, which can be overridden with crate::Style::wrap_mode.
Note that any \n in the text will always produce a new line.
Sourcepub fn wrap(self) -> ComboBox<'a>
pub fn wrap(self) -> ComboBox<'a>
Set Self::wrap_mode to TextWrapMode::Wrap.
Sourcepub fn close_behavior(self, close_behavior: PopupCloseBehavior) -> ComboBox<'a>
pub fn close_behavior(self, close_behavior: PopupCloseBehavior) -> ComboBox<'a>
Controls the close behavior for the popup.
By default, PopupCloseBehavior::CloseOnClick will be used.
Sourcepub fn popup_style(self, popup_style: StyleModifier) -> ComboBox<'a>
pub fn popup_style(self, popup_style: StyleModifier) -> ComboBox<'a>
Set the style of the popup menu.
Could for example be used with crate::containers::menu::menu_style to get the frame-less
menu button style.
Sourcepub fn show_ui<R>(
self,
ui: &mut Ui,
menu_contents: impl FnOnce(&mut Ui) -> R,
) -> InnerResponse<Option<R>>
pub fn show_ui<R>( self, ui: &mut Ui, menu_contents: impl FnOnce(&mut Ui) -> R, ) -> InnerResponse<Option<R>>
Show the combo box, with the given ui code for the menu contents.
Returns InnerResponse { inner: None } if the combo box is closed.
Sourcepub fn show_index<Text>(
self,
ui: &mut Ui,
selected: &mut usize,
len: usize,
get: impl Fn(usize) -> Text,
) -> Responsewhere
Text: IntoAtoms<'a>,
pub fn show_index<Text>(
self,
ui: &mut Ui,
selected: &mut usize,
len: usize,
get: impl Fn(usize) -> Text,
) -> Responsewhere
Text: IntoAtoms<'a>,
Show a list of items with the given selected index.
let alternatives = ["a", "b", "c", "d"];
let mut selected = 2;
egui::ComboBox::from_label("Select one!").show_index(
ui,
&mut selected,
alternatives.len(),
|i| alternatives[i]
);Trait Implementations§
Source§impl HasClasses for ComboBox<'_>
impl HasClasses for ComboBox<'_>
fn classes(&self) -> &Classes
fn classes_mut(&mut self) -> &mut Classes
Source§fn add_class(&mut self, class: impl Into<ClassName>) -> &mut Selfwhere
Self: Sized,
fn add_class(&mut self, class: impl Into<ClassName>) -> &mut Selfwhere
Self: Sized,
Source§fn set_class(&mut self, class: impl Into<ClassName>, present: bool) -> &mut Selfwhere
Self: Sized,
fn set_class(&mut self, class: impl Into<ClassName>, present: bool) -> &mut Selfwhere
Self: Sized,
present, remove it otherwise. Read moreSource§fn remove_class(&mut self, class: impl Into<ClassName>) -> &mut Selfwhere
Self: Sized,
fn remove_class(&mut self, class: impl Into<ClassName>) -> &mut Selfwhere
Self: Sized,
Source§fn with_class(self, class: impl Into<ClassName>) -> Selfwhere
Self: Sized,
fn with_class(self, class: impl Into<ClassName>) -> Selfwhere
Self: Sized,
self.Source§fn add_classes(&mut self, classes: Classes) -> &mut Self
fn add_classes(&mut self, classes: Classes) -> &mut Self
Source§fn with_classes(self, classes: Classes) -> Selfwhere
Self: Sized,
fn with_classes(self, classes: Classes) -> Selfwhere
Self: Sized,
self.Source§fn add_class_if(
&mut self,
class: impl Into<ClassName>,
condition: bool,
) -> &mut Selfwhere
Self: Sized,
fn add_class_if(
&mut self,
class: impl Into<ClassName>,
condition: bool,
) -> &mut Selfwhere
Self: Sized,
Source§fn with_class_if(self, class: impl Into<ClassName>, condition: bool) -> Selfwhere
Self: Sized,
fn with_class_if(self, class: impl Into<ClassName>, condition: bool) -> Selfwhere
Self: Sized,
self if the condition is true. Read moreSource§fn iter_classes(&self) -> Iter<'_, ClassName> ⓘ
fn iter_classes(&self) -> Iter<'_, ClassName> ⓘ
Source§fn classes_as_slice(&self) -> &[ClassName]
fn classes_as_slice(&self) -> &[ClassName]
Auto Trait Implementations§
impl<'a> !RefUnwindSafe for ComboBox<'a>
impl<'a> !Send for ComboBox<'a>
impl<'a> !Sync for ComboBox<'a>
impl<'a> !UnwindSafe for ComboBox<'a>
impl<'a> Forget for ComboBox<'a>
impl<'a> Freeze for ComboBox<'a>where
NonZero<u64>: Freeze,
*const u8 is !null: Freeze,
PhantomData<Atom<'a>>: Freeze,
*const dyn FnOnce(&Ui, Rect, &WidgetVisuals, bool) is !null: Freeze,
PhantomData<dyn FnOnce(&Ui, Rect, &WidgetVisuals, bool)>: Freeze,
*const ArcInner<dyn Fn(&mut Style) + Sync + Send> is !null: Freeze,
PhantomData<ArcInner<dyn Fn(&mut Style) + Sync + Send>>: Freeze,
&'static str: Freeze,
*const ArcInner<str> is !null: Freeze,
PhantomData<ArcInner<str>>: Freeze,
*const ClassName is !null: Freeze,
PhantomData<ClassName>: Freeze,
impl<'a> Move for ComboBox<'a>
impl<'a> Unpin for ComboBox<'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,
Box<dyn FnOnce(&Ui, Rect, &WidgetVisuals, bool)>: Unpin,
Arc<dyn Fn(&mut Style) + Sync + Send>: Unpin,
Arc<str>: Unpin,
*const ClassName is !null: Unpin,
ClassName: Unpin,
impl<'a> UnsafeUnpin for ComboBox<'a>where
NonZeroU64Inner: UnsafeUnpin,
*const u8 is !null: UnsafeUnpin,
PhantomData<Atom<'a>>: UnsafeUnpin,
*const dyn FnOnce(&Ui, Rect, &WidgetVisuals, bool) is !null: UnsafeUnpin,
PhantomData<dyn FnOnce(&Ui, Rect, &WidgetVisuals, bool)>: UnsafeUnpin,
*const ArcInner<dyn Fn(&mut Style) + Sync + Send> is !null: UnsafeUnpin,
PhantomData<ArcInner<dyn Fn(&mut Style) + Sync + Send>>: UnsafeUnpin,
&'static str: UnsafeUnpin,
*const ArcInner<str> is !null: UnsafeUnpin,
PhantomData<ArcInner<str>>: UnsafeUnpin,
*const ClassName is !null: UnsafeUnpin,
PhantomData<ClassName>: UnsafeUnpin,
Blanket Implementations§
Source§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> 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