#[must_use]
pub struct Select<'a, T: Clone + std::fmt::Display + PartialEq + 'static> {
pub(crate) selected: &'a mut Option<T>,
pub(crate) options: &'a [T],
pub(crate) placeholder: String,
pub(crate) width: Option<f32>,
pub(crate) selected_text_override: Option<String>,
}
impl<'a, T: Clone + std::fmt::Display + PartialEq + 'static> Select<'a, T> {
pub fn new(selected: &'a mut Option<T>, options: &'a [T]) -> Self {
Self {
selected,
options,
placeholder: "Select...".to_owned(),
width: None,
selected_text_override: None,
}
}
pub fn placeholder(mut self, placeholder: impl Into<String>) -> Self {
self.placeholder = placeholder.into();
self
}
pub fn width(mut self, width: f32) -> Self {
self.width = Some(width);
self
}
pub fn selected_text(mut self, text: impl Into<String>) -> Self {
self.selected_text_override = Some(text.into());
self
}
pub fn show(self, ui: &mut egui::Ui) -> egui::Response {
ui.add(self)
}
}
#[must_use]
pub struct SelectValue<'a, T: Clone + std::fmt::Display + PartialEq + 'static> {
pub(crate) selected: &'a mut T,
pub(crate) options: &'a [T],
pub(crate) width: Option<f32>,
pub(crate) selected_text_override: Option<String>,
}
impl<'a, T: Clone + std::fmt::Display + PartialEq + 'static> SelectValue<'a, T> {
pub fn new(selected: &'a mut T, options: &'a [T]) -> Self {
Self {
selected,
options,
width: None,
selected_text_override: None,
}
}
pub fn width(mut self, width: f32) -> Self {
self.width = Some(width);
self
}
pub fn selected_text(mut self, text: impl Into<String>) -> Self {
self.selected_text_override = Some(text.into());
self
}
pub fn show(self, ui: &mut egui::Ui) -> egui::Response {
ui.add(self)
}
}
#[must_use]
pub struct SelectLabeled<'a, T: Clone + PartialEq + 'static> {
pub(crate) selected: &'a mut Option<T>,
pub(crate) entries: &'a [(T, String)],
pub(crate) placeholder: String,
pub(crate) width: Option<f32>,
}
impl<'a, T: Clone + PartialEq + 'static> SelectLabeled<'a, T> {
pub fn new(selected: &'a mut Option<T>, entries: &'a [(T, String)]) -> Self {
Self {
selected,
entries,
placeholder: "Select...".to_owned(),
width: None,
}
}
pub fn placeholder(mut self, placeholder: impl Into<String>) -> Self {
self.placeholder = placeholder.into();
self
}
pub fn width(mut self, width: f32) -> Self {
self.width = Some(width);
self
}
pub fn show(self, ui: &mut egui::Ui) -> egui::Response {
ui.add(self)
}
}
#[must_use]
pub struct SelectValueLabeled<'a, T: Clone + PartialEq + 'static> {
pub(crate) selected: &'a mut T,
pub(crate) entries: &'a [(T, String)],
pub(crate) width: Option<f32>,
}
impl<'a, T: Clone + PartialEq + 'static> SelectValueLabeled<'a, T> {
pub fn new(selected: &'a mut T, entries: &'a [(T, String)]) -> Self {
Self {
selected,
entries,
width: None,
}
}
pub fn width(mut self, width: f32) -> Self {
self.width = Some(width);
self
}
pub fn show(self, ui: &mut egui::Ui) -> egui::Response {
ui.add(self)
}
}