Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Operations within PaneGrid #1533

Merged
merged 1 commit into from
Nov 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions native/src/widget/pane_grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ use crate::mouse;
use crate::overlay;
use crate::renderer;
use crate::touch;
use crate::widget;
use crate::widget::container;
use crate::widget::tree::{self, Tree};
use crate::{
Expand Down Expand Up @@ -289,6 +290,23 @@ where
)
}

fn operate(
&self,
tree: &mut Tree,
layout: Layout<'_>,
operation: &mut dyn widget::Operation<Message>,
) {
operation.container(None, &mut |operation| {
self.contents
.iter()
.zip(&mut tree.children)
.zip(layout.children())
.for_each(|(((_pane, content), state), layout)| {
content.operate(state, layout, operation);
})
});
}

fn on_event(
&mut self,
tree: &mut Tree,
Expand Down
29 changes: 28 additions & 1 deletion native/src/widget/pane_grid/content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::overlay;
use crate::renderer;
use crate::widget::container;
use crate::widget::pane_grid::{Draggable, TitleBar};
use crate::widget::Tree;
use crate::widget::{self, Tree};
use crate::{Clipboard, Element, Layout, Point, Rectangle, Shell, Size};

/// The content of a [`Pane`].
Expand Down Expand Up @@ -183,6 +183,33 @@ where
}
}

pub(crate) fn operate(
&self,
tree: &mut Tree,
layout: Layout<'_>,
operation: &mut dyn widget::Operation<Message>,
) {
let body_layout = if let Some(title_bar) = &self.title_bar {
let mut children = layout.children();

title_bar.operate(
&mut tree.children[1],
children.next().unwrap(),
operation,
);

children.next().unwrap()
} else {
layout
};

self.body.as_widget().operate(
&mut tree.children[0],
body_layout,
operation,
);
}

pub(crate) fn on_event(
&mut self,
tree: &mut Tree,
Expand Down
40 changes: 39 additions & 1 deletion native/src/widget/pane_grid/title_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::mouse;
use crate::overlay;
use crate::renderer;
use crate::widget::container;
use crate::widget::Tree;
use crate::widget::{self, Tree};
use crate::{
Clipboard, Element, Layout, Padding, Point, Rectangle, Shell, Size,
};
Expand Down Expand Up @@ -257,6 +257,44 @@ where
layout::Node::with_children(node.size().pad(self.padding), vec![node])
}

pub(crate) fn operate(
&self,
tree: &mut Tree,
layout: Layout<'_>,
operation: &mut dyn widget::Operation<Message>,
) {
let mut children = layout.children();
let padded = children.next().unwrap();

let mut children = padded.children();
let title_layout = children.next().unwrap();
let mut show_title = true;

if let Some(controls) = &self.controls {
let controls_layout = children.next().unwrap();

if title_layout.bounds().width + controls_layout.bounds().width
> padded.bounds().width
{
show_title = false;
}

controls.as_widget().operate(
&mut tree.children[1],
controls_layout,
operation,
)
};

if show_title {
self.content.as_widget().operate(
&mut tree.children[0],
title_layout,
operation,
)
}
}

pub(crate) fn on_event(
&mut self,
tree: &mut Tree,
Expand Down