ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_widget_toolbar.c File Reference

Toolbar leaf widget for the ra8_widget tree model (#145 Phase 2). More...

#include "ra8_widget_toolbar.h"
#include "ra8_check.h"
#include "ra8_ui.h"
#include "ra8_widget.h"
#include "ra8_widget_internal.h"
Include dependency graph for ra8_widget_toolbar.c:

Go to the source code of this file.

Functions

static ra8_ui_rect_t internal_tb_field_rect (const ra8_widget_toolbar_t *bar, const ra8_ui_rect_t *band)
 Compute the search-field sub-rectangle inside a toolbar band.
static void internal_tb_render (ra8_widget_t *w)
 Toolbar vtable render: band fill, bordered field + hint, count chip.
static bool internal_tb_on_input (ra8_widget_t *w, const ra8_widget_event_t *ev)
 Toolbar vtable input: latch a touch inside the search field.
const ra8_widget_vtable_tra8_widget_toolbar_vtable (void)
 Return the shared vtable backing every toolbar widget.
ra8_err_t ra8_widget_toolbar_init (ra8_widget_t *w, ra8_widget_toolbar_t *bar)
 Bind a widget instance to a toolbar.

Variables

static const char * s_tag = "ra8_widget_toolbar"
 Logging / check tag.
static const ra8_widget_vtable_t s_tb_vt
 The single immutable vtable shared by every toolbar.

Detailed Description

Toolbar leaf widget for the ra8_widget tree model (#145 Phase 2).

Extracts the e-reader Library toolbar (a search field + a count chip) into a reusable ra8_widget leaf. The search-field rect is computed once by internal_tb_field_rect and shared between render (paint the bordered box + hint) and on_input (hit-test a tap), so the tap target is exactly the drawn field. Painting goes through the injected ra8_widget_paint_t backend, so the file carries no ra8_gfx dependency and the whole thing is host-testable with a recording mock paint.

[Ring 5 / UI] {World: NS}

Since
0.1.0

Definition in file ra8_widget_toolbar.c.

Function Documentation

◆ internal_tb_field_rect()

ra8_ui_rect_t internal_tb_field_rect ( const ra8_widget_toolbar_t * bar,
const ra8_ui_rect_t * band )
static

Compute the search-field sub-rectangle inside a toolbar band.

The band is inset by pad on every side; the count chip reserves a fixed count_w (plus a pad gutter) on the right and the field fills the remaining width. Shared by render (draw the field) and on_input (hit-test a tap) so the drawn box and the tap target coincide.

Parameters
[in]barToolbar descriptor (non-NULL).
[in]bandThe toolbar widget rect (non-NULL).
Returns
The search-field rectangle (may have zero width on a narrow band).
Return values
rectThe inset field rectangle.
Precondition
bar and band are non-NULL.
None.
Postcondition
The returned rect lies within band.
No state is modified.
Note
Pure.
Since
0.1.0

Definition at line 51 of file ra8_widget_toolbar.c.

References ra8_ui_rect_t::h, ra8_ui_rect_t::w, ra8_ui_rect_t::x, and ra8_ui_rect_t::y.

Referenced by internal_tb_on_input(), and internal_tb_render().

◆ internal_tb_on_input()

bool internal_tb_on_input ( ra8_widget_t * w,
const ra8_widget_event_t * ev )
static

Toolbar vtable input: latch a touch inside the search field.

A touch that lands inside the search-field rect bumps searches, self-invalidates fast (so only this band re-flushes), fires the optional on_search, and reports the event consumed. A tap outside the field, or a button event, is declined so it keeps routing.

Parameters
[in]wThe toolbar widget (its ctx is a ra8_widget_toolbar_t).
[in]evThe event already routed to this toolbar.
Returns
true if a search-field touch was latched, false otherwise.
Return values
trueev was a touch inside the field and it latched.
falseNon-touch, a tap outside the field, or ctx is NULL.
Precondition
w and ev are non-NULL.
w->ctx points at a valid toolbar descriptor or is NULL.
Postcondition
On a field touch searches grew by one and w is dirty/fast.
No state changes on a declined event.
Note
Not thread-safe.
Since
0.1.0

Definition at line 131 of file ra8_widget_toolbar.c.

References internal_tb_field_rect(), k_ra8_widget_ev_touch, k_ra8_widget_refresh_fast, ra8_widget_event_t::kind, ra8_ui_rect_contains(), ra8_widget_invalidate(), ra8_widget_event_t::x, and ra8_widget_event_t::y.

◆ internal_tb_render()

void internal_tb_render ( ra8_widget_t * w)
static

Toolbar vtable render: band fill, bordered field + hint, count chip.

Reads the ra8_widget_toolbar_t from w->ctx, fills the band with bg, draws the border-framed search field with its left-aligned hint, then the right-aligned count chip – each through the paint backend and only when a draw_text callback is present.

Parameters
[in]wThe toolbar widget (its ctx is a ra8_widget_toolbar_t).
Returns
Nothing.
Precondition
w is non-NULL (guaranteed by ra8_widget_render_dirty).
w->ctx points at a valid toolbar descriptor or is NULL.
Postcondition
At most a band fill, a framed field, a hint draw and a count draw run.
No pixels are touched when the toolbar has no paint backend.
Note
Not thread-safe.
Since
0.1.0

Definition at line 81 of file ra8_widget_toolbar.c.

References internal_tb_field_rect(), k_ra8_widget_align_left, k_ra8_widget_align_right, priv_widget_fill_box(), and priv_widget_text_pos().

◆ ra8_widget_toolbar_init()

ra8_err_t ra8_widget_toolbar_init ( ra8_widget_t * w,
ra8_widget_toolbar_t * bar )
nodiscard

Bind a widget instance to a toolbar.

Wires w to render + route bar: sets its vtable to ra8_widget_toolbar_vtable, points its ctx at bar, and makes it visible. The caller still sets w's fixed / flex for its parent's layout.

Parameters
[in,out]wWidget to turn into a toolbar (non-NULL).
[in]barToolbar descriptor (non-NULL; outlives w's use).
Returns
ra8_err_t
Return values
k_ra8_okBound; w renders + routes bar.
k_ra8_err_null_ptrw or bar is NULL.
Precondition
w and bar are non-NULL.
bar outlives every render / dispatch of w.
Postcondition
On success w->vt == ra8_widget_toolbar_vtable(), w->ctx == bar, w->visible == true.
On failure w is left unchanged.
Note
Not thread-safe.
See also
ra8_widget_toolbar_vtable
Since
0.1.0

Definition at line 164 of file ra8_widget_toolbar.c.

References k_ra8_ok, RA8_CHECK_NULL_PTR, ra8_widget_toolbar_vtable(), and s_tag.

◆ ra8_widget_toolbar_vtable()

const ra8_widget_vtable_t * ra8_widget_toolbar_vtable ( void )

Return the shared vtable backing every toolbar widget.

One immutable vtable serves all toolbars: render fills the band, the bordered search field + hint, and the count chip through the toolbar's ra8_widget_paint_t; on_input latches a touch inside the search field and declines everything else; measure is NULL. ra8_widget_toolbar_init binds it.

Returns
Non-NULL pointer to the static toolbar vtable.
Precondition
None.
None.
Postcondition
The returned pointer is non-NULL and references static storage.
No state is modified.
Note
Pure; thread-safe (returns a pointer to immutable static data).
See also
ra8_widget_toolbar_init
Since
0.1.0

Definition at line 159 of file ra8_widget_toolbar.c.

References s_tb_vt.

Referenced by ra8_widget_toolbar_init(), and wd_build_tree().

Variable Documentation

◆ s_tag

const char* s_tag = "ra8_widget_toolbar"
static

Logging / check tag.

Definition at line 31 of file ra8_widget_toolbar.c.

◆ s_tb_vt

const ra8_widget_vtable_t s_tb_vt
static
Initial value:
= {
.measure = nullptr,
.render = internal_tb_render,
.on_input = internal_tb_on_input,
}
static bool internal_tb_on_input(ra8_widget_t *w, const ra8_widget_event_t *ev)
Toolbar vtable input: latch a touch inside the search field.
static void internal_tb_render(ra8_widget_t *w)
Toolbar vtable render: band fill, bordered field + hint, count chip.

The single immutable vtable shared by every toolbar.

Definition at line 153 of file ra8_widget_toolbar.c.

Referenced by ra8_widget_toolbar_vtable().