pub struct Frame<'a> {
pub area: Rect,
pub hit_map: &'a mut HitMap,
/* private fields */
}Expand description
A rendering frame — abstraction over the GUI backend.
During Model::view, the frame provides methods to draw widgets
and manage the UI tree for agent discoverability.
Fields§
§area: RectThe available drawing area.
hit_map: &'a mut HitMapThe hit map for mouse routing.
Implementations§
Source§impl<'a> Frame<'a>
impl<'a> Frame<'a>
Sourcepub fn new(
area: Rect,
hit_map: &'a mut HitMap,
painter: &'a mut dyn Painter,
) -> Self
pub fn new( area: Rect, hit_map: &'a mut HitMap, painter: &'a mut dyn Painter, ) -> Self
Create a new frame with the given area, hit map, and painter.
Sourcepub fn painter(&mut self) -> &mut dyn Painter
pub fn painter(&mut self) -> &mut dyn Painter
Get a mutable reference to the painter for this frame.
Examples found in repository?
examples/hello_agpu.rs (line 44)
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 }Sourcepub fn register_widget(&mut self, node: UiNode)
pub fn register_widget(&mut self, node: UiNode)
Register a widget in the UI tree for agent discoverability.
Sourcepub fn register_hitbox(
&mut self,
agent_id: impl Into<String>,
bounds: Rect,
z_order: u32,
)
pub fn register_hitbox( &mut self, agent_id: impl Into<String>, bounds: Rect, z_order: u32, )
Register a hitbox for mouse event routing.
Examples found in repository?
examples/hello_agpu.rs (line 74)
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 }Sourcepub fn take_nodes(&mut self) -> Vec<UiNode>
pub fn take_nodes(&mut self) -> Vec<UiNode>
Take the collected UI nodes (consumed by the runtime after rendering).
Auto Trait Implementations§
impl<'a> Freeze for Frame<'a>
impl<'a> !RefUnwindSafe for Frame<'a>
impl<'a> !Send for Frame<'a>
impl<'a> !Sync for Frame<'a>
impl<'a> Unpin for Frame<'a>
impl<'a> UnsafeUnpin for Frame<'a>
impl<'a> !UnwindSafe for Frame<'a>
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> 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> 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