Skip to content

Making a scrollable combo box doesn't work as expected. #75

@ArjunNair

Description

@ArjunNair

egui issue

I'm trying to list all the files in the combo box (as buttons). This will over spill the window area because the drop down is bigger than the window height as can be seen above. Since combo box itself doesn't seem to support scrolling out of the box, I thought of adding a ScrollArea within the combo box (since it's a container presumably).

This kind of works, in that I can scroll by moving the mouse up and down, but couple of things are broken:

  1. The scroll area width is the size of the Window width which is the parent container ui. I'm not sure how I can constrain it to the combo box dimensions.
  2. The vertical scroll bar doesn't appear (perhaps because it falls outside the window width).

Frankly, I expected the combo box to automatically take care of this. That is, it has a scroll area built into it, so that if the item dimensions > default combo box dimension, the comb box shows appropriate scroll bars (vertical/horizontal).

Failing the above, what would be the idiomatic way to do this in egui? I've included the source code for how I'm doing things now:

&egui::Window::new("Chipper")
            .fixed_pos(Pos2::new(0f32,0f32))
            //.default_size(vec2(WINDOW_WIDTH as f32, WINDOW_HEIGHT as f32))
            .resizable(false)
            .collapsible(false)
            .show(&mut egui_ctx, |ui| {
                if !is_paused {
                    ui.label(format!("FPS: {} ({} ms/frame)", fps, avg_frame_time));
                }
                else {
                    ui.label(format!("PAUSED"));
                }
                ui.add(Image::new(chip8_tex_id, vec2((CHIP8_DISPLAY_WIDTH * DISPLAY_SCALE) as f32, (CHIP8_DISPLAY_HEIGHT * DISPLAY_SCALE) as f32)));
                ui.label("");
                combo_box_with_label(ui, "ROM files", selected_rom, |ui| {
                    ScrollArea::from_max_height(50f32).show(ui, |ui| {
                        for (f, _p) in &rom_files {
                            if ui.button(f).clicked {
                                selected_rom = f;
                                chip8.boot_rom(rom_files.get(selected_rom).expect("No rom files to load!")).expect("Failed to load rom!");
                            };
                        }
                    })
                });
                //There is probably a better way to add line breaks in egui....
                ui.label("");
                if ui.checkbox(&mut use_vy_for_shift_operations, "Use Vy for shift operations").clicked {
                    chip8.shift_using_vy = use_vy_for_shift_operations;
                };  
                if ui.checkbox(&mut increment_i_on_ld_operations, "Increment I on  LD Vx operations").clicked {
                    chip8.increment_i_on_ld = increment_i_on_ld_operations;
                };
                ui.label("");
                ui.label("ESC = Pause/Resume.  F2 = Reset.");
                
        });

rom_files is a HashMap<String, String>.

I hope I'm not missing something blindingly obvious... :S

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions