[][src]Struct penrose::core::data_types::Region

pub struct Region {
    pub x: u32,
    pub y: u32,
    pub w: u32,
    pub h: u32,
}

An X window / screen position: top left corner + extent

Fields

x: u32

The x-coordinate of the top left corner of this region

y: u32

The y-coordinate of the top left corner of this region

w: u32

The width of this region

h: u32

The height of this region

Implementations

impl Region[src]

pub fn new(x: u32, y: u32, w: u32, h: u32) -> Region[src]

Create a new Region.

pub fn values(&self) -> (u32, u32, u32, u32)[src]

Destructure this Region into its component values (x, y, w, h).

Examples

use penrose::core::data_types::Region;

// In practice, this will be a region your code is receiving: not one you create
let r = Region::new(10, 20, 30, 40);

assert_eq!(r.values(), (10, 20, 30, 40));

pub fn scale_w(&self, factor: f64) -> Self[src]

Create a new Region with width equal to factor x self.w

Examples

use penrose::core::data_types::Region;

let r = Region::new(10, 20, 30, 40);

assert_eq!(r.scale_w(1.5), Region::new(10, 20, 45, 40));
assert_eq!(r.scale_w(0.5), Region::new(10, 20, 15, 40));

pub fn scale_h(&self, factor: f64) -> Self[src]

Create a new Region with height equal to factor x self.h

Examples

use penrose::core::data_types::Region;

let r = Region::new(10, 20, 30, 40);

assert_eq!(r.scale_h(1.5), Region::new(10, 20, 30, 60));
assert_eq!(r.scale_h(0.5), Region::new(10, 20, 30, 20));

pub fn contains(&self, other: &Region) -> bool[src]

Check whether this Region contains other as a sub-Region

Examples

use penrose::core::data_types::Region;

let r1 = Region::new(10, 10, 50, 50);
let r2 = Region::new(0, 0, 100, 100);

assert!(r2.contains(&r1));
assert!(!r1.contains(&r2));

pub fn contains_point(&self, p: &Point) -> bool[src]

Check whether this Region contains other as a sub-Region

Examples

use penrose::core::data_types::{Point, Region};

let r1 = Region::new(10, 10, 50, 50);

assert!(r1.contains_point(&Point::new(30, 20)));
assert!(!r1.contains_point(&Point::new(0, 0)));

pub fn centered_in(&self, enclosing: &Region) -> Result<Self>[src]

Center this region inside of enclosing.

Errors

Fails if this Region can not fit inside of enclosing

Examples

use penrose::core::data_types::Region;

let r1 = Region::new(10, 10, 50, 60);
let r2 = Region::new(0, 0, 100, 100);

let centered = r1.centered_in(&r2);
assert!(centered.is_ok());
assert_eq!(centered.unwrap(), Region::new(25, 20, 50, 60));

let too_big = r2.centered_in(&r1);
assert!(too_big.is_err());

pub fn as_rows(&self, n_rows: u32) -> Vec<Region>[src]

Split this Region into evenly sized rows.

Examples

use penrose::core::data_types::Region;

let r = Region::new(0, 0, 100, 100);

let regions = r.as_rows(2);

assert_eq!(regions.len(), 2);
assert_eq!(regions[0], Region::new(0, 0, 100, 50));
assert_eq!(regions[1], Region::new(0, 50, 100, 50));

pub fn as_columns(&self, n_columns: u32) -> Vec<Region>[src]

Split this Region into evenly sized columns.

Examples

use penrose::core::data_types::Region;

let r = Region::new(0, 0, 100, 100);

let regions = r.as_columns(2);

assert_eq!(regions.len(), 2);
assert_eq!(regions[0], Region::new(0, 0, 50, 100));
assert_eq!(regions[1], Region::new(50, 0, 50, 100));

pub fn split_at_width(&self, new_width: u32) -> Result<(Self, Self)>[src]

Divides this region into two columns where the first has the given width.

Errors

Fails if the requested split point is not contained within self

Examples

use penrose::core::data_types::Region;

let r = Region::new(10, 10, 50, 60);
let (r1, r2) = r.split_at_width(30).unwrap();

assert_eq!(r1, Region::new(10, 10, 30, 60));
assert_eq!(r2, Region::new(40, 10, 20, 60));

assert!(r.split_at_width(100).is_err());

pub fn split_at_height(&self, new_height: u32) -> Result<(Self, Self)>[src]

Divides this region into two rows where the first has the given height.

Errors

Fails if the requested split point is not contained within self

Examples

use penrose::core::data_types::Region;

let r = Region::new(10, 10, 50, 60);
let (r1, r2) = r.split_at_height(40).unwrap();

assert_eq!(r1, Region::new(10, 10, 50, 40));
assert_eq!(r2, Region::new(10, 50, 50, 20));

assert!(r.split_at_height(100).is_err());

Trait Implementations

impl Clone for Region[src]

impl Copy for Region[src]

impl Debug for Region[src]

impl Eq for Region[src]

impl Hash for Region[src]

impl PartialEq<Region> for Region[src]

impl StructuralEq for Region[src]

impl StructuralPartialEq for Region[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.