Skip to content

Commit

Permalink
Fix #77
Browse files Browse the repository at this point in the history
  • Loading branch information
genusistimelord committed Feb 21, 2024
1 parent be1fdc3 commit 987617c
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 23 deletions.
18 changes: 18 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,24 @@
"args": [],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug executable 'floating_element_overlay'",
"cargo": {
"args": [
"build",
"--bin=floating_element_overlay",
"--package=floating_element_overlay"
],
"filter": {
"name": "floating_element_overlay",
"kind": "bin"
}
},
"args": [],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ members = [
"examples/date_picker",
"examples/color_picker",
"examples/floating_element",
"examples/floating_element multioverlay",
"examples/floating_element_anchors",
"examples/grid",
"examples/modal",
Expand Down
56 changes: 33 additions & 23 deletions src/native/floating_element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ use super::overlay::floating_element::FloatingElementOverlay;
use iced::{
advanced::{
layout::{Limits, Node},
overlay, renderer,
overlay::{self, Group},
renderer,
widget::{Operation, Tree},
Clipboard, Layout, Shell, Widget,
},
Expand Down Expand Up @@ -212,31 +213,40 @@ where
renderer: &Renderer,
translation: Vector,
) -> Option<overlay::Element<'b, Message, Theme, Renderer>> {
if self.hidden {
return self.underlay.as_widget_mut().overlay(
&mut state.children[0],
layout,
renderer,
translation,
);
let mut group = Group::new();
let mut children = state.children.iter_mut();

if let Some(underlay) = self.underlay
.as_widget_mut()
.overlay(
children
.next()
.expect("missing underlay in floating element"),
layout,
renderer,
translation,
) {
group = group.push(underlay);
}

if state.children.len() == 2 {
let bounds = layout.bounds();

Some(overlay::Element::new(Box::new(
FloatingElementOverlay::new(
layout.position() + translation,
&mut state.children[1],
&mut self.element,
&self.anchor,
&self.offset,
bounds,
),
)))
} else {
None
if !self.hidden {
if let Some(el) = children.next() {
let bounds = layout.bounds();

group = group.push(overlay::Element::new(Box::new(
FloatingElementOverlay::new(
layout.position() + translation,
el,
&mut self.element,
&self.anchor,
&self.offset,
bounds,
),
)));
}
}

Some(group.overlay())
}
}

Expand Down

0 comments on commit 987617c

Please sign in to comment.