Implement pure version of PaneGrid widget

This commit is contained in:
Héctor Ramón Jiménez 2022-03-10 19:25:57 +07:00
parent 9f27969d14
commit 6dd187ff08
No known key found for this signature in database
GPG key ID: 140CC052C94F138E
13 changed files with 2107 additions and 417 deletions

View file

@ -4,7 +4,7 @@ use crate::mouse;
use crate::overlay;
use crate::renderer;
use crate::widget::container;
use crate::widget::pane_grid::TitleBar;
use crate::widget::pane_grid::{Draggable, TitleBar};
use crate::{Clipboard, Element, Layout, Point, Rectangle, Shell, Size};
/// The content of a [`Pane`].
@ -101,23 +101,6 @@ where
}
}
/// Returns whether the [`Content`] with the given [`Layout`] can be picked
/// at the provided cursor position.
pub fn can_be_picked_at(
&self,
layout: Layout<'_>,
cursor_position: Point,
) -> bool {
if let Some(title_bar) = &self.title_bar {
let mut children = layout.children();
let title_bar_layout = children.next().unwrap();
title_bar.is_over_pick_area(title_bar_layout, cursor_position)
} else {
false
}
}
pub(crate) fn layout(
&self,
renderer: &Renderer,
@ -253,6 +236,26 @@ where
}
}
impl<'a, Message, Renderer> Draggable for &Content<'a, Message, Renderer>
where
Renderer: crate::Renderer,
{
fn can_be_dragged_at(
&self,
layout: Layout<'_>,
cursor_position: Point,
) -> bool {
if let Some(title_bar) = &self.title_bar {
let mut children = layout.children();
let title_bar_layout = children.next().unwrap();
title_bar.is_over_pick_area(title_bar_layout, cursor_position)
} else {
false
}
}
}
impl<'a, T, Message, Renderer> From<T> for Content<'a, Message, Renderer>
where
T: Into<Element<'a, Message, Renderer>>,