Rename Split to Axis

This commit is contained in:
Héctor Ramón Jiménez 2020-03-14 06:32:56 +01:00
parent 00c2b55b56
commit a79603e4ca
4 changed files with 18 additions and 23 deletions

View File

@ -1,12 +1,12 @@
mod axis;
mod direction;
mod node;
mod pane;
mod split;
mod state;
pub use axis::Axis;
pub use direction::Direction;
pub use pane::Pane;
pub use split::Split;
pub use state::{Focus, State};
use crate::{

View File

@ -1,20 +1,20 @@
use crate::Rectangle;
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
pub enum Split {
pub enum Axis {
Horizontal,
Vertical,
}
impl Split {
pub(super) fn apply(
impl Axis {
pub(super) fn split(
&self,
rectangle: &Rectangle,
ratio: f32,
halved_spacing: f32,
) -> (Rectangle, Rectangle) {
match self {
Split::Horizontal => {
Axis::Horizontal => {
let width_left =
(rectangle.width * ratio).round() - halved_spacing;
let width_right = rectangle.width - width_left - halved_spacing;
@ -31,7 +31,7 @@ impl Split {
},
)
}
Split::Vertical => {
Axis::Vertical => {
let height_top =
(rectangle.height * ratio).round() - halved_spacing;
let height_bottom =

View File

@ -1,5 +1,5 @@
use crate::{
pane_grid::{Pane, Split},
pane_grid::{Axis, Pane},
Rectangle, Size,
};
@ -9,7 +9,7 @@ use std::collections::HashMap;
pub enum Node {
Split {
id: usize,
kind: Split,
axis: Axis,
ratio: u32,
a: Box<Node>,
b: Box<Node>,
@ -33,10 +33,10 @@ impl Node {
}
}
pub fn split(&mut self, id: usize, kind: Split, new_pane: Pane) {
pub fn split(&mut self, id: usize, axis: Axis, new_pane: Pane) {
*self = Node::Split {
id,
kind,
axis,
ratio: 500_000,
a: Box::new(self.clone()),
b: Box::new(Node::Pane(new_pane)),
@ -115,11 +115,11 @@ impl Node {
) {
match self {
Node::Split {
kind, ratio, a, b, ..
axis, ratio, a, b, ..
} => {
let ratio = *ratio as f32 / 1_000_000.0;
let (region_a, region_b) =
kind.apply(current, ratio, halved_spacing);
axis.split(current, ratio, halved_spacing);
a.compute_regions(halved_spacing, &region_a, regions);
b.compute_regions(halved_spacing, &region_b, regions);

View File

@ -1,6 +1,6 @@
use crate::{
input::keyboard,
pane_grid::{node::Node, Direction, Pane, Split},
pane_grid::{node::Node, Axis, Direction, Pane},
Hasher, Point, Rectangle, Size,
};
@ -99,7 +99,7 @@ impl<T> State<T> {
}
pub fn split_vertically(&mut self, pane: &Pane, state: T) -> Option<Pane> {
self.split(Split::Vertical, pane, state)
self.split(Axis::Vertical, pane, state)
}
pub fn split_horizontally(
@ -107,15 +107,10 @@ impl<T> State<T> {
pane: &Pane,
state: T,
) -> Option<Pane> {
self.split(Split::Horizontal, pane, state)
self.split(Axis::Horizontal, pane, state)
}
pub fn split(
&mut self,
kind: Split,
pane: &Pane,
state: T,
) -> Option<Pane> {
pub fn split(&mut self, axis: Axis, pane: &Pane, state: T) -> Option<Pane> {
let node = self.internal.layout.find(pane)?;
let new_pane = {
@ -130,7 +125,7 @@ impl<T> State<T> {
self.internal.last_id
};
node.split(split_id, kind, new_pane);
node.split(split_id, axis, new_pane);
let _ = self.panes.insert(new_pane, state);
self.focus(&new_pane);