Make dropdowns start with the current value when you open them

This commit is contained in:
Dustin Carlino 2021-04-21 14:54:51 -07:00
parent 1fb1253e97
commit 4ee50de58d
2 changed files with 5 additions and 1 deletions

View File

@ -56,7 +56,6 @@ impl<T: 'static + PartialEq + Clone> Dropdown<T> {
impl<T: 'static + Clone> Dropdown<T> {
fn open_menu(&mut self, ctx: &mut EventCtx) {
// TODO set current idx in menu
let mut menu = Menu::new(
ctx,
self.choices
@ -65,6 +64,7 @@ impl<T: 'static + Clone> Dropdown<T> {
.map(|(idx, c)| c.with_value(idx))
.collect(),
);
menu.set_current(self.current_idx);
let y1_below = self.btn.top_left.y + self.btn.dims.height + 15.0;
menu.set_pos(ScreenPt::new(

View File

@ -35,6 +35,10 @@ impl<T: 'static> Menu<T> {
self.choices.remove(self.current_idx).data
}
pub fn set_current(&mut self, idx: usize) {
self.current_idx = idx;
}
fn calculate_txt(&self, style: &Style) -> Text {
let mut txt = Text::new();