RMGui 0.15.0
C11 retained-mode UI library: layout kernel, style schema, widget painters, fonts, software framebuffer
Loading...
Searching...
No Matches
tab.h File Reference

tab.h — the tab element: a bounded strip of tabs, each owning one panel, with its selection model, the tab face and the shelf the strip sits on. More...

#include <stddef.h>
#include <stdint.h>
#include "fb.h"
#include "font.h"
#include "geom.h"
#include "input.h"
#include "style.h"
#include "draw_target.h"
#include "context_menu.h"
#include "ui_context.h"

Data Structures

struct  rmgui_tab_item_t
 One tab: nonzero ids, unique within the strip, of the tab's own focus target and of its panel, plus the focus target entered on first visit to the panel (0: none). More...
struct  rmgui_tab_t
 Retained strip state, caller-owned, written by rmgui_tab_init, rmgui_tab_viewport, rmgui_tab_select and rmgui_tab_input; the host reads selected, first_visible, visible_count, sets or clears RMGUI_STYLE_STATE_DISABLED in states, and may set or clear bytes of disabled (disabling the selected tab leaves it selected). More...
struct  rmgui_tab_view_t
 Borrow an initialized tab model and an optional state->count array of NUL-terminated labels. More...
struct  rmgui_tab_event_t
struct  rmgui_tab_strip_t

Macros

#define RMGUI_TAB_NONE   UINT32_MAX
 The hover / pressed value meaning "no tab".

Typedefs

typedef int(*) rmgui_tab_strip_style_fn(void *context, rmgui_style_class_t class_id, rmgui_style_states_t states, rmgui_style_resolved_t *out)
 Resolve an authored tab or control style on demand, returning 0 or -1.

Enumerations

enum  rmgui_tab_focus_t { RMGUI_TAB_FOCUS_KEEP , RMGUI_TAB_FOCUS_ENTER_PANEL }
 Where rmgui_tab_select sends focus: the selected tab, or into its panel. More...
enum  rmgui_tab_segment_t { RMGUI_TAB_SEGMENT_SINGLE = 0 , RMGUI_TAB_SEGMENT_FIRST = 1 , RMGUI_TAB_SEGMENT_MIDDLE = 2 , RMGUI_TAB_SEGMENT_LAST = 3 }
enum  rmgui_tab_event_kind_t { RMGUI_TAB_EVENT_NONE , RMGUI_TAB_EVENT_CLOSE , RMGUI_TAB_EVENT_REORDER }

Functions

int rmgui_tab_prepare (const rmgui_ui_t *ui, const rmgui_tab_view_t *tabs, size_t index)
 Prepare one tab's label before recording without emitting commands.
int rmgui_tab_draw (const rmgui_ui_t *ui, const rmgui_tab_view_t *tabs, size_t index, rmgui_rect_t box)
 Draw one tab face from the model's current state.
int rmgui_tab_init (rmgui_tab_t *self, const rmgui_tab_item_t *items, size_t count, uint64_t *saved_focus, uint8_t *disabled, size_t capacity, size_t selected)
 Borrows count identities and caller-owned saved_focus/disabled arrays with capacity entries.
void rmgui_tab_viewport (rmgui_tab_t *self, size_t capacity)
 Shows at most capacity tabs (0 counts as 1), moving first_visible the least distance that keeps the selected tab visible.
int rmgui_tab_select (rmgui_tab_t *self, size_t index, uint64_t leaving_focus, rmgui_tab_focus_t focus, uint64_t *out_focus)
 Selects enabled tab index.
uint64_t rmgui_tab_panel (const rmgui_tab_t *self)
 Panel id of the selected tab; NULL or an empty strip returns zero.
uint64_t rmgui_tab_enter (const rmgui_tab_t *self)
 Focus target to enter the selected panel with: its remembered focus, else its first_focus (0: none).
rmgui_size_t rmgui_tab_measure (const rmgui_font_t *font, const rmgui_style_resolved_t *rs, const char *label)
 Minimum outer size of one tab: the label in font plus the TAB face inset on both sides; height max(rs->min_height, rs->line_height + both vertical insets).
