Use the new Popup api for the color picker button (#7137)
The color picker popup is now aligned to the bottom left edge (instead of the bottom right), but I think this makes more sense and is aligned with ComboBox etc. It also gets the new nice auto positioning. * closes #5832 * [x] I have followed the instructions in the PR template
This commit is contained in:
parent
0152a87519
commit
c8b844cd83
|
|
@ -2,8 +2,8 @@
|
||||||
|
|
||||||
use crate::util::fixed_cache::FixedCache;
|
use crate::util::fixed_cache::FixedCache;
|
||||||
use crate::{
|
use crate::{
|
||||||
epaint, lerp, remap_clamp, Area, Context, DragValue, Frame, Id, Key, Order, Painter, Response,
|
epaint, lerp, remap_clamp, Context, DragValue, Id, Painter, Popup, PopupCloseBehavior,
|
||||||
Sense, Ui, UiKind, Widget as _, WidgetInfo, WidgetType,
|
Response, Sense, Ui, Widget as _, WidgetInfo, WidgetType,
|
||||||
};
|
};
|
||||||
use epaint::{
|
use epaint::{
|
||||||
ecolor::{Color32, Hsva, HsvaGamma, Rgba},
|
ecolor::{Color32, Hsva, HsvaGamma, Rgba},
|
||||||
|
|
@ -496,35 +496,17 @@ pub fn color_edit_button_hsva(ui: &mut Ui, hsva: &mut Hsva, alpha: Alpha) -> Res
|
||||||
button_response = button_response.on_hover_text("Click to edit color");
|
button_response = button_response.on_hover_text("Click to edit color");
|
||||||
}
|
}
|
||||||
|
|
||||||
if button_response.clicked() {
|
|
||||||
ui.memory_mut(|mem| mem.toggle_popup(popup_id));
|
|
||||||
}
|
|
||||||
|
|
||||||
const COLOR_SLIDER_WIDTH: f32 = 275.0;
|
const COLOR_SLIDER_WIDTH: f32 = 275.0;
|
||||||
|
|
||||||
// TODO(lucasmerlin): Update this to use new Popup struct
|
Popup::menu(&button_response)
|
||||||
if ui.memory(|mem| mem.is_popup_open(popup_id)) {
|
.id(popup_id)
|
||||||
ui.memory_mut(|mem| mem.keep_popup_open(popup_id));
|
.close_behavior(PopupCloseBehavior::CloseOnClickOutside)
|
||||||
let area_response = Area::new(popup_id)
|
.show(|ui| {
|
||||||
.kind(UiKind::Picker)
|
ui.spacing_mut().slider_width = COLOR_SLIDER_WIDTH;
|
||||||
.order(Order::Foreground)
|
if color_picker_hsva_2d(ui, hsva, alpha) {
|
||||||
.fixed_pos(button_response.rect.max)
|
button_response.mark_changed();
|
||||||
.show(ui.ctx(), |ui| {
|
}
|
||||||
ui.spacing_mut().slider_width = COLOR_SLIDER_WIDTH;
|
});
|
||||||
Frame::popup(ui.style()).show(ui, |ui| {
|
|
||||||
if color_picker_hsva_2d(ui, hsva, alpha) {
|
|
||||||
button_response.mark_changed();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.response;
|
|
||||||
|
|
||||||
if !button_response.clicked()
|
|
||||||
&& (ui.input(|i| i.key_pressed(Key::Escape)) || area_response.clicked_elsewhere())
|
|
||||||
{
|
|
||||||
ui.memory_mut(|mem| mem.close_popup(popup_id));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
button_response
|
button_response
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue