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

chart_axis.h — the visible range of a chart, 1/2/5 tick selection for value and time axes, time labels, and the axis grid painter. More...

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

Data Structures

struct  rmgui_chart_view_t
 Visible chart value range [v0, v1] and time window [t0, t1] in ms. More...

Macros

#define RMGUI_CHART_VIEW_T_DEFINED

Functions

size_t rmgui_chart_ticks (int32_t v0, int32_t v1, int max_ticks, int32_t *out, size_t cap)
 Ticks for the value range [v0, v1]: the step is the least of 1, 2, 5, 10, 20, 50, ... whose multiples in [v0, v1] number at most max_ticks, and the ticks are those multiples in ascending order (possibly none).
size_t rmgui_chart_time_ticks (uint32_t t0, uint32_t t1, int max_ticks, uint32_t *out, size_t cap)
 rmgui_chart_ticks for the time window [t0, t1] in ms: the step is the least of 1, 2, 5, 10, ... ms whose multiples in [t0, t0 + (t1 - t0)] (counted without wrapping) number at most max_ticks; each tick is written as that multiple reduced mod 2^32, ascending in wrapping order.
size_t rmgui_chart_time_label (uint32_t t_ms, char *out, size_t cap)
 Formats t_ms, floored to whole seconds, as "m:ss" below one hour and "h:mm:ss" from one hour on (0 -> "0:00", 59999 -> "0:59", 3600000 -> "1:00:00"; at most 10 characters).
void rmgui_chart_axis_paint (rmgui_fb_t *fb, rmgui_rect_t rect, rmgui_rect_t clip, const rmgui_chart_view_t *view, const rmgui_style_resolved_t *rs, rmgui_font_t *font, int font_px)
 Paints the grid of view inside rect, with L = rmgui_font_line_height( font_px):
void rmgui_chart_axis_paint_to (rmgui_target_t *, rmgui_rect_t, rmgui_rect_t, const rmgui_chart_view_t *, const rmgui_style_resolved_t *, rmgui_font_t *, int)
 Explicit destination axis paint; prepared glyphs are required for RECORD.
int rmgui_chart_axis_prepare (const rmgui_ui_t *ui)
 Prepare the time-label glyphs before recording.
int rmgui_chart_axis_draw (const rmgui_ui_t *ui, const rmgui_chart_view_t *view, rmgui_rect_t rect)
 Draw the grid and time labels for a valid view.

Detailed Description

chart_axis.h — the visible range of a chart, 1/2/5 tick selection for value and time axes, time labels, and the axis grid painter.

Values are raw int32 and never scaled; times are uint32 ms relative to an origin the caller owns, ordered with wrapping subtraction as in chart_series.h.

Macro Definition Documentation

◆ RMGUI_CHART_VIEW_T_DEFINED

#define RMGUI_CHART_VIEW_T_DEFINED

Function Documentation

◆ rmgui_chart_ticks()

size_t rmgui_chart_ticks ( int32_t v0,
int32_t v1,
int max_ticks,
int32_t * out,
size_t cap )

Ticks for the value range [v0, v1]: the step is the least of 1, 2, 5, 10, 20, 50, ... whose multiples in [v0, v1] number at most max_ticks, and the ticks are those multiples in ascending order (possibly none).

Writes at most cap of them to out and returns how many it wrote, never more than max_ticks. Returns 0 with out unchanged for NULL out, cap 0, max_ticks < 1 or v0 >= v1.

◆ rmgui_chart_time_ticks()

size_t rmgui_chart_time_ticks ( uint32_t t0,
uint32_t t1,
int max_ticks,
uint32_t * out,
size_t cap )

rmgui_chart_ticks for the time window [t0, t1] in ms: the step is the least of 1, 2, 5, 10, ... ms whose multiples in [t0, t0 + (t1 - t0)] (counted without wrapping) number at most max_ticks; each tick is written as that multiple reduced mod 2^32, ascending in wrapping order.

Returns 0 with out unchanged for NULL out, cap 0, max_ticks < 1 or a window not valid for rmgui_chart_view_t.

◆ rmgui_chart_time_label()

size_t rmgui_chart_time_label ( uint32_t t_ms,
char * out,
size_t cap )

Formats t_ms, floored to whole seconds, as "m:ss" below one hour and "h:mm:ss" from one hour on (0 -> "0:00", 59999 -> "0:59", 3600000 -> "1:00:00"; at most 10 characters).

Writes at most cap - 1 characters and a NUL, and returns the full label's length (excluding the NUL), so a return >= cap means out holds a truncated prefix. Returns 0 with out unchanged for NULL out or cap 0.

◆ rmgui_chart_axis_paint()

void rmgui_chart_axis_paint ( rmgui_fb_t * fb,
rmgui_rect_t rect,
rmgui_rect_t clip,
const rmgui_chart_view_t * view,
const rmgui_style_resolved_t * rs,
rmgui_font_t * font,
int font_px )

Paints the grid of view inside rect, with L = rmgui_font_line_height( font_px):

  • one row per value tick (rmgui_chart_ticks with max_ticks clamp(rect.h / (2 * L), 1, 16)), at y = rect.y + (v1 - v) * rect.h / (v1 - v0) (int64_t, floored), in rs->grid_strong for the value 0 and rs->grid otherwise;
  • one column per time tick (rmgui_chart_time_ticks with max_ticks clamp(rect.w / (6 * font_px), 1, 16)), at x = rect.x + (t - t0) * rect.w / (t1 - t0) (int64_t, floored), in rs->grid;
  • each time tick's rmgui_chart_time_label in rs->text at font_px through rmgui_paint_text, its line box's top-left at (x + 2, rect.y + rect.h - L). A position on the rect's far edge moves onto its last row or column. Rows paint before columns, labels last, blended. Value labels are the host's (from rmgui_chart_ticks). Writes only pixels inside the intersection of rect and clip. NULL fb, view, rs or font, font_px < 1, an invalid view, or an empty intersection paints nothing. Label drawing may fill font's glyph cache (font.h).

◆ rmgui_chart_axis_paint_to()

void rmgui_chart_axis_paint_to ( rmgui_target_t * ,
rmgui_rect_t ,
rmgui_rect_t ,
const rmgui_chart_view_t * ,
const rmgui_style_resolved_t * ,
rmgui_font_t * ,
int  )

Explicit destination axis paint; prepared glyphs are required for RECORD.

Geometry and labels match the CPU painter; bounded failures latch.

◆ rmgui_chart_axis_prepare()

int rmgui_chart_axis_prepare ( const rmgui_ui_t * ui)

Prepare the time-label glyphs before recording.

CPU targets and contexts without a font need no preparation. Returns 0 or -1 on error.

◆ rmgui_chart_axis_draw()

int rmgui_chart_axis_draw ( const rmgui_ui_t * ui,
const rmgui_chart_view_t * view,
rmgui_rect_t rect )

Draw the grid and time labels for a valid view.

With no font the axis draws nothing. Returns 0 or -1 for invalid arguments or style; paint errors are reported by the target.