80 lines
2.4 KiB
C
80 lines
2.4 KiB
C
//---
|
|
// ft.widgets.flist: Scrolling list with selectable elements
|
|
//---
|
|
|
|
#ifndef _FT_WIDGETS_FLIST_H_
|
|
#define _FT_WIDGETS_FLIST_H_
|
|
|
|
#include <justui/jwidget.h>
|
|
#include <gint/display.h>
|
|
#include <gint/defs/call.h>
|
|
|
|
/* flist: A scrolling list with a selection cursor
|
|
|
|
This widget is a list of horizontal entries of a fixed height. The rendering
|
|
of entries and data storage is delegated to caller code. This widget only
|
|
handles the geometry and has no idea about the contents of the entries. */
|
|
typedef struct flist {
|
|
jwidget widget;
|
|
/* Renderer function */
|
|
gint_call_t renderer;
|
|
/* Number of rows, number of rows visible on-screen, current top row, and
|
|
currently-selected row (-1 if none) */
|
|
uint16_t rows;
|
|
uint16_t visible;
|
|
uint16_t top;
|
|
int16_t selected;
|
|
/* Row height */
|
|
uint16_t row_height;
|
|
/* Parameters available during rendering */
|
|
int16_t x, y;
|
|
int16_t row;
|
|
} flist;
|
|
|
|
/* The cursor has moved to a different entry */
|
|
extern uint16_t FLIST_SELECTED;
|
|
/* The current entry has been validated with EXE */
|
|
extern uint16_t FLIST_VALIDATED;
|
|
|
|
/* flist_create(): Create a scrolling list
|
|
Rows are dynamic, this function only sets the rendering function, which
|
|
should have the following prototype:
|
|
|
|
void render(flist *f, ...);
|
|
|
|
The GINT_CALL() for the renderer can use argument 2 to 4, the first will be
|
|
overridden by the flist code during the call.
|
|
|
|
The renderer can access the dimensions and row_height setting of the flist
|
|
widget, as well as draw_x, draw_y, draw_row and selected. Note however that
|
|
a couple of pixels may be reserved on the right to render a scrollbar. */
|
|
flist *flist_create(gint_call_t renderer, void *parent);
|
|
|
|
/* flist_set_renderer(): Change renderer after creation */
|
|
void flist_set_renderer(flist *l, gint_call_t renderer);
|
|
|
|
//---
|
|
// Configuration of rows
|
|
//---
|
|
|
|
/* flist_set_rows(): Set the number of rows */
|
|
void flist_set_rows(flist *l, int rows);
|
|
|
|
/* flist_set_row_height(): Fix the row height for every row */
|
|
void flist_set_row_height(flist *l, int row_height);
|
|
|
|
//---
|
|
// Movement
|
|
//---
|
|
|
|
/* flist_scroll_to(): Scroll to the specified offset */
|
|
void flist_scroll_to(flist *l, int offset);
|
|
|
|
/* flist_select(): Select an entry and scroll to it if needed */
|
|
void flist_select(flist *l, int entry);
|
|
|
|
/* flist_end(): Offset of the end of the list */
|
|
int flist_end(flist *l);
|
|
|
|
#endif /* _FT_WIDGETS_FLIST_H_ */
|