Skip to main content

Rect

Struct Rect 

Source
pub struct Rect {
    pub x: f32,
    pub y: f32,
    pub w: f32,
    pub h: f32,
}
Expand description

A rectangle in logical pixels. The host’s scale_factor is applied at paint time, so layout, hit-testing, and Rect-shaped API arguments all speak the same un-scaled coordinate space.

Origin top-left, +y down.

Fields§

§x: f32§y: f32§w: f32§h: f32

Implementations§

Source§

impl Rect

Source

pub const fn new(x: f32, y: f32, w: f32, h: f32) -> Self

Examples found in repository?
examples/scrollbar.rs (line 100)
97fn main() -> std::io::Result<()> {
98    let mut root = fixture();
99
100    let viewport = Rect::new(0.0, 0.0, 960.0, 360.0);
101    let bundle = render_bundle(&mut root, viewport);
102
103    let out_dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("out");
104    let written = write_bundle(&bundle, &out_dir, "scrollbar")?;
105    for p in &written {
106        println!("wrote {}", p.display());
107    }
108
109    if !bundle.lint.findings.is_empty() {
110        eprintln!("\nlint findings ({}):", bundle.lint.findings.len());
111        eprint!("{}", bundle.lint.text());
112    }
113
114    Ok(())
115}
More examples
Hide additional examples
examples/settings.rs (line 68)
65fn main() -> std::io::Result<()> {
66    let mut root = settings();
67
68    let viewport = Rect::new(0.0, 0.0, 720.0, 760.0);
69    let bundle = render_bundle(&mut root, viewport);
70
71    let out_dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("out");
72    let written = write_bundle(&bundle, &out_dir, "settings")?;
73    for p in &written {
74        println!("wrote {}", p.display());
75    }
76
77    if !bundle.lint.findings.is_empty() {
78        eprintln!("\nlint findings ({}):", bundle.lint.findings.len());
79        eprint!("{}", bundle.lint.text());
80    }
81
82    Ok(())
83}
examples/modal.rs (line 57)
55fn main() -> std::io::Result<()> {
56    let mut root = modal_fixture();
57    let viewport = Rect::new(0.0, 0.0, 720.0, 560.0);
58    let bundle = render_bundle(&mut root, viewport);
59
60    let out_dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("out");
61    let written = write_bundle(&bundle, &out_dir, "modal")?;
62    for p in &written {
63        println!("wrote {}", p.display());
64    }
65
66    if !bundle.lint.findings.is_empty() {
67        eprintln!("\nlint findings ({}):", bundle.lint.findings.len());
68        eprint!("{}", bundle.lint.text());
69    }
70
71    Ok(())
72}
examples/custom_paint.rs (line 113)
111fn main() -> std::io::Result<()> {
112    let mut root = fixture();
113    let viewport = Rect::new(0.0, 0.0, 900.0, 360.0);
114    let bundle = render_bundle(&mut root, viewport);
115
116    let out_dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("out");
117    let written = write_bundle(&bundle, &out_dir, "custom_paint")?;
118    for p in &written {
119        println!("wrote {}", p.display());
120    }
121
122    if !bundle.lint.findings.is_empty() {
123        eprintln!("\nlint findings ({}):", bundle.lint.findings.len());
124        eprint!("{}", bundle.lint.text());
125    }
126
127    Ok(())
128}
examples/inline_runs.rs (line 53)
50fn main() -> std::io::Result<()> {
51    let mut root = fixture();
52
53    let viewport = Rect::new(0.0, 0.0, 640.0, 360.0);
54    let bundle = render_bundle(&mut root, viewport);
55
56    let out_dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("out");
57    let written = write_bundle(&bundle, &out_dir, "inline_runs")?;
58    for p in &written {
59        println!("wrote {}", p.display());
60    }
61
62    if !bundle.lint.findings.is_empty() {
63        eprintln!("\nlint findings ({}):", bundle.lint.findings.len());
64        eprint!("{}", bundle.lint.text());
65    }
66
67    Ok(())
68}
examples/custom_shader.rs (line 74)
71fn main() -> std::io::Result<()> {
72    let mut root = fixture();
73
74    let viewport = Rect::new(0.0, 0.0, 720.0, 360.0);
75    let bundle = render_bundle(&mut root, viewport);
76
77    let out_dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("out");
78    let written = write_bundle(&bundle, &out_dir, "custom_shader")?;
79    for p in &written {
80        println!("wrote {}", p.display());
81    }
82
83    if !bundle.lint.findings.is_empty() {
84        eprintln!("\nlint findings ({}):", bundle.lint.findings.len());
85        eprint!("{}", bundle.lint.text());
86    }
87
88    Ok(())
89}
Source

pub fn right(self) -> f32

Source

pub fn bottom(self) -> f32

Source

pub fn center_x(self) -> f32

Source

pub fn center_y(self) -> f32

Source

pub fn contains(self, x: f32, y: f32) -> bool

Source

pub fn intersect(self, other: Rect) -> Option<Rect>

Source

pub fn inset(self, p: Sides) -> Self

Source

pub fn outset(self, p: Sides) -> Self

Inverse of Self::inset: extend the rect outward by p on each side.

Trait Implementations§

Source§

impl Clone for Rect

Source§

fn clone(&self) -> Rect

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Rect

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Rect

Source§

fn default() -> Rect

Returns the “default value” for a type. Read more
Source§

impl PartialEq for Rect

Source§

fn eq(&self, other: &Rect) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for Rect

Source§

impl StructuralPartialEq for Rect

Auto Trait Implementations§

§

impl Freeze for Rect

§

impl RefUnwindSafe for Rect

§

impl Send for Rect

§

impl Sync for Rect

§

impl Unpin for Rect

§

impl UnsafeUnpin for Rect

§

impl UnwindSafe for Rect

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,