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

View File

@ -1,5 +1,5 @@
/// A rectangular region in a [`PaneGrid`] used to display widgets.
///
/// [`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);

View File

@ -1,5 +1,5 @@
/// A divider that splits a region in a [`PaneGrid`] into two different panes.
///
/// [`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);

View File

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