Skip to content

Commit

Permalink
Fix size of textedit when heading missing in EditableList
Browse files Browse the repository at this point in the history
  • Loading branch information
vv9k committed Dec 11, 2021
1 parent 5581854 commit 1075e73
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/app/ui/editable_list.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
use crate::app::ui::{icon, key};

#[derive(Debug)]
/// Represents the types of data that can be displayed by [`EditableList`](EditableList).
enum ListData<'a> {
KeyVal(&'a mut Vec<(String, String)>),
Key(&'a mut Vec<String>),
}

#[derive(Debug)]
/// UI widget that can display editable lists of string items. There is a button to add new values
/// as well as a button to remove each entry.
pub struct EditableList<'a> {
heading: Option<&'a str>,
data: ListData<'a>,
Expand Down Expand Up @@ -70,13 +73,18 @@ impl<'a> EditableList<'a> {
let response = grid.show(ui, |ui| match &mut self.data {
ListData::Key(data) => {
for (i, key) in data.iter_mut().enumerate() {
if let Some(key_heading) = self.key_heading {
key!(ui, key_heading);
}
ui.add(egui::TextEdit::singleline(key));
if ui.button(icon::DELETE).clicked() {
to_delete = Some(i);
}
ui.end_row();
}
ui.scope(|_| {});
if self.key_heading.is_some() {
ui.scope(|_| {});
}
ui.allocate_space(desired_size);
ui.end_row();
}
Expand All @@ -95,9 +103,13 @@ impl<'a> EditableList<'a> {
}
ui.end_row();
}
ui.scope(|_| {});
if self.key_heading.is_some() {
ui.scope(|_| {});
}
ui.allocate_space(desired_size);
ui.scope(|_| {});
if self.val_heading.is_some() {
ui.scope(|_| {});
}
ui.allocate_space(desired_size);
ui.end_row();
}
Expand Down

0 comments on commit 1075e73

Please sign in to comment.