void rmgui_tab_paint (rmgui_fb_t *fb, rmgui_font_t *font, const rmgui_style_resolved_t *rs, rmgui_rect_t rect, rmgui_rect_t clip, const char *label)
 Paints one tab into rect: background, border_width edges in rs->border on three sides (four unless rs->states has SELECTED), and label in font at the padding origin.
void rmgui_tab_paint_shelf (rmgui_fb_t *fb, const rmgui_style_resolved_t *rs, rmgui_rect_t strip, rmgui_rect_t clip, rmgui_rect_t selected)
 Paints TAB/TRACK once across strip for a segmented skin, before its segments; no conventional bottom gap is painted.
void rmgui_tab_paint_to (rmgui_target_t *, rmgui_font_t *, const rmgui_style_resolved_t *, rmgui_rect_t, rmgui_rect_t, const char *)
 Explicit tab destination; RECORD requires label glyphs prepared beforehand.
void rmgui_tab_paint_segment_to (rmgui_target_t *, rmgui_font_t *, const rmgui_style_resolved_t *, rmgui_rect_t, rmgui_rect_t, const char *, rmgui_tab_segment_t)
void rmgui_tab_paint_shelf_to (rmgui_target_t *, const rmgui_style_resolved_t *, rmgui_rect_t, rmgui_rect_t, rmgui_rect_t)
 Explicit shelf destination with the same border and edge ownership.
rmgui_style_states_t rmgui_tab_states (const rmgui_tab_t *self, size_t tab)
 State set of tab tab: HOVER under the pointer, PRESSED while pressed and hovered, SELECTED for the selected tab, FOCUSED for the selected tab while the strip has focus, DISABLED for a disabled tab or while the strip is.
rmgui_input_result_t rmgui_tab_input (rmgui_tab_t *self, const rmgui_rect_t *tabs, const rmgui_input_t *in)
 Applies one event.
int rmgui_tab_strip_prepare (const rmgui_ui_t *ui, const rmgui_tab_strip_t *strip, rmgui_tab_strip_style_fn resolve, void *context)
 Prepare the arranged strip's visible labels and controls before recording, without emitting commands.
int rmgui_tab_strip_draw (const rmgui_ui_t *ui, const rmgui_tab_strip_t *strip, rmgui_tab_strip_style_fn resolve, void *context)
 Draw the arranged strip, excluding its host-routed popup.
int rmgui_tab_strip_init (rmgui_tab_strip_t *, rmgui_tab_t *, const char *const *labels, const uint8_t *closable, rmgui_rect_t *rects, rmgui_rect_t *closes, rmgui_context_menu_item_t *menu_items, size_t capacity, int tab_width, int button_width)
int rmgui_tab_strip_layout (rmgui_tab_strip_t *, rmgui_rect_t)
int rmgui_tab_strip_scroll (rmgui_tab_strip_t *, int delta)
int rmgui_tab_strip_input (rmgui_tab_strip_t *, rmgui_rect_t popup, const rmgui_style_resolved_t *popup_style, const rmgui_input_t *, rmgui_input_result_t *result, rmgui_tab_event_t *event)
void rmgui_tab_strip_paint_to (rmgui_target_t *, rmgui_font_t *, const rmgui_tab_strip_t *, const rmgui_style_resolved_t *tabs, const rmgui_style_resolved_t *controls, rmgui_rect_t clip)
void rmgui_tab_strip_paint (rmgui_fb_t *, rmgui_font_t *, const rmgui_tab_strip_t *, const rmgui_style_resolved_t *, const rmgui_style_resolved_t *, rmgui_rect_t)

Detailed Description

tab.h — the tab element: a bounded strip of tabs, each owning one panel, with its selection model, the tab face and the shelf the strip sits on.

Macro Definition Documentation

◆ RMGUI_TAB_NONE

#define RMGUI_TAB_NONE   UINT32_MAX

The hover / pressed value meaning "no tab".

Typedef Documentation

◆ rmgui_tab_strip_style_fn

typedef int(*) rmgui_tab_strip_style_fn(void *context, rmgui_style_class_t class_id, rmgui_style_states_t states, rmgui_style_resolved_t *out)

