summaryrefslogtreecommitdiffstats
path: root/native
diff options
context:
space:
mode:
Diffstat (limited to 'native')
-rw-r--r--native/src/layout.rs9
-rw-r--r--native/src/lib.rs4
-rw-r--r--native/src/renderer/null.rs21
-rw-r--r--native/src/widget/pane_grid.rs98
-rw-r--r--native/src/widget/pane_grid/configuration.rs30
-rw-r--r--native/src/widget/pane_grid/content.rs207
-rw-r--r--native/src/widget/pane_grid/state.rs37
-rw-r--r--native/src/widget/pane_grid/title_bar.rs188
8 files changed, 521 insertions, 73 deletions
diff --git a/native/src/layout.rs b/native/src/layout.rs
index 4a3ab94a..93d95e17 100644
--- a/native/src/layout.rs
+++ b/native/src/layout.rs
@@ -34,7 +34,14 @@ impl<'a> Layout<'a> {
}
}
- /// Gets the bounds of the [`Layout`].
+ /// Returns the position of the [`Layout`].
+ ///
+ /// [`Layout`]: struct.Layout.html
+ pub fn position(&self) -> Point {
+ self.position
+ }
+
+ /// Returns the bounds of the [`Layout`].
///
/// The returned [`Rectangle`] describes the position and size of a
/// [`Node`].
diff --git a/native/src/lib.rs b/native/src/lib.rs
index b67ff2a1..86046f63 100644
--- a/native/src/lib.rs
+++ b/native/src/lib.rs
@@ -30,8 +30,8 @@
//! [`Widget`]: widget/trait.Widget.html
//! [`UserInterface`]: struct.UserInterface.html
//! [renderer]: renderer/index.html
-#![deny(missing_docs)]
-#![deny(missing_debug_implementations)]
+//#![deny(missing_docs)]
+//#![deny(missing_debug_implementations)]
#![deny(unused_results)]
#![forbid(unsafe_code)]
#![forbid(rust_2018_idioms)]
diff --git a/native/src/renderer/null.rs b/native/src/renderer/null.rs
index b8695b9c..29df3e14 100644
--- a/native/src/renderer/null.rs
+++ b/native/src/renderer/null.rs
@@ -1,7 +1,7 @@
use crate::{
- button, checkbox, column, progress_bar, radio, row, scrollable, slider,
- text, text_input, Color, Element, Font, HorizontalAlignment, Layout, Point,
- Rectangle, Renderer, Size, VerticalAlignment,
+ button, checkbox, column, container, progress_bar, radio, row, scrollable,
+ slider, text, text_input, Color, Element, Font, HorizontalAlignment,
+ Layout, Point, Rectangle, Renderer, Size, VerticalAlignment,
};
/// A renderer that does nothing.
@@ -226,3 +226,18 @@ impl progress_bar::Renderer for Null {
) {
}
}
+
+impl container::Renderer for Null {
+ type Style = ();
+
+ fn draw<Message>(
+ &mut self,
+ _defaults: &Self::Defaults,
+ _bounds: Rectangle,
+ _cursor_position: Point,
+ _style: &Self::Style,
+ _content: &Element<'_, Message, Self>,
+ _content_layout: Layout<'_>,
+ ) {
+ }
+}
diff --git a/native/src/widget/pane_grid.rs b/native/src/widget/pane_grid.rs
index f8788932..8fb6c20c 100644
--- a/native/src/widget/pane_grid.rs
+++ b/native/src/widget/pane_grid.rs
@@ -9,24 +9,28 @@
//! [`pane_grid` example]: https://github.com/hecrj/iced/tree/0.1/examples/pane_grid
//! [`PaneGrid`]: struct.PaneGrid.html
mod axis;
+mod configuration;
mod content;
mod direction;
mod node;
mod pane;
mod split;
mod state;
+mod title_bar;
pub use axis::Axis;
+pub use configuration::Configuration;
pub use content::Content;
pub use direction::Direction;
pub use node::Node;
pub use pane::Pane;
pub use split::Split;
pub use state::{Focus, State};
+pub use title_bar::TitleBar;
use crate::{
- keyboard, layout, mouse, Clipboard, Element, Event, Hasher, Layout, Length,
- Point, Rectangle, Size, Widget,
+ container, keyboard, layout, mouse, row, Clipboard, Element, Event, Hasher,
+ Layout, Length, Point, Rectangle, Size, Widget,
};
/// A collection of panes distributed using either vertical or horizontal splits
@@ -70,10 +74,10 @@ use crate::{
///
/// let pane_grid =
/// PaneGrid::new(&mut state, |pane, state, focus| {
-/// match state {
+/// pane_grid::Content::new(match state {
/// PaneState::SomePane => Text::new("This is some pane"),
/// PaneState::AnotherKindOfPane => Text::new("This is another kind of pane"),
-/// }.into()
+/// })
/// })
/// .on_drag(Message::PaneDragged)
/// .on_resize(10, Message::PaneResized);
@@ -82,10 +86,10 @@ use crate::{
/// [`PaneGrid`]: struct.PaneGrid.html
/// [`State`]: struct.State.html
#[allow(missing_debug_implementations)]
-pub struct PaneGrid<'a, Message, Renderer> {
+pub struct PaneGrid<'a, Message, Renderer: container::Renderer> {
state: &'a mut state::Internal,
pressed_modifiers: &'a mut keyboard::ModifiersState,
- elements: Vec<(Pane, Element<'a, Message, Renderer>)>,
+ elements: Vec<(Pane, Content<'a, Message, Renderer>)>,
width: Length,
height: Length,
spacing: u16,
@@ -95,7 +99,10 @@ pub struct PaneGrid<'a, Message, Renderer> {
on_key_press: Option<Box<dyn Fn(KeyPressEvent) -> Option<Message> + 'a>>,
}
-impl<'a, Message, Renderer> PaneGrid<'a, Message, Renderer> {
+impl<'a, Message, Renderer> PaneGrid<'a, Message, Renderer>
+where
+ Renderer: container::Renderer,
+{
/// Creates a [`PaneGrid`] with the given [`State`] and view function.
///
/// The view function will be called to display each [`Pane`] present in the
@@ -110,7 +117,7 @@ impl<'a, Message, Renderer> PaneGrid<'a, Message, Renderer> {
Pane,
&'a mut T,
Option<Focus>,
- ) -> Element<'a, Message, Renderer>,
+ ) -> Content<'a, Message, Renderer>,
) -> Self {
let elements = {
let action = state.internal.action();
@@ -194,8 +201,6 @@ impl<'a, Message, Renderer> PaneGrid<'a, Message, Renderer> {
/// Enables the drag and drop interactions of the [`PaneGrid`], which will
/// use the provided function to produce messages.
///
- /// Panes can be dragged using `Modifier keys + Left click`.
- ///
/// [`PaneGrid`]: struct.PaneGrid.html
pub fn on_drag<F>(mut self, f: F) -> Self
where
@@ -244,7 +249,12 @@ impl<'a, Message, Renderer> PaneGrid<'a, Message, Renderer> {
self.on_key_press = Some(Box::new(f));
self
}
+}
+impl<'a, Message, Renderer> PaneGrid<'a, Message, Renderer>
+where
+ Renderer: self::Renderer,
+{
fn click_pane(
&mut self,
layout: Layout<'_>,
@@ -256,16 +266,21 @@ impl<'a, Message, Renderer> PaneGrid<'a, Message, Renderer> {
|(_, layout)| layout.bounds().contains(cursor_position),
);
- if let Some(((pane, _), _)) = clicked_region.next() {
+ if let Some(((pane, content), layout)) = clicked_region.next() {
match &self.on_drag {
- Some(on_drag)
- if self.pressed_modifiers.matches(self.modifier_keys) =>
- {
- self.state.pick_pane(pane);
-
- messages.push(on_drag(DragEvent::Picked { pane: *pane }));
+ Some(on_drag) => {
+ if let Some(origin) =
+ content.drag_origin(layout, cursor_position)
+ {
+ self.state.pick_pane(pane, origin);
+
+ messages
+ .push(on_drag(DragEvent::Picked { pane: *pane }));
+ } else {
+ self.state.focus(pane);
+ }
}
- _ => {
+ None => {
self.state.focus(pane);
}
}
@@ -388,7 +403,7 @@ pub struct KeyPressEvent {
impl<'a, Message, Renderer> Widget<Message, Renderer>
for PaneGrid<'a, Message, Renderer>
where
- Renderer: self::Renderer,
+ Renderer: self::Renderer + container::Renderer,
{
fn width(&self) -> Length {
self.width
@@ -481,7 +496,7 @@ where
}
}
mouse::Event::ButtonReleased(mouse::Button::Left) => {
- if let Some(pane) = self.state.picked_pane() {
+ if let Some((pane, _)) = self.state.picked_pane() {
self.state.focus(&pane);
if let Some(on_drag) = &self.on_drag {
@@ -551,7 +566,7 @@ where
{
self.elements.iter_mut().zip(layout.children()).for_each(
|((_, pane), layout)| {
- pane.widget.on_event(
+ pane.on_event(
event.clone(),
layout,
cursor_position,
@@ -598,7 +613,8 @@ where
})
.map(|(_, axis)| axis);
- renderer.draw(
+ self::Renderer::draw(
+ renderer,
defaults,
&self.elements,
self.state.picked_pane(),
@@ -630,7 +646,7 @@ where
///
/// [`PaneGrid`]: struct.PaneGrid.html
/// [renderer]: ../../renderer/index.html
-pub trait Renderer: crate::Renderer + Sized {
+pub trait Renderer: crate::Renderer + container::Renderer + Sized {
/// Draws a [`PaneGrid`].
///
/// It receives:
@@ -646,18 +662,48 @@ pub trait Renderer: crate::Renderer + Sized {
fn draw<Message>(
&mut self,
defaults: &Self::Defaults,
- content: &[(Pane, Element<'_, Message, Self>)],
- dragging: Option<Pane>,
+ content: &[(Pane, Content<'_, Message, Self>)],
+ dragging: Option<(Pane, Point)>,
resizing: Option<Axis>,
layout: Layout<'_>,
cursor_position: Point,
) -> Self::Output;
+
+ /// Draws a [`Pane`].
+ ///
+ /// It receives:
+ /// - the [`TitleBar`] of the [`Pane`], if any
+ /// - the [`Content`] of the [`Pane`]
+ /// - the [`Layout`] of the [`Pane`] and its elements
+ /// - the cursor position
+ ///
+ /// [`Pane`]: struct.Pane.html
+ /// [`Layout`]: ../layout/struct.Layout.html
+ fn draw_pane<Message>(
+ &mut self,
+ defaults: &Self::Defaults,
+ bounds: Rectangle,
+ style: &Self::Style,
+ title_bar: Option<(&TitleBar<'_, Message, Self>, Layout<'_>)>,
+ body: (&Element<'_, Message, Self>, Layout<'_>),
+ cursor_position: Point,
+ ) -> Self::Output;
+
+ fn draw_title_bar<Message>(
+ &mut self,
+ defaults: &Self::Defaults,
+ bounds: Rectangle,
+ style: &Self::Style,
+ title: (&Element<'_, Message, Self>, Layout<'_>),
+ controls: Option<(&Element<'_, Message, Self>, Layout<'_>)>,
+ cursor_position: Point,
+ ) -> Self::Output;
}
impl<'a, Message, Renderer> From<PaneGrid<'a, Message, Renderer>>
for Element<'a, Message, Renderer>
where
- Renderer: 'a + self::Renderer,
+ Renderer: 'a + self::Renderer + row::Renderer,
Message: 'a,
{
fn from(
diff --git a/native/src/widget/pane_grid/configuration.rs b/native/src/widget/pane_grid/configuration.rs
new file mode 100644
index 00000000..1fed98b7
--- /dev/null
+++ b/native/src/widget/pane_grid/configuration.rs
@@ -0,0 +1,30 @@
+use crate::pane_grid::Axis;
+
+/// The arrangement of a [`PaneGrid`].
+///
+/// [`PaneGrid`]: struct.PaneGrid.html
+#[derive(Debug, Clone)]
+pub enum Configuration<T> {
+ /// A split of the available space.
+ Split {
+ /// The direction of the split.
+ axis: Axis,
+
+ /// The ratio of the split in [0.0, 1.0].
+ ratio: f32,
+
+ /// The left/top [`Content`] of the split.
+ ///
+ /// [`Configuration`]: enum.Node.html
+ a: Box<Configuration<T>>,
+
+ /// The right/bottom [`Content`] of the split.
+ ///
+ /// [`Configuration`]: enum.Node.html
+ b: Box<Configuration<T>>,
+ },
+ /// A [`Pane`].
+ ///
+ /// [`Pane`]: struct.Pane.html
+ Pane(T),
+}
diff --git a/native/src/widget/pane_grid/content.rs b/native/src/widget/pane_grid/content.rs
index 8822083e..843dcec4 100644
--- a/native/src/widget/pane_grid/content.rs
+++ b/native/src/widget/pane_grid/content.rs
@@ -1,30 +1,185 @@
-use crate::pane_grid::Axis;
+use crate::container;
+use crate::layout;
+use crate::pane_grid::{self, TitleBar};
+use crate::{Clipboard, Element, Event, Hasher, Layout, Point, Size, Vector};
-/// The content of a [`PaneGrid`].
+/// The content of a [`Pane`].
///
-/// [`PaneGrid`]: struct.PaneGrid.html
-#[derive(Debug, Clone)]
-pub enum Content<T> {
- /// A split of the available space.
- Split {
- /// The direction of the split.
- axis: Axis,
-
- /// The ratio of the split in [0.0, 1.0].
- ratio: f32,
-
- /// The left/top [`Content`] of the split.
- ///
- /// [`Content`]: enum.Node.html
- a: Box<Content<T>>,
-
- /// The right/bottom [`Content`] of the split.
- ///
- /// [`Content`]: enum.Node.html
- b: Box<Content<T>>,
- },
- /// A [`Pane`].
+/// [`Pane`]: struct.Pane.html
+pub struct Content<'a, Message, Renderer: container::Renderer> {
+ title_bar: Option<TitleBar<'a, Message, Renderer>>,
+ body: Element<'a, Message, Renderer>,
+ style: Renderer::Style,
+}
+
+impl<'a, Message, Renderer> Content<'a, Message, Renderer>
+where
+ Renderer: container::Renderer,
+{
+ pub fn new(body: impl Into<Element<'a, Message, Renderer>>) -> Self {
+ Self {
+ title_bar: None,
+ body: body.into(),
+ style: Renderer::Style::default(),
+ }
+ }
+
+ pub fn title_bar(
+ mut self,
+ title_bar: TitleBar<'a, Message, Renderer>,
+ ) -> Self {
+ self.title_bar = Some(title_bar);
+ self
+ }
+
+ /// Sets the style of the [`TitleBar`].
///
- /// [`Pane`]: struct.Pane.html
- Pane(T),
+ /// [`TitleBar`]: struct.TitleBar.html
+ pub fn style(mut self, style: impl Into<Renderer::Style>) -> Self {
+ self.style = style.into();
+ self
+ }
+}
+
+impl<'a, Message, Renderer> Content<'a, Message, Renderer>
+where
+ Renderer: pane_grid::Renderer + container::Renderer,
+{
+ pub fn draw(
+ &self,
+ renderer: &mut Renderer,
+ defaults: &Renderer::Defaults,
+ layout: Layout<'_>,
+ cursor_position: Point,
+ ) -> Renderer::Output {
+ if let Some(title_bar) = &self.title_bar {
+ let mut children = layout.children();
+ let title_bar_layout = children.next().unwrap();
+ let body_layout = children.next().unwrap();
+
+ renderer.draw_pane(
+ defaults,
+ layout.bounds(),
+ &self.style,
+ Some((title_bar, title_bar_layout)),
+ (&self.body, body_layout),
+ cursor_position,
+ )
+ } else {
+ renderer.draw_pane(
+ defaults,
+ layout.bounds(),
+ &self.style,
+ None,
+ (&self.body, layout),
+ cursor_position,
+ )
+ }
+ }
+
+ pub fn drag_origin(
+ &self,
+ layout: Layout<'_>,
+ cursor_position: Point,
+ ) -> Option<Point> {
+ if let Some(title_bar) = &self.title_bar {
+ let mut children = layout.children();
+ let title_bar_layout = children.next().unwrap();
+
+ if title_bar.is_over_draggable(title_bar_layout, cursor_position) {
+ let position = layout.position();
+
+ Some(cursor_position - Vector::new(position.x, position.y))
+ } else {
+ None
+ }
+ } else {
+ None
+ }
+ }
+
+ pub(crate) fn layout(
+ &self,
+ renderer: &Renderer,
+ limits: &layout::Limits,
+ ) -> layout::Node {
+ if let Some(title_bar) = &self.title_bar {
+ let max_size = limits.max();
+
+ let title_bar_layout = title_bar
+ .layout(renderer, &layout::Limits::new(Size::ZERO, max_size));
+
+ let title_bar_size = title_bar_layout.size();
+
+ let mut body_layout = self.body.layout(
+ renderer,
+ &layout::Limits::new(
+ Size::ZERO,
+ Size::new(
+ max_size.width,
+ max_size.height - title_bar_size.height,
+ ),
+ ),
+ );
+
+ body_layout.move_to(Point::new(0.0, title_bar_size.height));
+
+ layout::Node::with_children(
+ max_size,
+ vec![title_bar_layout, body_layout],
+ )
+ } else {
+ self.body.layout(renderer, limits)
+ }
+ }
+
+ pub(crate) fn on_event(
+ &mut self,
+ event: Event,
+ layout: Layout<'_>,
+ cursor_position: Point,
+ messages: &mut Vec<Message>,
+ renderer: &Renderer,
+ clipboard: Option<&dyn Clipboard>,
+ ) {
+ let body_layout = if let Some(title_bar) = &mut self.title_bar {
+ let mut children = layout.children();
+
+ title_bar.on_event(
+ event.clone(),
+ children.next().unwrap(),
+ cursor_position,
+ messages,
+ renderer,
+ clipboard,
+ );
+
+ children.next().unwrap()
+ } else {
+ layout
+ };
+
+ self.body.on_event(
+ event,
+ body_layout,
+ cursor_position,
+ messages,
+ renderer,
+ clipboard,
+ );
+ }
+
+ pub(crate) fn hash_layout(&self, state: &mut Hasher) {
+ self.body.hash_layout(state);
+ }
+}
+
+impl<'a, T, Message, Renderer> From<T> for Content<'a, Message, Renderer>
+where
+ T: Into<Element<'a, Message, Renderer>>,
+ Renderer: pane_grid::Renderer + container::Renderer,
+{
+ fn from(element: T) -> Self {
+ Self::new(element)
+ }
}
diff --git a/native/src/widget/pane_grid/state.rs b/native/src/widget/pane_grid/state.rs
index 4b13fb8e..a8431dec 100644
--- a/native/src/widget/pane_grid/state.rs
+++ b/native/src/widget/pane_grid/state.rs
@@ -1,6 +1,6 @@
use crate::{
keyboard,
- pane_grid::{Axis, Content, Direction, Node, Pane, Split},
+ pane_grid::{Axis, Configuration, Direction, Node, Pane, Split},
Hasher, Point, Rectangle, Size,
};
@@ -53,18 +53,21 @@ impl<T> State<T> {
/// [`State`]: struct.State.html
/// [`Pane`]: struct.Pane.html
pub fn new(first_pane_state: T) -> (Self, Pane) {
- (Self::with_content(Content::Pane(first_pane_state)), Pane(0))
+ (
+ Self::with_configuration(Configuration::Pane(first_pane_state)),
+ Pane(0),
+ )
}
- /// Creates a new [`State`] with the given [`Content`].
+ /// Creates a new [`State`] with the given [`Configuration`].
///
/// [`State`]: struct.State.html
- /// [`Content`]: enum.Content.html
- pub fn with_content(content: impl Into<Content<T>>) -> Self {
+ /// [`Configuration`]: enum.Configuration.html
+ pub fn with_configuration(config: impl Into<Configuration<T>>) -> Self {
let mut panes = HashMap::new();
let (layout, last_id) =
- Self::distribute_content(&mut panes, content.into(), 0);
+ Self::distribute_content(&mut panes, config.into(), 0);
State {
panes,
@@ -274,11 +277,11 @@ impl<T> State<T> {
fn distribute_content(
panes: &mut HashMap<Pane, T>,
- content: Content<T>,
+ content: Configuration<T>,
next_id: usize,
) -> (Node, usize) {
match content {
- Content::Split { axis, ratio, a, b } => {
+ Configuration::Split { axis, ratio, a, b } => {
let (a, next_id) = Self::distribute_content(panes, *a, next_id);
let (b, next_id) = Self::distribute_content(panes, *b, next_id);
@@ -293,7 +296,7 @@ impl<T> State<T> {
next_id + 1,
)
}
- Content::Pane(state) => {
+ Configuration::Pane(state) => {
let id = Pane(next_id);
let _ = panes.insert(id, state);
@@ -310,13 +313,14 @@ pub struct Internal {
action: Action,
}
-#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+#[derive(Debug, Clone, Copy, PartialEq)]
pub enum Action {
Idle {
focus: Option<Pane>,
},
Dragging {
pane: Pane,
+ origin: Point,
},
Resizing {
split: Split,
@@ -331,7 +335,7 @@ impl Action {
Action::Idle { focus } | Action::Resizing { focus, .. } => {
focus.map(|pane| (pane, Focus::Idle))
}
- Action::Dragging { pane } => Some((*pane, Focus::Dragging)),
+ Action::Dragging { pane, .. } => Some((*pane, Focus::Dragging)),
}
}
}
@@ -348,9 +352,9 @@ impl Internal {
}
}
- pub fn picked_pane(&self) -> Option<Pane> {
+ pub fn picked_pane(&self) -> Option<(Pane, Point)> {
match self.action {
- Action::Dragging { pane } => Some(pane),
+ Action::Dragging { pane, origin } => Some((pane, origin)),
_ => None,
}
}
@@ -382,8 +386,11 @@ impl Internal {
self.action = Action::Idle { focus: Some(*pane) };
}
- pub fn pick_pane(&mut self, pane: &Pane) {
- self.action = Action::Dragging { pane: *pane };
+ pub fn pick_pane(&mut self, pane: &Pane, origin: Point) {
+ self.action = Action::Dragging {
+ pane: *pane,
+ origin,
+ };
}
pub fn pick_split(&mut self, split: &Split, axis: Axis) {
diff --git a/native/src/widget/pane_grid/title_bar.rs b/native/src/widget/pane_grid/title_bar.rs
new file mode 100644
index 00000000..dc96dcbf
--- /dev/null
+++ b/native/src/widget/pane_grid/title_bar.rs
@@ -0,0 +1,188 @@
+use crate::container;
+use crate::layout;
+use crate::pane_grid;
+use crate::{Clipboard, Element, Event, Layout, Point, Size};
+
+pub struct TitleBar<'a, Message, Renderer: container::Renderer> {
+ title: Element<'a, Message, Renderer>,
+ controls: Option<Element<'a, Message, Renderer>>,
+ padding: u16,
+ style: Renderer::Style,
+}
+
+impl<'a, Message, Renderer> TitleBar<'a, Message, Renderer>
+where
+ Renderer: container::Renderer,
+{
+ pub fn new(title: impl Into<Element<'a, Message, Renderer>>) -> Self {
+ Self {
+ title: title.into(),
+ controls: None,
+ padding: 0,
+ style: Renderer::Style::default(),
+ }
+ }
+
+ pub fn controls(
+ mut self,
+ controls: impl Into<Element<'a, Message, Renderer>>,
+ ) -> Self {
+ self.controls = Some(controls.into());
+ self
+ }
+
+ /// Sets the padding of the [`TitleBar`].
+ ///
+ /// [`TitleBar`]: struct.TitleBar.html
+ pub fn padding(mut self, units: u16) -> Self {
+ self.padding = units;
+ self
+ }
+
+ /// Sets the style of the [`TitleBar`].
+ ///
+ /// [`TitleBar`]: struct.TitleBar.html
+ pub fn style(mut self, style: impl Into<Renderer::Style>) -> Self {
+ self.style = style.into();
+ self
+ }
+}
+
+impl<'a, Message, Renderer> TitleBar<'a, Message, Renderer>
+where
+ Renderer: pane_grid::Renderer,
+{
+ pub fn draw(
+ &self,
+ renderer: &mut Renderer,
+ defaults: &Renderer::Defaults,
+ layout: Layout<'_>,
+ cursor_position: Point,
+ show_controls: bool,
+ ) -> Renderer::Output {
+ let mut children = layout.children();
+ let padded = children.next().unwrap();
+
+ if let Some(controls) = &self.controls {
+ let mut children = padded.children();
+ let title_layout = children.next().unwrap();
+ let controls_layout = children.next().unwrap();
+
+ renderer.draw_title_bar(
+ defaults,
+ layout.bounds(),
+ &self.style,
+ (&self.title, title_layout),
+ if show_controls {
+ Some((controls, controls_layout))
+ } else {
+ None
+ },
+ cursor_position,
+ )
+ } else {
+ renderer.draw_title_bar(
+ defaults,
+ layout.bounds(),
+ &self.style,
+ (&self.title, padded),
+ None,
+ cursor_position,
+ )
+ }
+ }
+
+ pub fn is_over_draggable(
+ &self,
+ layout: Layout<'_>,
+ cursor_position: Point,
+ ) -> bool {
+ if layout.bounds().contains(cursor_position) {
+ let mut children = layout.children();
+ let padded = children.next().unwrap();
+
+ if self.controls.is_some() {
+ let mut children = padded.children();
+ let _ = children.next().unwrap();
+ let controls_layout = children.next().unwrap();
+
+ !controls_layout.bounds().contains(cursor_position)
+ } else {
+ true
+ }
+ } else {
+ false
+ }
+ }
+
+ pub(crate) fn layout(
+ &self,
+ renderer: &Renderer,
+ limits: &layout::Limits,
+ ) -> layout::Node {
+ let padding = f32::from(self.padding);
+ let limits = limits.pad(padding);
+
+ let node = if let Some(controls) = &self.controls {
+ let max_size = limits.max();
+
+ let mut controls_layout = controls
+ .layout(renderer, &layout::Limits::new(Size::ZERO, max_size));
+
+ let controls_size = controls_layout.size();
+ let space_before_controls = max_size.width - controls_size.width;
+
+ let mut title_layout = self.title.layout(
+ renderer,
+ &layout::Limits::new(
+ Size::ZERO,
+ Size::new(space_before_controls, max_size.height),
+ ),
+ );
+
+ title_layout.move_to(Point::new(padding, padding));
+ controls_layout
+ .move_to(Point::new(space_before_controls + padding, padding));
+
+ let title_size = title_layout.size();
+ let height = title_size.height.max(controls_size.height);
+
+ layout::Node::with_children(
+ Size::new(max_size.width, height),
+ vec![title_layout, controls_layout],
+ )
+ } else {
+ self.title.layout(renderer, &limits)
+ };
+
+ layout::Node::with_children(node.size().pad(padding), vec![node])
+ }
+
+ pub(crate) fn on_event(
+ &mut self,
+ event: Event,
+ layout: Layout<'_>,
+ cursor_position: Point,
+ messages: &mut Vec<Message>,
+ renderer: &Renderer,
+ clipboard: Option<&dyn Clipboard>,
+ ) {
+ if let Some(controls) = &mut self.controls {
+ let mut children = layout.children();
+ let padded = children.next().unwrap();
+
+ let mut children = padded.children();
+ let _ = children.next();
+ let controls_layout = children.next().unwrap();
+
+ controls.on_event(
+ event,
+ controls_layout,
+ cursor_position,
+ messages,
+ renderer,
+ clipboard,
+ );
+ }
+ }
+}