-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Add pane maximize / restore for PaneGrid
#1504
Conversation
c802789
to
1209f81
Compare
1209f81
to
2f6c71d
Compare
This is a great addition to the pane grid. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good! Just one suggestion!
native/src/widget/pane_grid.rs
Outdated
pub fn iter(&self) -> Box<dyn Iterator<Item = (Pane, &T)> + '_> { | ||
match self { | ||
Contents::All(contents) => Box::new( | ||
contents.iter().map(|(pane, content)| (*pane, content)), | ||
), | ||
Contents::Maximized(pane, content) => { | ||
Box::new(std::iter::once((*pane, content))) | ||
} | ||
} | ||
} | ||
|
||
fn iter_mut(&mut self) -> Box<dyn Iterator<Item = (Pane, &mut T)> + '_> { | ||
match self { | ||
Contents::All(contents) => Box::new( | ||
contents.iter_mut().map(|(pane, content)| (*pane, content)), | ||
), | ||
Contents::Maximized(pane, content) => { | ||
Box::new(std::iter::once((*pane, content))) | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! We avoid a lot of code changes with this API :) Iterators are pretty nifty.
native/src/widget/pane_grid.rs
Outdated
Contents::Maximized(pane, view(pane, pane_state, true)), | ||
state::Scoped::Maximized(Node::Pane(pane)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These seem inherently coupled, but the current data model allows us to potentially have desync. Could we simply merge Scoped
with Contents
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Good call, fixed in 7de9d24
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! Let's sail 🚢
Adds the ability to maximize / restore a pane in the pane grid. When maximized, dragging is disabled (we can remove this, since dragging is enabled when only 1 pane exists currently).
API
Two new methods are exposed on
State
to allow the user control of maximizing and restoring a pane:Once a pane is maximized, a new
bool
is passed on theview
function to specify if the pane is maximized or not. Maybe we create an enum here for a stronger type since the closure is not descriptive:Implementation
State
stores the maximized pane in a new field:maximized: Option<Pane>
and is set by the above API.Instead of storing
Vec<Content>
in thePaneGrid
, I've created a new helperContents
that is built considering the maximized pane. This can be iterated over for building the widget tree & layout.A new
state::Scoped
has been added which either wraps the internal state when no field is maximized, or specifies the maximized pane. The widget methods now take this for determining the layout Node of thePaneGrid
.Iterating on
Contents
and callingScoped::layout
allowed for very minimal adjustments of the existing widget implementation code.Demo
simplescreenrecorder-2022-11-02_17.13.37.mp4