From b4671fb251bab1c5fcf57b9968cd4f2fff6fb33f Mon Sep 17 00:00:00 2001 From: genusistimelord Date: Wed, 8 Nov 2023 10:30:09 -0500 Subject: [PATCH] Fixed context menu --- .vscode/launch.json | 18 ++++++++++++++++++ Cargo.toml | 10 +++++----- src/native/context_menu.rs | 6 ++++-- src/native/overlay/context_menu.rs | 7 +++++-- src/native/quad.rs | 2 +- src/native/segmented_button.rs | 7 +++++-- 6 files changed, 38 insertions(+), 12 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 5b94a8d7..f84a46b4 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -22,6 +22,24 @@ "args": [], "cwd": "${workspaceFolder}" }, + { + "type": "lldb", + "request": "launch", + "name": "Debug executable 'segmented_button'", + "cargo": { + "args": [ + "build", + "--bin=segmented_button", + "--package=segmented_button" + ], + "filter": { + "name": "segmented_button", + "kind": "bin" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + }, { "type": "lldb", "request": "launch", diff --git a/Cargo.toml b/Cargo.toml index 4e8ee070..f727ef88 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -54,11 +54,11 @@ default = [ "selection_list", "split", #"menu", - #"quad", - #"context_menu", + "quad", + "context_menu", "spinner", "cupertino", - #"segmented_button", + "segmented_button", ] [dependencies] @@ -102,9 +102,9 @@ members = [ "examples/split_scroller", #"examples/menu", "examples/spinner", - #"examples/context_menu", + "examples/context_menu", #"examples/WidgetIDReturn", - #"examples/segmented_button", + "examples/segmented_button", ] [workspace.dependencies.iced] diff --git a/src/native/context_menu.rs b/src/native/context_menu.rs index 7b60d001..93127a74 100644 --- a/src/native/context_menu.rs +++ b/src/native/context_menu.rs @@ -95,8 +95,10 @@ where self.underlay.as_widget().height() } - fn layout(&self, renderer: &Renderer, limits: &Limits) -> Node { - self.underlay.as_widget().layout(renderer, limits) + fn layout(&self, tree: &mut Tree, renderer: &Renderer, limits: &Limits) -> Node { + self.underlay + .as_widget() + .layout(&mut tree.children[0], renderer, limits) } fn draw( diff --git a/src/native/overlay/context_menu.rs b/src/native/overlay/context_menu.rs index 34ee7911..0c2caad7 100644 --- a/src/native/overlay/context_menu.rs +++ b/src/native/overlay/context_menu.rs @@ -70,11 +70,14 @@ where Renderer: 'a + core::Renderer, Renderer::Theme: StyleSheet, { - fn layout(&self, renderer: &Renderer, bounds: Size, position: Point) -> Node { + fn layout(&mut self, renderer: &Renderer, bounds: Size, position: Point) -> Node { let limits = Limits::new(Size::ZERO, bounds); let max_size = limits.max(); - let mut content = self.content.as_widget().layout(renderer, &limits); + let mut content = self + .content + .as_widget() + .layout(self.tree, renderer, &limits); // Try to stay inside borders let mut position = position; diff --git a/src/native/quad.rs b/src/native/quad.rs index 6946eb34..962a6486 100644 --- a/src/native/quad.rs +++ b/src/native/quad.rs @@ -115,7 +115,7 @@ where self.height } - fn layout(&self, _renderer: &Renderer, limits: &Limits) -> Node { + fn layout(&self, _tree: &mut Tree, _renderer: &Renderer, limits: &Limits) -> Node { let limits = limits.width(self.width).height(self.height); Node::new(limits.max()) } diff --git a/src/native/segmented_button.rs b/src/native/segmented_button.rs index ef02d26e..e716a47c 100644 --- a/src/native/segmented_button.rs +++ b/src/native/segmented_button.rs @@ -141,7 +141,7 @@ where self.height } - fn layout(&self, renderer: &Renderer, limits: &Limits) -> Node { + fn layout(&self, tree: &mut Tree, renderer: &Renderer, limits: &Limits) -> Node { let padding = self.padding; let limits = limits .loose() @@ -149,7 +149,10 @@ where .height(self.height) .pad(padding); - let mut content = self.content.as_widget().layout(renderer, &limits.loose()); + let mut content = + self.content + .as_widget() + .layout(&mut tree.children[0], renderer, &limits.loose()); let size = limits.resolve(content.size()); content.move_to(Point::new(padding.left, padding.top));