Add layouts and decouple immediate drawings
This commit is contained in:
32
src/k3menu.h
32
src/k3menu.h
@@ -3,8 +3,9 @@
|
||||
#include<stdint.h>
|
||||
#include<stdlib.h>
|
||||
#include<stdbool.h>
|
||||
#include"k3font.h"
|
||||
#include<stddef.h>
|
||||
|
||||
struct k3Font;
|
||||
struct k3MObj;
|
||||
|
||||
#define k3M_EVENT_MOUSE_ENTER 0
|
||||
@@ -18,7 +19,9 @@ struct k3MObj;
|
||||
#define k3M_EVENT_INPUT 8
|
||||
#define k3M_EVENT_DRAW 9
|
||||
#define k3M_EVENT_COMPLETE 10
|
||||
#define k3M_EVENT_ALL 11
|
||||
#define k3M_EVENT_MEASURE 11
|
||||
#define k3M_EVENT_ARRANGE 12
|
||||
#define k3M_EVENT_ALL 13
|
||||
|
||||
#define k3M_MOUSE_BUTTON_0 0
|
||||
#define k3M_MOUSE_BUTTON_1 1
|
||||
@@ -30,6 +33,16 @@ struct k3MObj;
|
||||
|
||||
#define k3M_USERDATA_SIZE 16
|
||||
|
||||
#define k3M_ALIGN_LEFT 0
|
||||
#define k3M_ALIGN_CENTER 1
|
||||
#define k3M_ALIGN_RIGHT 2
|
||||
|
||||
#ifdef k3M_FIXED_POINT
|
||||
typedef uint8_t k3MCC;
|
||||
#else
|
||||
typedef float k3MCC;
|
||||
#endif
|
||||
|
||||
struct k3MEvent {
|
||||
uint16_t code;
|
||||
|
||||
@@ -64,6 +77,8 @@ typedef struct k3MEventHandler {
|
||||
enum k3MPropertyType {
|
||||
k3M_PROP_BG_COLOR,
|
||||
k3M_PROP_BORDER_RADIUS,
|
||||
k3M_PROP_MARGIN,
|
||||
k3M_PROP_HORIZONTAL_ALIGNMENT,
|
||||
};
|
||||
struct k3MProperty {
|
||||
enum k3MPropertyType type;
|
||||
@@ -85,6 +100,9 @@ struct k3MObj {
|
||||
int16_t w;
|
||||
int16_t h;
|
||||
|
||||
int16_t wDesired;
|
||||
int16_t hDesired;
|
||||
|
||||
bool invisible, hovered, disabled;
|
||||
|
||||
k3MEventHandler *handlers;
|
||||
@@ -93,6 +111,16 @@ struct k3MObj {
|
||||
struct k3MProperty *properties;
|
||||
size_t propertyCount;
|
||||
};
|
||||
struct k3MObj *k3MObj();
|
||||
|
||||
/* Akin to the measure pass of WPF. Recursive, called by parent. Sets wDesired and hDesired. */
|
||||
void k3MMeasure(struct k3MObj *this);
|
||||
|
||||
/* Akin to the arrange pass of WPF. Recursive, called by parent after w and h is set. Adjusts all children using it's own definitive size. */
|
||||
void k3MArrange(struct k3MObj *this);
|
||||
|
||||
/* Set linear layout management on this object. Must not be called on descendants of k3MObj. */
|
||||
void k3MSetLayoutLinear(struct k3MObj *this, bool vertical);
|
||||
|
||||
#define k3MenuSetBounds(a, x, y, w, h) k3MenuSetBounds_((struct k3MObj*) (a), (x), (y), (w), (h))
|
||||
void k3MenuSetBounds_(struct k3MObj *this, int16_t x, int16_t y, int16_t w, int16_t h);
|
||||
|
||||
Reference in New Issue
Block a user