forked from Lephenixnoir/hex-editor
62 lines
1.8 KiB
C
62 lines
1.8 KiB
C
// hlist: A basic list selector
|
|
//
|
|
// This is like jfileselect, but for custom items. And also, maybe, a base for
|
|
// a reasonably-generic list view backed by a reasonable list model. Who knows.
|
|
|
|
#pragma once
|
|
#include <justui/defs.h>
|
|
#include <justui/jwidget.h>
|
|
#include <gint/display.h>
|
|
|
|
/* hlist: Generic list view and selector
|
|
|
|
Events:
|
|
* HLIST_VALIDATED
|
|
* HLIST_CANCELED */
|
|
typedef struct {
|
|
jwidget widget;
|
|
|
|
/* List of entries; size of individual entries; number of entries */
|
|
void *entries;
|
|
size_t entry_size;
|
|
int entry_count;
|
|
|
|
/* Height in pixels for each entry */
|
|
int render_height;
|
|
/* Renderer function */
|
|
void (*render_func)(int x, int y, int w, int h, void *entry,bool selected);
|
|
|
|
/* Selected entry ID */
|
|
int selected_index;
|
|
|
|
/* Current cursor position (0 .. entry_count-1) */
|
|
int16_t cursor;
|
|
/* Current scroll position */
|
|
int16_t scroll;
|
|
/* Number of visible lines */
|
|
int8_t visible_lines;
|
|
|
|
} hlist;
|
|
|
|
/* Event IDs */
|
|
extern uint16_t HLIST_VALIDATED;
|
|
extern uint16_t HLIST_CANCELED;
|
|
|
|
/* hlist_create(): Create a list view and selector
|
|
Initially, there is no data and the widget does not handle events. */
|
|
hlist *hlist_create(void *parent);
|
|
|
|
/* hlist_set_entries(): Load the model (list of entries) */
|
|
void hlist_set_entries(hlist *l, void *entries, size_t entry_size, int count);
|
|
|
|
/* hlist_set_renderer(): Set the rendering settings for the entries
|
|
The rendering function should be of type:
|
|
void render(int x, int y, int width, int height,
|
|
void *pointer_to_entry, bool selected); */
|
|
void hlist_set_renderer(hlist *h, int entry_height, void *render);
|
|
|
|
/* hlist_selected_index(): Index of the selected entry
|
|
The selected index is -1 until hlist_set_entries() is called and the user
|
|
selects an entry in the interface. */
|
|
int hlist_selected_index(hlist *l);
|