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: f32Implementations§
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
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
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}Additional examples can be found in:
pub fn right(self) -> f32
pub fn bottom(self) -> f32
pub fn center_x(self) -> f32
pub fn center_y(self) -> f32
pub fn contains(self, x: f32, y: f32) -> bool
pub fn intersect(self, other: Rect) -> Option<Rect>
pub fn inset(self, p: Sides) -> Self
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
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
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
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.