Resolve an authored tab or control style on demand, returning 0 or -1.

A NULL resolver selects the UI theme's TAB and BUTTON classes.

Enumeration Type Documentation

◆ rmgui_tab_focus_t

Where rmgui_tab_select sends focus: the selected tab, or into its panel.

Enumerator
RMGUI_TAB_FOCUS_KEEP 
RMGUI_TAB_FOCUS_ENTER_PANEL 

◆ rmgui_tab_segment_t

  • Position in the visible joined bar, independent of interaction state.
Enumerator
RMGUI_TAB_SEGMENT_SINGLE 
RMGUI_TAB_SEGMENT_FIRST 
RMGUI_TAB_SEGMENT_MIDDLE 
RMGUI_TAB_SEGMENT_LAST 

◆ rmgui_tab_event_kind_t

  • Overflow-strip event. CLOSE requests removal; REORDER requests moving from to insertion (an index in the pre-move array, count means append). The host owns identity/model arrays and applies structural changes.
Enumerator
RMGUI_TAB_EVENT_NONE 
RMGUI_TAB_EVENT_CLOSE 
RMGUI_TAB_EVENT_REORDER 

Function Documentation

◆ rmgui_tab_prepare()

int rmgui_tab_prepare ( const rmgui_ui_t * ui,
const rmgui_tab_view_t * tabs,
size_t index )

Prepare one tab's label before recording without emitting commands.

Index is an absolute tab index. Returns 0 or -1.

◆ rmgui_tab_draw()

int rmgui_tab_draw ( const rmgui_ui_t * ui,
const rmgui_tab_view_t * tabs,
size_t index,
rmgui_rect_t box )

Draw one tab face from the model's current state.

The host supplies its box and owns panel and popup routing. Returns 0 or -1 for invalid arguments or style; paint errors latch on the target.

◆ rmgui_tab_init()

int rmgui_tab_init ( rmgui_tab_t * self,
const rmgui_tab_item_t * items,
size_t count,
uint64_t * saved_focus,
uint8_t * disabled,
size_t capacity,
size_t selected )

Borrows count identities and caller-owned saved_focus/disabled arrays with capacity entries.

Items and arrays must remain alive until the strip is retired; arrays must not alias one another or self. Disabled bytes are 0 or 1 and retained; saved_focus is cleared on success. Every tab starts visible. Returns 0, or -1 leaving self and storage unchanged for NULL, count outside 1..INT_MAX or above capacity, invalid disabled bytes, selected outside count or disabled, or zero/repeated tab/panel IDs.

◆ rmgui_tab_viewport()

void rmgui_tab_viewport ( rmgui_tab_t * self,
size_t capacity )

Shows at most capacity tabs (0 counts as 1), moving first_visible the least distance that keeps the selected tab visible.

Precondition: self initialized; NULL or an empty zeroed strip is a no-op.

◆ rmgui_tab_select()

int rmgui_tab_select ( rmgui_tab_t * self,
size_t index,
uint64_t leaving_focus,
rmgui_tab_focus_t focus,
uint64_t * out_focus )

Selects enabled tab index.

A nonzero leaving_focus that is not a tab id is remembered as the previously selected panel's focus. When out_focus is non-NULL it receives the focus target to move to: the tab's id for RMGUI_TAB_FOCUS_KEEP, rmgui_tab_enter's result for RMGUI_TAB_FOCUS_ENTER_PANEL. Returns 0, or -1 (nothing changed) when self is NULL, index >= count or the tab is disabled.

◆ rmgui_tab_panel()

uint64_t rmgui_tab_panel ( const rmgui_tab_t * self)

Panel id of the selected tab; NULL or an empty strip returns zero.

◆ rmgui_tab_enter()

uint64_t rmgui_tab_enter ( const rmgui_tab_t * self)

Focus target to enter the selected panel with: its remembered focus, else its first_focus (0: none).

NULL or an empty strip returns zero.

◆ rmgui_tab_measure()

