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: f32Left edge, in logical pixels.
y: f32Top edge, in logical pixels.
w: f32Width, in logical pixels.
h: f32Height, in logical pixels.
Implementations§
Source§impl Rect
impl Rect
Sourcepub const fn new(x: f32, y: f32, w: f32, h: f32) -> Self
pub const fn new(x: f32, y: f32, w: f32, h: f32) -> Self
Construct a rect from its left edge, top edge, width, and height.
Examples found in repository?
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
66fn main() -> std::io::Result<()> {
67 let mut root = settings();
68
69 let viewport = Rect::new(0.0, 0.0, 720.0, 760.0);
70 let bundle = render_bundle(&mut root, viewport);
71
72 let out_dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("out");
73 let written = write_bundle(&bundle, &out_dir, "settings")?;
74 for p in &written {
75 println!("wrote {}", p.display());
76 }
77
78 if !bundle.lint.findings.is_empty() {
79 eprintln!("\nlint findings ({}):", bundle.lint.findings.len());
80 eprint!("{}", bundle.lint.text());
81 }
82
83 Ok(())
84}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}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}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}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}Sourcepub fn contains(self, x: f32, y: f32) -> bool
pub fn contains(self, x: f32, y: f32) -> bool
True when the point lies inside the rect. Left/top edges are inclusive; right/bottom edges are exclusive, so adjacent rects never both claim a shared-edge point.
Sourcepub fn intersect(self, other: Rect) -> Option<Rect>
pub fn intersect(self, other: Rect) -> Option<Rect>
Overlapping region of the two rects, or None when they don’t
overlap (touching edges count as no overlap).
Sourcepub fn inset(self, p: Sides) -> Self
pub fn inset(self, p: Sides) -> Self
Shrink the rect inward by p on each side (e.g. to go from a
node’s layout rect to its padded content rect). Width and height
clamp at 0.0 rather than going negative.
Sourcepub fn outset(self, p: Sides) -> Self
pub fn outset(self, p: Sides) -> Self
Inverse of Self::inset: extend the rect outward by p on each side.
Trait Implementations§
impl Copy for Rect
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
impl<T> Scalar for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.