Skip to content

Commit

Permalink
Fixed context menu
Browse files Browse the repository at this point in the history
  • Loading branch information
genusistimelord committed Nov 8, 2023
1 parent 14850b9 commit b4671fb
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 12 deletions.
18 changes: 18 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ default = [
"selection_list",
"split",
#"menu",
#"quad",
#"context_menu",
"quad",
"context_menu",
"spinner",
"cupertino",
#"segmented_button",
"segmented_button",
]

[dependencies]
Expand Down Expand Up @@ -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]
Expand Down
6 changes: 4 additions & 2 deletions src/native/context_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
7 changes: 5 additions & 2 deletions src/native/overlay/context_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/native/quad.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down
7 changes: 5 additions & 2 deletions src/native/segmented_button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,18 @@ 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()
.width(self.width)
.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));
Expand Down

0 comments on commit b4671fb

Please sign in to comment.