rmgui_size_t rmgui_tab_measure ( const rmgui_font_t * font,
const rmgui_style_resolved_t * rs,
const char * label )

Minimum outer size of one tab: the label in font plus the TAB face inset on both sides; height max(rs->min_height, rs->line_height + both vertical insets).

rs NULL returns {0, 0}; a NULL label measures as empty.

◆ rmgui_tab_paint()

void rmgui_tab_paint ( rmgui_fb_t * fb,
rmgui_font_t * font,
const rmgui_style_resolved_t * rs,
rmgui_rect_t rect,
rmgui_rect_t clip,
const char * label )

Paints one tab into rect: background, border_width edges in rs->border on three sides (four unless rs->states has SELECTED), and label in font at the padding origin.

A selected tab is open at the bottom in a bound skin too: the built-in Remix selected tab has square bottom corners, side borders that run to the seam, and a cleared bottom edge between them, so the strip's shelf gap and the content below show through instead of an accent rule. No pixel outside the intersection of rect and clip is written. fb or rs NULL paints nothing; a NULL label paints as empty and a NULL font paints no label.

◆ rmgui_tab_paint_shelf()

void rmgui_tab_paint_shelf ( rmgui_fb_t * fb,
const rmgui_style_resolved_t * rs,
rmgui_rect_t strip,
rmgui_rect_t clip,
rmgui_rect_t selected )

Paints TAB/TRACK once across strip for a segmented skin, before its segments; no conventional bottom gap is painted.

Otherwise paints a border_width-thick rule (1 when border_width <= 0) in rs->border along strip's bottom, interrupted under selected (zero width if not shown). No pixel outside clip is written. fb or rs NULL paints nothing.

◆ rmgui_tab_paint_to()

void rmgui_tab_paint_to ( rmgui_target_t * ,
rmgui_font_t * ,
const rmgui_style_resolved_t * ,
rmgui_rect_t ,
rmgui_rect_t ,
const char *  )

Explicit tab destination; RECORD requires label glyphs prepared beforehand.

Geometry, clipping and skin semantics match rmgui_tab_paint.

◆ rmgui_tab_paint_segment_to()

void rmgui_tab_paint_segment_to ( rmgui_target_t * ,
rmgui_font_t * ,
const rmgui_style_resolved_t * ,
rmgui_rect_t ,
rmgui_rect_t ,
const char * ,
rmgui_tab_segment_t  )
  • Paint one visible segment using TAB/FACE, TAB_SEGMENT_FIRST, FILL or TAB_SEGMENT_LAST for SINGLE/FIRST/MIDDLE/LAST. Segmented skins retain SELECTED art through hover/press/focus, with DISABLED taking precedence and INACTIVE preserved. When segment art is present, it owns inter-segment dividers; the element paints none. Each segment paints its label once in resolved role ink. Paint the shelf first. Without segment declarations, behavior is unchanged and matches rmgui_tab_paint_to. Invalid position or NULL destination/style paints nothing. RECORD label preparation and clipping match rmgui_tab_paint_to.

◆ rmgui_tab_paint_shelf_to()

void rmgui_tab_paint_shelf_to ( rmgui_target_t * ,
const rmgui_style_resolved_t * ,
rmgui_rect_t ,
rmgui_rect_t ,
rmgui_rect_t  )

Explicit shelf destination with the same border and edge ownership.

◆ rmgui_tab_states()

rmgui_style_states_t rmgui_tab_states ( const rmgui_tab_t * self,
size_t tab )

State set of tab tab: HOVER under the pointer, PRESSED while pressed and hovered, SELECTED for the selected tab, FOCUSED for the selected tab while the strip has focus, DISABLED for a disabled tab or while the strip is.

A tab >= count returns NORMAL.

◆ rmgui_tab_input()

rmgui_input_result_t rmgui_tab_input ( rmgui_tab_t * self,
const rmgui_rect_t * tabs,
const rmgui_input_t * in )

Applies one event.

