pub struct Rect {
pub x: f32,
pub y: f32,
pub width: f32,
pub height: f32,
}Expand description
A 2D rectangle defined by position and size in logical pixels.
Fields§
§x: f32§y: f32§width: f32§height: f32Implementations§
Source§impl Rect
impl Rect
pub const ZERO: Self
Sourcepub const fn new(x: f32, y: f32, width: f32, height: f32) -> Self
pub const fn new(x: f32, y: f32, width: f32, height: f32) -> Self
Examples found in repository?
examples/hello_agpu.rs (line 34)
31 fn view(&self, frame: &mut Frame<'_>) {
32 let area = frame.area;
33 let btn_y = area.y + 50.0;
34 let dec_rect = Rect::new(area.x + 10.0, btn_y, 80.0, 36.0);
35 let inc_rect = Rect::new(area.x + 100.0, btn_y, 80.0, 36.0);
36
37 // Paint everything first
38 {
39 let style = TextStyle {
40 font_size: 24.0,
41 color: Color::WHITE,
42 ..Default::default()
43 };
44 let p = frame.painter();
45
46 // Background
47 p.fill_rect(area, Color::rgba(0.1, 0.1, 0.12, 1.0), 0.0);
48
49 // Counter label
50 p.text(
51 Position::new(area.x + 10.0, area.y + 8.0),
52 &format!("Count: {}", self.count),
53 &style,
54 );
55
56 // Decrement button
57 p.fill_rect(dec_rect, Color::rgba(0.8, 0.2, 0.2, 1.0), 4.0);
58 p.text(
59 Position::new(dec_rect.x + 30.0, dec_rect.y + 6.0),
60 "−",
61 &style,
62 );
63
64 // Increment button
65 p.fill_rect(inc_rect, Color::rgba(0.2, 0.6, 0.2, 1.0), 4.0);
66 p.text(
67 Position::new(inc_rect.x + 30.0, inc_rect.y + 6.0),
68 "+",
69 &style,
70 );
71 }
72
73 // Register hitboxes for event routing
74 frame.register_hitbox("decrement_btn", dec_rect, 0);
75 frame.register_hitbox("increment_btn", inc_rect, 0);
76 }pub fn from_size(width: f32, height: f32) -> Self
pub fn right(&self) -> f32
pub fn bottom(&self) -> f32
pub fn center(&self) -> Position
pub fn contains(&self, pos: Position) -> bool
pub fn intersection(&self, other: &Rect) -> Option<Rect>
pub fn union(&self, other: &Rect) -> Rect
pub fn inner(&self, margin: &Margin) -> Rect
pub fn is_empty(&self) -> bool
pub fn size(&self) -> Size
pub fn position(&self) -> Position
pub fn translate(&self, dx: f32, dy: f32) -> Self
pub fn inflate(&self, dx: f32, dy: f32) -> Self
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Rect
impl<'de> Deserialize<'de> for Rect
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl From<Rect> for NodeBounds
impl From<Rect> for NodeBounds
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<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more