moved Point<I>
to module utils
and also added `Size<I>` both types depend on `num-traits`
This commit is contained in:
parent
f6a871d1e7
commit
c9b926f5ba
|
@ -22,3 +22,4 @@ bitflags = "1.3.2"
|
||||||
derivative = "2.2.0"
|
derivative = "2.2.0"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
toml = "0.5"
|
toml = "0.5"
|
||||||
|
num-traits = "0.2.14"
|
||||||
|
|
|
@ -129,42 +129,7 @@ impl<Window> KeyEvent<Window> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, PartialEq, PartialOrd)]
|
pub use crate::util::Point;
|
||||||
pub struct Point<I>
|
|
||||||
where
|
|
||||||
I: Copy + Clone + PartialEq + PartialOrd,
|
|
||||||
{
|
|
||||||
pub x: I,
|
|
||||||
pub y: I,
|
|
||||||
}
|
|
||||||
impl<I> From<(I, I)> for Point<I>
|
|
||||||
where
|
|
||||||
I: Copy + Clone + PartialEq + PartialOrd,
|
|
||||||
{
|
|
||||||
fn from(value: (I, I)) -> Self {
|
|
||||||
Self::from_tuple(value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<I> Point<I>
|
|
||||||
where
|
|
||||||
I: Copy + Clone + PartialEq + PartialOrd,
|
|
||||||
{
|
|
||||||
pub fn new(x: I, y: I) -> Self {
|
|
||||||
Self { x, y }
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn from_tuple(tuple: (I, I)) -> Self {
|
|
||||||
Self {
|
|
||||||
x: tuple.0,
|
|
||||||
y: tuple.1,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn as_tuple(&self) -> (I, I) {
|
|
||||||
(self.x, self.y)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct ButtonEvent<Window> {
|
pub struct ButtonEvent<Window> {
|
||||||
|
|
|
@ -2,10 +2,10 @@ use std::num::NonZeroI32;
|
||||||
use std::{ops::Rem, usize};
|
use std::{ops::Rem, usize};
|
||||||
|
|
||||||
use indexmap::IndexMap;
|
use indexmap::IndexMap;
|
||||||
use log::{error, info};
|
use log::error;
|
||||||
|
|
||||||
use crate::backends::window_event::Point;
|
|
||||||
use crate::util::BuildIdentityHasher;
|
use crate::util::BuildIdentityHasher;
|
||||||
|
use crate::util::{Point, Size};
|
||||||
|
|
||||||
mod client {
|
mod client {
|
||||||
use std::hash::{Hash, Hasher};
|
use std::hash::{Hash, Hasher};
|
||||||
|
@ -538,7 +538,7 @@ impl ClientState {
|
||||||
let (new, old) = self.focus_client_inner(key);
|
let (new, old) = self.focus_client_inner(key);
|
||||||
|
|
||||||
if !(new.is_vacant() && old.is_vacant()) {
|
if !(new.is_vacant() && old.is_vacant()) {
|
||||||
info!("Swapping focus: new({:?}) old({:?})", new, old);
|
//info!("Swapping focus: new({:?}) old({:?})", new, old);
|
||||||
}
|
}
|
||||||
|
|
||||||
(new, old)
|
(new, old)
|
||||||
|
|
133
src/util.rs
133
src/util.rs
|
@ -22,3 +22,136 @@ impl Hasher for IdentityHasher {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type BuildIdentityHasher = BuildHasherDefault<IdentityHasher>;
|
pub type BuildIdentityHasher = BuildHasherDefault<IdentityHasher>;
|
||||||
|
|
||||||
|
pub use point::Point;
|
||||||
|
pub use size::Size;
|
||||||
|
|
||||||
|
mod size {
|
||||||
|
#[derive(Debug, Copy, Clone, PartialEq, PartialOrd)]
|
||||||
|
pub struct Size<I>
|
||||||
|
where
|
||||||
|
I: num_traits::PrimInt + num_traits::Zero,
|
||||||
|
{
|
||||||
|
pub width: I,
|
||||||
|
pub height: I,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<I> Default for Size<I>
|
||||||
|
where
|
||||||
|
I: num_traits::PrimInt + num_traits::Zero,
|
||||||
|
{
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
width: I::zero(),
|
||||||
|
height: I::zero(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<I> From<(I, I)> for Size<I>
|
||||||
|
where
|
||||||
|
I: num_traits::PrimInt + num_traits::Zero,
|
||||||
|
{
|
||||||
|
fn from(value: (I, I)) -> Self {
|
||||||
|
Self::from_tuple(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<I> From<super::point::Point<I>> for Size<I>
|
||||||
|
where
|
||||||
|
I: num_traits::PrimInt + num_traits::Zero,
|
||||||
|
{
|
||||||
|
fn from(value: super::point::Point<I>) -> Self {
|
||||||
|
Self::new(value.x, value.y)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<I> Size<I>
|
||||||
|
where
|
||||||
|
I: num_traits::PrimInt + num_traits::Zero,
|
||||||
|
{
|
||||||
|
pub fn new(width: I, height: I) -> Self {
|
||||||
|
Self { width, height }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn from_tuple(tuple: (I, I)) -> Self {
|
||||||
|
Self::new(tuple.0, tuple.1)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn as_tuple(&self) -> (I, I) {
|
||||||
|
(self.width, self.height)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn map<F>(self, f: F) -> Self
|
||||||
|
where
|
||||||
|
F: FnOnce(I, I) -> Self,
|
||||||
|
{
|
||||||
|
f(self.width, self.height)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod point {
|
||||||
|
#[derive(Debug, Copy, Clone, PartialEq, PartialOrd)]
|
||||||
|
pub struct Point<I>
|
||||||
|
where
|
||||||
|
I: num_traits::PrimInt + num_traits::Zero,
|
||||||
|
{
|
||||||
|
pub x: I,
|
||||||
|
pub y: I,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<I> Default for Point<I>
|
||||||
|
where
|
||||||
|
I: num_traits::PrimInt + num_traits::Zero,
|
||||||
|
{
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
x: I::zero(),
|
||||||
|
y: I::zero(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<I> From<(I, I)> for Point<I>
|
||||||
|
where
|
||||||
|
I: num_traits::PrimInt + num_traits::Zero,
|
||||||
|
{
|
||||||
|
fn from(value: (I, I)) -> Self {
|
||||||
|
Self::from_tuple(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<I> From<super::size::Size<I>> for Point<I>
|
||||||
|
where
|
||||||
|
I: num_traits::PrimInt + num_traits::Zero,
|
||||||
|
{
|
||||||
|
fn from(value: super::size::Size<I>) -> Self {
|
||||||
|
Self::new(value.width, value.height)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<I> Point<I>
|
||||||
|
where
|
||||||
|
I: num_traits::PrimInt + num_traits::Zero,
|
||||||
|
{
|
||||||
|
pub fn new(x: I, y: I) -> Self {
|
||||||
|
Self { x, y }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn from_tuple(tuple: (I, I)) -> Self {
|
||||||
|
Self::new(tuple.0, tuple.1)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn as_tuple(&self) -> (I, I) {
|
||||||
|
(self.x, self.y)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn map<F, T>(self, f: F) -> T
|
||||||
|
where
|
||||||
|
F: FnOnce(I, I) -> T,
|
||||||
|
{
|
||||||
|
f(self.x, self.y)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue