Skip to main content

Frame

Struct Frame 

Source
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: Rect

The available drawing area.

§hit_map: &'a mut HitMap

The hit map for mouse routing.

Implementations§

Source§

impl<'a> Frame<'a>

Source

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.

Source

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    }
Source

pub fn register_widget(&mut self, node: UiNode)

Register a widget in the UI tree for agent discoverability.

Source

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    }
Source

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> 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> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> Downcast for T
where T: Any,

Source§

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>

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)

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)

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more