Merge PR #1365: Fix font dropdown list resizing and keyboard up/down navigation

crates/ui-egui/src/ribbon.rs: ported the sel clamp, sized scroll area and position-based sel into combo_popup, keeping row_w and the filter-only separator
This commit is contained in:
aiongg
2026-10-22 02:35:15 +00:00
+25 -4
View File
@@ -466,6 +466,7 @@ fn combo_popup(
let filtered: Vec<usize> = items.iter().enumerate().filter(|(_, (_, d))| d.to_lowercase().contains(&lower)).map(|(i, _)| i).collect();
if !filtered.is_empty() {
let n = filtered.len() as i32;
st.sel = st.sel.clamp(0, n - 1);
if down {
st.sel = (st.sel + 1).rem_euclid(n);
}
@@ -480,15 +481,35 @@ fn combo_popup(
if filter {
ui.separator();
}
egui::ScrollArea::vertical().max_height(240.0).show(ui, |ui| {
for i in &filtered {
let button_h = ui.spacing().interact_size.y.max(20.0);
let spacing = ui.spacing().item_spacing.y;
let n = filtered.len() as f32;
let content_h = n * button_h + (n - 1.0).max(0.0) * spacing;
let max_rows = 9.0_f32;
let max_h = max_rows * button_h + (max_rows - 1.0) * spacing;
let desired_h = content_h.min(max_h);
ui.set_min_height(desired_h);
egui::ScrollArea::vertical().max_height(desired_h).show(ui, |ui| {
for (pos, i) in filtered.iter().enumerate() {
let (value, disp) = &items[*i];
let row = ui.add(egui::Button::selectable(*i as i32 == st.sel, egui::RichText::new(disp)).min_size(vec2(row_w, 20.0)));
let row = ui.add(egui::Button::selectable(pos as i32 == st.sel, egui::RichText::new(disp)).min_size(vec2(row_w, 20.0)));
if (down || up) && pos as i32 == st.sel && !ui.clip_rect().contains_rect(row.rect) {
row.scroll_to_me(Some(if down { egui::Align::Max } else { egui::Align::Min }));
}
if row.clicked() {
result = ComboResult::Picked(value.to_string());
}
if row.hovered() {
st.sel = *i as i32;
st.sel = pos as i32;
}
}
});