From 39ce6a23464493a8299918ca05dc9ac5a2e206bf Mon Sep 17 00:00:00 2001 From: Michael Mauderer Date: Tue, 11 Apr 2023 15:53:34 +0200 Subject: [PATCH] Fix click overlay. --- .../view/execution-mode-selector/src/lib.rs | 2 + .../component/drop-down-menu/src/lib.rs | 44 ++++++++++++------- 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/app/gui/view/execution-mode-selector/src/lib.rs b/app/gui/view/execution-mode-selector/src/lib.rs index e10ca39a8f1c..a5a4caa9bb10 100644 --- a/app/gui/view/execution-mode-selector/src/lib.rs +++ b/app/gui/view/execution-mode-selector/src/lib.rs @@ -208,6 +208,8 @@ impl component::Model for Model { scene.layers.panel.add(÷r); dropdown.set_label_layer(&scene.layers.panel_text); + dropdown.restore_shape_constraints(app); + Self { display_object, background, play_icon, dropdown, inner_root, divider } } diff --git a/lib/rust/ensogl/component/drop-down-menu/src/lib.rs b/lib/rust/ensogl/component/drop-down-menu/src/lib.rs index 4452d1e8a848..9dc4763382f0 100644 --- a/lib/rust/ensogl/component/drop-down-menu/src/lib.rs +++ b/lib/rust/ensogl/component/drop-down-menu/src/lib.rs @@ -75,6 +75,7 @@ pub mod chooser_hover_area { use super::*; ensogl_core::shape! { + above = [arrow]; alignment = center; (style: Style) { let width : Var = "input_size.x".into(); @@ -144,8 +145,8 @@ pub type Entry = list_view::entry::Label; struct Model { display_object: display::object::Instance, - icon: arrow::View, - icon_overlay: chooser_hover_area::View, + icon: arrow::View, + click_overlay: chooser_hover_area::View, label: text::Text, selection_menu: list_view::ListView, @@ -158,17 +159,17 @@ impl Model { fn new(app: &Application) -> Self { let display_object = display::object::Instance::new(); let icon = arrow::View::new(); - let icon_overlay = chooser_hover_area::View::new(); + let click_overlay = chooser_hover_area::View::new(); let selection_menu = list_view::ListView::new(app); let label = app.new_view::(); let content = default(); - Self { display_object, icon, icon_overlay, label, selection_menu, content }.init() + Self { display_object, icon, click_overlay, label, selection_menu, content }.init() } fn init(self) -> Self { self.add_child(&self.icon); - self.add_child(&self.icon_overlay); + self.add_child(&self.click_overlay); self.add_child(&self.label); // Clear default parent and hide again. self.show_selection_menu(); @@ -309,13 +310,17 @@ impl DropDownMenu { model.label.set_y(0.5 * text_height); }); - overlay_size <- all(model.label.frp.width,model.label.frp.height,frp.input.set_icon_size); - eval overlay_size ([model]((text_width,text_height,icon_size)) { + overlay_size <- all( + model.label.frp.width, + model.label.frp.height, + frp.input.set_icon_size, + frp.input.set_icon_padding); + eval overlay_size ([model]((text_width,text_height,icon_size,icon_padding)) { let height = icon_size.y.max(*text_height); - let width = text_width + icon_size.x; + let width = text_width + icon_size.x + icon_padding.x; let size = Vector2::new(width,height); - model.icon_overlay.set_size(size); - model.icon_overlay.set_x(-text_width/2.0); + model.click_overlay.set_size(size); + model.click_overlay.set_x(-width/2.0 + icon_size.x/2.0 - icon_padding.x); }); @@ -380,14 +385,14 @@ impl DropDownMenu { // === Menu Toggle Through Mouse Interaction === icon_hovered <- source::(); - eval_ model.icon_overlay.events_deprecated.mouse_over ( icon_hovered.emit(true) ); - eval_ model.icon_overlay.events_deprecated.mouse_out ( icon_hovered.emit(false) ); + eval_ model.click_overlay.events_deprecated.mouse_over ( icon_hovered.emit(true) ); + eval_ model.click_overlay.events_deprecated.mouse_out ( icon_hovered.emit(false) ); - frp.source.icon_mouse_over <+ model.icon_overlay.events_deprecated.mouse_over; - frp.source.icon_mouse_out <+ model.icon_overlay.events_deprecated.mouse_out; + frp.source.icon_mouse_over <+ model.click_overlay.events_deprecated.mouse_over; + frp.source.icon_mouse_out <+ model.click_overlay.events_deprecated.mouse_out; - let icon_mouse_down = model.icon_overlay.events_deprecated.mouse_down_primary.clone_ref(); + let icon_mouse_down = model.click_overlay.events_deprecated.mouse_down_primary.clone_ref(); visibility_on_mouse_down <- frp.source.menu_visible.sample(&icon_mouse_down) ; eval visibility_on_mouse_down ([show_menu,hide_menu](is_visible){ @@ -426,6 +431,15 @@ impl DropDownMenu { self.model.selection_menu.set_label_layer(layer); self.model.label.add_to_scene_layer(layer); } + + pub fn restore_shape_constraints(&self, app: &Application) { + let scene = &app.display.default_scene; + shapes_order_dependencies! { + scene => { + arrow -> chooser_hover_area; + } + } + } } impl display::Object for DropDownMenu {