tabs holds the arranged rects of the visible_count tabs from first_visible. A click (press and release on the same enabled tab) selects it; LEFT/RIGHT select the previous/next enabled tab, wrapping; HOME/END select the first/last enabled tab. Selecting another tab returns CHANGE, value = its index; the host then asks rmgui_tab_enter where focus goes. Other keys are not consumed. A primary press inside a disabled tab or disabled strip returns REFUSED (value 0, consumed 1, captured 0); a tab disabled while pressed cannot activate on release. Disabled keyboard input returns NONE; hover and focus still track. self or in NULL returns NONE.

◆ rmgui_tab_strip_prepare()

int rmgui_tab_strip_prepare ( const rmgui_ui_t * ui,
const rmgui_tab_strip_t * strip,
rmgui_tab_strip_style_fn resolve,
void * context )

Prepare the arranged strip's visible labels and controls before recording, without emitting commands.

Use the same optional resolver as for drawing. Returns 0 or -1 for invalid arguments, style or preparation.

◆ rmgui_tab_strip_draw()

int rmgui_tab_strip_draw ( const rmgui_ui_t * ui,
const rmgui_tab_strip_t * strip,
rmgui_tab_strip_style_fn resolve,
void * context )

Draw the arranged strip, excluding its host-routed popup.

The optional resolver supplies styles one at a time without a caller-owned style array. Returns 0 or -1 for invalid arguments or style; paint errors latch on the target. A resolver failure does not roll back tabs that were already drawn.

◆ rmgui_tab_strip_init()

int rmgui_tab_strip_init ( rmgui_tab_strip_t * ,
rmgui_tab_t * ,
const char *const * labels,
const uint8_t * closable,
rmgui_rect_t * rects,
rmgui_rect_t * closes,
rmgui_context_menu_item_t * menu_items,
size_t capacity,
int tab_width,
int button_width )
  • Bind initialized nonempty tabs and disjoint caller arrays. Return 0 or -1 unchanged for NULL, insufficient capacity, invalid labels/closable bytes, tab_width <= 0 or button_width <= 0. No array is written by binding.

◆ rmgui_tab_strip_layout()

int rmgui_tab_strip_layout ( rmgui_tab_strip_t * ,
rmgui_rect_t  )
  • Arrange fixed-width tabs with previous/next/list buttons when overflowing, scrolling active into view. Close hit targets occupy the trailing button width (clamped to half a tab). Return 0 or -1 unchanged for invalid bounds, insufficient storage or no room for one tab plus three buttons.

◆ rmgui_tab_strip_scroll()

int rmgui_tab_strip_scroll ( rmgui_tab_strip_t * ,
int delta )
  • Scroll the viewport by signed tab count without selecting a tab; clamp at the ends. Return 0, or -1 unchanged for NULL/unarranged state.

◆ rmgui_tab_strip_input()

int rmgui_tab_strip_input ( rmgui_tab_strip_t * ,
rmgui_rect_t popup,
const rmgui_style_resolved_t * popup_style,
const rmgui_input_t * ,
rmgui_input_result_t * result,
rmgui_tab_event_t * event )
  • Extended input: close targets, auxiliary button 2 closes, drag reorder after 4 pixels with insertion marker, scroll buttons/wheel and overflow popup. Event is replaced on every valid call (NONE if no structural event). Base tab selection/keyboard semantics are retained. Popup rect/style are caller arranged; NULL required pointers refuse without mutation.

◆ rmgui_tab_strip_paint_to()

void rmgui_tab_strip_paint_to ( rmgui_target_t * ,
rmgui_font_t * ,
const rmgui_tab_strip_t * ,
const rmgui_style_resolved_t * tabs,
const rmgui_style_resolved_t * controls,
rmgui_rect_t clip )
  • Paint visible tabs, close/scroll/list controls and pending insertion marker through extension-resolved styles (one per tab and one for controls). RECORD labels/control glyphs must be prepared. NULL paints nothing.

◆ rmgui_tab_strip_paint()

void rmgui_tab_strip_paint ( rmgui_fb_t * ,
rmgui_font_t * ,
const rmgui_tab_strip_t * ,
const rmgui_style_resolved_t * ,
const rmgui_style_resolved_t * ,
rmgui_rect_t  )
  • CPU equivalent with identical geometry and clipping.