Rename Split
to Axis
This commit is contained in:
parent
00c2b55b56
commit
a79603e4ca
@ -1,12 +1,12 @@
|
|||||||
|
mod axis;
|
||||||
mod direction;
|
mod direction;
|
||||||
mod node;
|
mod node;
|
||||||
mod pane;
|
mod pane;
|
||||||
mod split;
|
|
||||||
mod state;
|
mod state;
|
||||||
|
|
||||||
|
pub use axis::Axis;
|
||||||
pub use direction::Direction;
|
pub use direction::Direction;
|
||||||
pub use pane::Pane;
|
pub use pane::Pane;
|
||||||
pub use split::Split;
|
|
||||||
pub use state::{Focus, State};
|
pub use state::{Focus, State};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -1,20 +1,20 @@
|
|||||||
use crate::Rectangle;
|
use crate::Rectangle;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
|
||||||
pub enum Split {
|
pub enum Axis {
|
||||||
Horizontal,
|
Horizontal,
|
||||||
Vertical,
|
Vertical,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Split {
|
impl Axis {
|
||||||
pub(super) fn apply(
|
pub(super) fn split(
|
||||||
&self,
|
&self,
|
||||||
rectangle: &Rectangle,
|
rectangle: &Rectangle,
|
||||||
ratio: f32,
|
ratio: f32,
|
||||||
halved_spacing: f32,
|
halved_spacing: f32,
|
||||||
) -> (Rectangle, Rectangle) {
|
) -> (Rectangle, Rectangle) {
|
||||||
match self {
|
match self {
|
||||||
Split::Horizontal => {
|
Axis::Horizontal => {
|
||||||
let width_left =
|
let width_left =
|
||||||
(rectangle.width * ratio).round() - halved_spacing;
|
(rectangle.width * ratio).round() - halved_spacing;
|
||||||
let width_right = rectangle.width - width_left - halved_spacing;
|
let width_right = rectangle.width - width_left - halved_spacing;
|
||||||
@ -31,7 +31,7 @@ impl Split {
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
Split::Vertical => {
|
Axis::Vertical => {
|
||||||
let height_top =
|
let height_top =
|
||||||
(rectangle.height * ratio).round() - halved_spacing;
|
(rectangle.height * ratio).round() - halved_spacing;
|
||||||
let height_bottom =
|
let height_bottom =
|
@ -1,5 +1,5 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
pane_grid::{Pane, Split},
|
pane_grid::{Axis, Pane},
|
||||||
Rectangle, Size,
|
Rectangle, Size,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -9,7 +9,7 @@ use std::collections::HashMap;
|
|||||||
pub enum Node {
|
pub enum Node {
|
||||||
Split {
|
Split {
|
||||||
id: usize,
|
id: usize,
|
||||||
kind: Split,
|
axis: Axis,
|
||||||
ratio: u32,
|
ratio: u32,
|
||||||
a: Box<Node>,
|
a: Box<Node>,
|
||||||
b: 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 {
|
*self = Node::Split {
|
||||||
id,
|
id,
|
||||||
kind,
|
axis,
|
||||||
ratio: 500_000,
|
ratio: 500_000,
|
||||||
a: Box::new(self.clone()),
|
a: Box::new(self.clone()),
|
||||||
b: Box::new(Node::Pane(new_pane)),
|
b: Box::new(Node::Pane(new_pane)),
|
||||||
@ -115,11 +115,11 @@ impl Node {
|
|||||||
) {
|
) {
|
||||||
match self {
|
match self {
|
||||||
Node::Split {
|
Node::Split {
|
||||||
kind, ratio, a, b, ..
|
axis, ratio, a, b, ..
|
||||||
} => {
|
} => {
|
||||||
let ratio = *ratio as f32 / 1_000_000.0;
|
let ratio = *ratio as f32 / 1_000_000.0;
|
||||||
let (region_a, region_b) =
|
let (region_a, region_b) =
|
||||||
kind.apply(current, ratio, halved_spacing);
|
axis.split(current, ratio, halved_spacing);
|
||||||
|
|
||||||
a.compute_regions(halved_spacing, ®ion_a, regions);
|
a.compute_regions(halved_spacing, ®ion_a, regions);
|
||||||
b.compute_regions(halved_spacing, ®ion_b, regions);
|
b.compute_regions(halved_spacing, ®ion_b, regions);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
input::keyboard,
|
input::keyboard,
|
||||||
pane_grid::{node::Node, Direction, Pane, Split},
|
pane_grid::{node::Node, Axis, Direction, Pane},
|
||||||
Hasher, Point, Rectangle, Size,
|
Hasher, Point, Rectangle, Size,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -99,7 +99,7 @@ impl<T> State<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn split_vertically(&mut self, pane: &Pane, state: T) -> Option<Pane> {
|
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(
|
pub fn split_horizontally(
|
||||||
@ -107,15 +107,10 @@ impl<T> State<T> {
|
|||||||
pane: &Pane,
|
pane: &Pane,
|
||||||
state: T,
|
state: T,
|
||||||
) -> Option<Pane> {
|
) -> Option<Pane> {
|
||||||
self.split(Split::Horizontal, pane, state)
|
self.split(Axis::Horizontal, pane, state)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn split(
|
pub fn split(&mut self, axis: Axis, pane: &Pane, state: T) -> Option<Pane> {
|
||||||
&mut self,
|
|
||||||
kind: Split,
|
|
||||||
pane: &Pane,
|
|
||||||
state: T,
|
|
||||||
) -> Option<Pane> {
|
|
||||||
let node = self.internal.layout.find(pane)?;
|
let node = self.internal.layout.find(pane)?;
|
||||||
|
|
||||||
let new_pane = {
|
let new_pane = {
|
||||||
@ -130,7 +125,7 @@ impl<T> State<T> {
|
|||||||
self.internal.last_id
|
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);
|
let _ = self.panes.insert(new_pane, state);
|
||||||
self.focus(&new_pane);
|
self.focus(&new_pane);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user