2016-11-27 16:36:11 -06:00
|
|
|
// 20 june 2016
|
|
|
|
// kept in a separate file for now
|
|
|
|
|
2018-08-05 16:52:15 -05:00
|
|
|
// uiImage stores an image for display on screen.
|
|
|
|
//
|
|
|
|
// Images are built from one or more representations, each with the
|
|
|
|
// same aspect ratio but a different pixel size. libui automatically
|
|
|
|
// selects the most appropriate representation for drawing the image
|
|
|
|
// when it comes time to draw the image; what this means depends
|
|
|
|
// on the pixel density of the target context. Therefore, one can use
|
|
|
|
// uiImage to draw higher-detailed images on higher-density
|
|
|
|
// displays. The typical use cases are either:
|
|
|
|
//
|
|
|
|
// - have just a single representation, at which point all screens
|
|
|
|
// use the same image, and thus uiImage acts like a simple
|
|
|
|
// bitmap image, or
|
|
|
|
// - have two images, one at normal resolution and one at 2x
|
|
|
|
// resolution; this matches the current expectations of some
|
|
|
|
// desktop systems at the time of writing (mid-2018)
|
|
|
|
//
|
|
|
|
// uiImage is very simple: it only supports non-premultiplied 32-bit
|
|
|
|
// ARGB images, and libui does not provide any image file loading
|
|
|
|
// or image format conversion utilities on top of that.
|
2016-11-27 16:36:11 -06:00
|
|
|
typedef struct uiImage uiImage;
|
|
|
|
|
2018-08-05 16:52:15 -05:00
|
|
|
// @role uiImage constructor
|
|
|
|
// uiNewImage creates a new uiImage with the given width and
|
|
|
|
// height. This width and height should be the size in points of the
|
|
|
|
// image in the device-independent case; typically this is the 1x size.
|
|
|
|
// TODO for all uiImage functions: use const void * for const correctness
|
2016-11-27 16:36:11 -06:00
|
|
|
_UI_EXTERN uiImage *uiNewImage(double width, double height);
|
2018-08-05 16:52:15 -05:00
|
|
|
|
|
|
|
// @role uiImage destructor
|
|
|
|
// uiFreeImage frees the given image and all associated resources.
|
2016-11-27 16:36:11 -06:00
|
|
|
_UI_EXTERN void uiFreeImage(uiImage *i);
|
2018-08-05 16:52:15 -05:00
|
|
|
|
|
|
|
// uiImageAppend adds a representation to the uiImage.
|
|
|
|
// pixels should point to a byte array of non-premultiplied pixels
|
2018-08-05 17:39:29 -05:00
|
|
|
// stored in [R G B A] order (so ((uint8_t *) pixels)[0] is the A of the
|
2018-08-05 16:52:15 -05:00
|
|
|
// first pixel and [3] is the B of the first pixel). pixelWidth and
|
|
|
|
// pixelHeight is the size *in pixels* of the image, and pixelStride is
|
2018-08-05 17:39:29 -05:00
|
|
|
// the number *of bytes* per row of the pixels array. Therefore,
|
|
|
|
// pixels itself must be at least byteStride * pixelHeight bytes long.
|
|
|
|
_UI_EXTERN void uiImageAppend(uiImage *i, void *pixels, int pixelWidth, int pixelHeight, int byteStride);
|
2016-11-27 16:36:11 -06:00
|
|
|
|
2018-06-23 19:19:30 -05:00
|
|
|
typedef struct uiTableValue uiTableValue;
|
2018-06-03 16:18:01 -05:00
|
|
|
|
2018-06-23 19:19:30 -05:00
|
|
|
_UI_EXTERN void uiFreeTableValue(uiTableValue *v);
|
2016-11-27 16:36:11 -06:00
|
|
|
|
|
|
|
// TODO actually validate these
|
2018-06-23 19:19:30 -05:00
|
|
|
_UI_ENUM(uiTableValueType) {
|
|
|
|
uiTableValueTypeString,
|
|
|
|
uiTableValueTypeImage,
|
|
|
|
uiTableValueTypeInt,
|
|
|
|
uiTableValueTypeColor,
|
2016-11-27 16:36:11 -06:00
|
|
|
};
|
|
|
|
|
2018-06-03 16:18:01 -05:00
|
|
|
// TODO I don't like this name
|
2018-06-23 19:19:30 -05:00
|
|
|
_UI_EXTERN uiTableValueType uiTableValueGetType(const uiTableValue *v);
|
2018-06-03 16:18:01 -05:00
|
|
|
|
2018-06-23 19:19:30 -05:00
|
|
|
_UI_EXTERN uiTableValue *uiNewTableValueString(const char *str);
|
|
|
|
_UI_EXTERN const char *uiTableValueString(const uiTableValue *v);
|
2018-06-03 16:18:01 -05:00
|
|
|
|
2018-06-23 19:19:30 -05:00
|
|
|
_UI_EXTERN uiTableValue *uiNewTableValueImage(uiImage *img);
|
|
|
|
_UI_EXTERN uiImage *uiTableValueImage(const uiTableValue *v);
|
2018-06-03 16:18:01 -05:00
|
|
|
|
2018-06-23 19:19:30 -05:00
|
|
|
_UI_EXTERN uiTableValue *uiNewTableValueInt(int i);
|
|
|
|
_UI_EXTERN int uiTableValueInt(const uiTableValue *v);
|
2018-06-03 16:18:01 -05:00
|
|
|
|
2018-06-23 19:19:30 -05:00
|
|
|
_UI_EXTERN uiTableValue *uiNewTableValueColor(double r, double g, double b, double a);
|
|
|
|
_UI_EXTERN void uiTableValueColor(const uiTableValue *v, double *r, double *g, double *b, double *a);
|
2018-06-03 16:18:01 -05:00
|
|
|
|
|
|
|
typedef struct uiTableModel uiTableModel;
|
|
|
|
typedef struct uiTableModelHandler uiTableModelHandler;
|
|
|
|
|
2016-11-27 16:36:11 -06:00
|
|
|
// TODO validate ranges; validate types on each getter/setter call (? table columns only?)
|
|
|
|
struct uiTableModelHandler {
|
|
|
|
int (*NumColumns)(uiTableModelHandler *, uiTableModel *);
|
2018-06-23 19:19:30 -05:00
|
|
|
uiTableValueType (*ColumnType)(uiTableModelHandler *, uiTableModel *, int);
|
2016-11-27 16:36:11 -06:00
|
|
|
int (*NumRows)(uiTableModelHandler *, uiTableModel *);
|
2018-06-23 19:19:30 -05:00
|
|
|
uiTableValue *(*CellValue)(uiTableModelHandler *, uiTableModel *, int, int);
|
|
|
|
void (*SetCellValue)(uiTableModelHandler *, uiTableModel *, int, int, const uiTableValue *);
|
2016-11-27 16:36:11 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
_UI_EXTERN uiTableModel *uiNewTableModel(uiTableModelHandler *mh);
|
|
|
|
_UI_EXTERN void uiFreeTableModel(uiTableModel *m);
|
|
|
|
_UI_EXTERN void uiTableModelRowInserted(uiTableModel *m, int newIndex);
|
|
|
|
_UI_EXTERN void uiTableModelRowChanged(uiTableModel *m, int index);
|
|
|
|
_UI_EXTERN void uiTableModelRowDeleted(uiTableModel *m, int oldIndex);
|
|
|
|
// TODO reordering/moving
|
|
|
|
|
2018-06-03 11:26:23 -05:00
|
|
|
#define uiTableModelColumnNeverEditable (-1)
|
|
|
|
#define uiTableModelColumnAlwaysEditable (-2)
|
2016-11-27 16:36:11 -06:00
|
|
|
|
2018-06-03 11:26:23 -05:00
|
|
|
typedef struct uiTableTextColumnOptionalParams uiTableTextColumnOptionalParams;
|
2018-06-24 09:28:41 -05:00
|
|
|
typedef struct uiTableParams uiTableParams;
|
2018-06-03 11:26:23 -05:00
|
|
|
|
|
|
|
struct uiTableTextColumnOptionalParams {
|
|
|
|
int ColorModelColumn;
|
|
|
|
};
|
2016-11-27 16:36:11 -06:00
|
|
|
|
2018-06-24 09:28:41 -05:00
|
|
|
struct uiTableParams {
|
|
|
|
uiTableModel *Model;
|
|
|
|
int RowBackgroundColorModelColumn;
|
|
|
|
};
|
|
|
|
|
2016-11-27 16:36:11 -06:00
|
|
|
typedef struct uiTable uiTable;
|
|
|
|
#define uiTable(this) ((uiTable *) (this))
|
2018-06-03 11:26:23 -05:00
|
|
|
_UI_EXTERN void uiTableAppendTextColumn(uiTable *t,
|
|
|
|
const char *name,
|
|
|
|
int textModelColumn,
|
|
|
|
int textEditableModelColumn,
|
2018-06-24 08:52:01 -05:00
|
|
|
uiTableTextColumnOptionalParams *textParams);
|
2018-06-03 11:26:23 -05:00
|
|
|
_UI_EXTERN void uiTableAppendImageColumn(uiTable *t,
|
|
|
|
const char *name,
|
|
|
|
int imageModelColumn);
|
|
|
|
_UI_EXTERN void uiTableAppendImageTextColumn(uiTable *t,
|
|
|
|
const char *name,
|
|
|
|
int imageModelColumn,
|
|
|
|
int textModelColumn,
|
|
|
|
int textEditableModelColumn,
|
|
|
|
uiTableTextColumnOptionalParams *textParams);
|
|
|
|
_UI_EXTERN void uiTableAppendCheckboxColumn(uiTable *t,
|
|
|
|
const char *name,
|
|
|
|
int checkboxModelColumn,
|
|
|
|
int checkboxEditableModelColumn);
|
|
|
|
_UI_EXTERN void uiTableAppendCheckboxTextColumn(uiTable *t,
|
|
|
|
const char *name,
|
|
|
|
int checkboxModelColumn,
|
|
|
|
int checkboxEditableModelColumn,
|
|
|
|
int textModelColumn,
|
|
|
|
int textEditableModelColumn,
|
|
|
|
uiTableTextColumnOptionalParams *textParams);
|
|
|
|
_UI_EXTERN void uiTableAppendProgressBarColumn(uiTable *t,
|
|
|
|
const char *name,
|
|
|
|
int progressModelColumn);
|
|
|
|
_UI_EXTERN void uiTableAppendButtonColumn(uiTable *t,
|
|
|
|
const char *name,
|
2018-06-24 08:52:01 -05:00
|
|
|
int buttonModelColumn,
|
2018-06-03 11:26:23 -05:00
|
|
|
int buttonClickableModelColumn);
|
2018-06-24 09:28:41 -05:00
|
|
|
_UI_EXTERN uiTable *uiNewTable(uiTableParams *params);
|