|
2 | 2 |
|
3 | 3 | use crate::util::fixed_cache::FixedCache;
|
4 | 4 | use crate::{
|
5 |
| - epaint, lerp, remap_clamp, Area, Context, DragValue, Frame, Id, Key, Order, Painter, Response, |
6 |
| - Sense, Ui, UiKind, Widget as _, WidgetInfo, WidgetType, |
| 5 | + epaint, lerp, remap_clamp, Context, DragValue, Id, Painter, Popup, PopupCloseBehavior, |
| 6 | + Response, Sense, Ui, Widget as _, WidgetInfo, WidgetType, |
7 | 7 | };
|
8 | 8 | use epaint::{
|
9 | 9 | ecolor::{Color32, Hsva, HsvaGamma, Rgba},
|
@@ -496,35 +496,17 @@ pub fn color_edit_button_hsva(ui: &mut Ui, hsva: &mut Hsva, alpha: Alpha) -> Res
|
496 | 496 | button_response = button_response.on_hover_text("Click to edit color");
|
497 | 497 | }
|
498 | 498 |
|
499 |
| - if button_response.clicked() { |
500 |
| - ui.memory_mut(|mem| mem.toggle_popup(popup_id)); |
501 |
| - } |
502 |
| - |
503 | 499 | const COLOR_SLIDER_WIDTH: f32 = 275.0;
|
504 | 500 |
|
505 |
| - // TODO(lucasmerlin): Update this to use new Popup struct |
506 |
| - if ui.memory(|mem| mem.is_popup_open(popup_id)) { |
507 |
| - ui.memory_mut(|mem| mem.keep_popup_open(popup_id)); |
508 |
| - let area_response = Area::new(popup_id) |
509 |
| - .kind(UiKind::Picker) |
510 |
| - .order(Order::Foreground) |
511 |
| - .fixed_pos(button_response.rect.max) |
512 |
| - .show(ui.ctx(), |ui| { |
513 |
| - ui.spacing_mut().slider_width = COLOR_SLIDER_WIDTH; |
514 |
| - Frame::popup(ui.style()).show(ui, |ui| { |
515 |
| - if color_picker_hsva_2d(ui, hsva, alpha) { |
516 |
| - button_response.mark_changed(); |
517 |
| - } |
518 |
| - }); |
519 |
| - }) |
520 |
| - .response; |
521 |
| - |
522 |
| - if !button_response.clicked() |
523 |
| - && (ui.input(|i| i.key_pressed(Key::Escape)) || area_response.clicked_elsewhere()) |
524 |
| - { |
525 |
| - ui.memory_mut(|mem| mem.close_popup(popup_id)); |
526 |
| - } |
527 |
| - } |
| 501 | + Popup::menu(&button_response) |
| 502 | + .id(popup_id) |
| 503 | + .close_behavior(PopupCloseBehavior::CloseOnClickOutside) |
| 504 | + .show(|ui| { |
| 505 | + ui.spacing_mut().slider_width = COLOR_SLIDER_WIDTH; |
| 506 | + if color_picker_hsva_2d(ui, hsva, alpha) { |
| 507 | + button_response.mark_changed(); |
| 508 | + } |
| 509 | + }); |
528 | 510 |
|
529 | 511 | button_response
|
530 | 512 | }
|
|
0 commit comments