Use `BTreeMap` for splits and regions in `pane_grid`

This preserves ordering between calls to update and draw logic.
This commit is contained in:
Héctor Ramón Jiménez 2021-01-07 21:07:44 +01:00
parent 31522e30aa
commit e7344d03b4
4 changed files with 12 additions and 12 deletions

View File

@ -3,7 +3,7 @@ use crate::{
Rectangle, Size, Rectangle, Size,
}; };
use std::collections::HashMap; use std::collections::BTreeMap;
/// A layout node of a [`PaneGrid`]. /// A layout node of a [`PaneGrid`].
/// ///
@ -59,8 +59,8 @@ impl Node {
&self, &self,
spacing: f32, spacing: f32,
size: Size, size: Size,
) -> HashMap<Pane, Rectangle> { ) -> BTreeMap<Pane, Rectangle> {
let mut regions = HashMap::new(); let mut regions = BTreeMap::new();
self.compute_regions( self.compute_regions(
spacing, spacing,
@ -83,8 +83,8 @@ impl Node {
&self, &self,
spacing: f32, spacing: f32,
size: Size, size: Size,
) -> HashMap<Split, (Axis, Rectangle, f32)> { ) -> BTreeMap<Split, (Axis, Rectangle, f32)> {
let mut splits = HashMap::new(); let mut splits = BTreeMap::new();
self.compute_splits( self.compute_splits(
spacing, spacing,
@ -191,7 +191,7 @@ impl Node {
&self, &self,
spacing: f32, spacing: f32,
current: &Rectangle, current: &Rectangle,
regions: &mut HashMap<Pane, Rectangle>, regions: &mut BTreeMap<Pane, Rectangle>,
) { ) {
match self { match self {
Node::Split { Node::Split {
@ -212,7 +212,7 @@ impl Node {
&self, &self,
spacing: f32, spacing: f32,
current: &Rectangle, current: &Rectangle,
splits: &mut HashMap<Split, (Axis, Rectangle, f32)>, splits: &mut BTreeMap<Split, (Axis, Rectangle, f32)>,
) { ) {
match self { match self {
Node::Split { Node::Split {

View File

@ -1,5 +1,5 @@
/// A rectangular region in a [`PaneGrid`] used to display widgets. /// A rectangular region in a [`PaneGrid`] used to display widgets.
/// ///
/// [`PaneGrid`]: crate::widget::PaneGrid /// [`PaneGrid`]: crate::widget::PaneGrid
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Pane(pub(super) usize); pub struct Pane(pub(super) usize);

View File

@ -1,5 +1,5 @@
/// A divider that splits a region in a [`PaneGrid`] into two different panes. /// A divider that splits a region in a [`PaneGrid`] into two different panes.
/// ///
/// [`PaneGrid`]: crate::widget::PaneGrid /// [`PaneGrid`]: crate::widget::PaneGrid
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Split(pub(super) usize); pub struct Split(pub(super) usize);

View File

@ -3,7 +3,7 @@ use crate::{
Hasher, Point, Rectangle, Size, Hasher, Point, Rectangle, Size,
}; };
use std::collections::HashMap; use std::collections::{BTreeMap, HashMap};
/// The state of a [`PaneGrid`]. /// The state of a [`PaneGrid`].
/// ///
@ -257,7 +257,7 @@ impl Internal {
&self, &self,
spacing: f32, spacing: f32,
size: Size, size: Size,
) -> HashMap<Pane, Rectangle> { ) -> BTreeMap<Pane, Rectangle> {
self.layout.pane_regions(spacing, size) self.layout.pane_regions(spacing, size)
} }
@ -265,7 +265,7 @@ impl Internal {
&self, &self,
spacing: f32, spacing: f32,
size: Size, size: Size,
) -> HashMap<Split, (Axis, Rectangle, f32)> { ) -> BTreeMap<Split, (Axis, Rectangle, f32)> {
self.layout.split_regions(spacing, size) self.layout.split_regions(spacing, size)
} }