pub struct ComboBox { /* private fields */ }Expand description
A drop-down selection menu with a descriptive label.
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");
}
);Implementations§
Source§impl ComboBox
impl ComboBox
Sourcepub fn new(id_source: impl Hash, label: impl Into<WidgetText>) -> ComboBox
pub fn new(id_source: impl Hash, label: impl Into<WidgetText>) -> ComboBox
Create new ComboBox with id and label
Sourcepub fn from_label(label: impl Into<WidgetText>) -> ComboBox
pub fn from_label(label: impl Into<WidgetText>) -> ComboBox
Label shown next to the combo box
Sourcepub fn from_id_source(id_source: impl Hash) -> ComboBox
pub fn from_id_source(id_source: impl Hash) -> ComboBox
Without label.
Sourcepub fn selected_text(self, selected_text: impl Into<WidgetText>) -> ComboBox
pub fn selected_text(self, selected_text: impl Into<WidgetText>) -> ComboBox
What we show as the currently selected value
Sourcepub fn icon(
self,
icon_fn: impl FnOnce(&Ui, Rect, &WidgetVisuals, bool, AboveOrBelow) + 'static,
) -> ComboBox
pub fn icon( self, icon_fn: impl FnOnce(&Ui, Rect, &WidgetVisuals, bool, AboveOrBelow) + 'static, ) -> ComboBox
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,
_above_or_below: egui::AboveOrBelow,
) {
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_source("my-combobox")
.selected_text(text)
.icon(filled_triangle)
.show_ui(ui, |_ui| {});Sourcepub fn wrap(self, wrap: bool) -> ComboBox
pub fn wrap(self, wrap: bool) -> ComboBox
Controls whether text wrap is used for the selected text
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: Into<WidgetText>,
pub fn show_index<Text>(
self,
ui: &mut Ui,
selected: &mut usize,
len: usize,
get: impl Fn(usize) -> Text,
) -> Responsewhere
Text: Into<WidgetText>,
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]
);Auto Trait Implementations§
impl Freeze for ComboBox
impl !RefUnwindSafe for ComboBox
impl !Send for ComboBox
impl !Sync for ComboBox
impl Unpin for ComboBox
impl !UnwindSafe for ComboBox
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
Mutably borrows from an owned value. Read more
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
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> ⓘ
Converts
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> ⓘ
Converts
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 moreSource§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.