Skip to content

Commit

Permalink
Merge pull request #1533 from rs017991/op_bug_fix_panegrid
Browse files Browse the repository at this point in the history
Fixed Operations within PaneGrid
  • Loading branch information
hecrj authored Nov 13, 2022
2 parents 23299a5 + b0678f4 commit 5f08b8d
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 2 deletions.
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

0 comments on commit 5f08b8d

Please sign in to comment.