emilk / egui

egui: an easy-to-use immediate mode GUI in Rust that runs on both web and native
https://www.egui.rs/
Apache License 2.0
22.6k stars 1.62k forks source link

Configuration options for color picker layout/style #5153

Open philpax opened 2 months ago

philpax commented 2 months ago

Is your feature request related to a problem? Please describe. Using egui::widgets::color_picker::color_picker_hsva_2d (or similar) by itself results in a color slider that's much smaller than the row with the drag values: image

This is because the color area draws its size from style.spacing.slider_with (which is slightly unintuitive if you haven't looked at the code / know that the area is a slider). This can be scaled up in a child UI

ui.scope(|ui| {
    ui.spacing_mut().slider_width = 220.0;
    egui::widgets::color_picker::color_picker_hsva_2d(
        ui,
        &mut egui_color,
        egui::color_picker::Alpha::Opaque,
    );
});

to get reasonable results: image

However, I don't actually need the ability to change the color format or to copy the color, and would prefer to keep the color slider small.

Describe the solution you'd like I would like the ability to configure the style and layout of the color picker widget, so that you can specify:

I suspect the best way to do this would be to convert it into a formal Widget so that it can be configured and placed as the user requires.

In addition to this, breaking apart the widget into its constituent components and exposing them would help users pick and choose what they want. For example, making color_slider_2d (or its Widget equivalent) public would be perfect for what I need.

Describe alternatives you've considered The only solution I can see that would work externally would be to copy the code from egui or to fork it, neither of which is ideal. A short-term fix would be to make all of the relevant constituent functions public, so that they can be used without using the full color_picker.

Additional context I believe the disparity in size between the color picker and the value row was exacerbated by #2734.

lucasmerlin commented 2 months ago

A proper configurable ColorPicker widget would be neat, that would also be useful in my app.