Moved some code around.
This commit is contained in:
@ -8,8 +8,10 @@
|
||||
#include "frame.h"
|
||||
#include "textmenu.h"
|
||||
|
||||
/** The default gutter for the grid of a framed text menu */
|
||||
#define FRAMED_TEXT_MENU_GUTTER_DEFAULT 8.0f
|
||||
|
||||
typedef struct {
|
||||
frame_t frame;
|
||||
textmenu_t menu;
|
||||
float width, height;
|
||||
} framedtextmenu_t;
|
@ -8,68 +8,33 @@
|
||||
#pragma once
|
||||
#include "../libs.h"
|
||||
|
||||
/** Maximum number of breakpoints a grid can support */
|
||||
#define GRID_BREAKPOINT_COUNT 4
|
||||
/** Maximum number of columns a grid can have */
|
||||
#define GRID_COLUMN_COUNT_MAX 16
|
||||
/** Maximum number of rows a grid can have */
|
||||
#define GRID_ROW_COUNT_MAX GRID_COLUMN_COUNT_MAX
|
||||
|
||||
/** Max number of children that a grid can support */
|
||||
#define GRID_CHILD_COUNT 32
|
||||
|
||||
/** Definition of a breakpoint */
|
||||
typedef struct {
|
||||
float width;
|
||||
} breakpointsize_t;
|
||||
|
||||
/** Definition of a grid breakpoint */
|
||||
typedef struct {
|
||||
uint8_t rows;
|
||||
uint8_t columns;
|
||||
float gutterX;
|
||||
float gutterY;
|
||||
} gridbreakpoint_t;
|
||||
|
||||
/** Definition of a grid child's breakpoint */
|
||||
typedef struct {
|
||||
uint8_t columns;
|
||||
uint8_t rows;
|
||||
uint8_t x;
|
||||
uint8_t y;
|
||||
} gridchildbreakpoint_t;
|
||||
|
||||
/** Callback to receive when a grid child is to be resized */
|
||||
typedef void gridchildresizecallback_t(
|
||||
void *user, uint8_t i, gridchildbreakpoint_t *breakpoint,
|
||||
float screenWidth, float screenHeight,
|
||||
float x, float y,
|
||||
float width, float height
|
||||
);
|
||||
|
||||
/** Definition of a grid child */
|
||||
typedef struct {
|
||||
gridchildbreakpoint_t breakpoints[GRID_BREAKPOINT_COUNT];
|
||||
uint8_t breakpointCount;
|
||||
} gridchild_t;
|
||||
/** Cell size for "auto", basically to fill the remaining space evenly */
|
||||
#define GRID_CEL_SIZE_AUTO -1
|
||||
|
||||
/** Definitio of a grid */
|
||||
typedef struct {
|
||||
/** Breakpoints */
|
||||
gridbreakpoint_t breakpoints[GRID_BREAKPOINT_COUNT];
|
||||
breakpointsize_t breakpointSizes[GRID_BREAKPOINT_COUNT];
|
||||
uint8_t breakpointCount;
|
||||
uint8_t breakpointCurrent;
|
||||
/** Count of columns/rows in the grid */
|
||||
uint8_t columns, rows;
|
||||
|
||||
/** Child items of the grid */
|
||||
gridchild_t children[GRID_CHILD_COUNT];
|
||||
uint8_t childCount;
|
||||
/** Cell Definitions, used to control how the cells will size themselves */
|
||||
float columnDefinitions[GRID_COLUMN_COUNT_MAX];
|
||||
float rowDefinitions[GRID_COLUMN_COUNT_MAX];
|
||||
|
||||
/** Settings to control gutters (space between cells) and border (of grid) */
|
||||
float gutterX, gutterY;
|
||||
float borderX, borderY;
|
||||
|
||||
/** Internal size reference, used for caching resize events */
|
||||
float width;
|
||||
float height;
|
||||
float x;
|
||||
float y;
|
||||
/** Calculated sizes and positions for each cell */
|
||||
float columnSizes[GRID_COLUMN_COUNT_MAX];
|
||||
float columnPositions[GRID_COLUMN_COUNT_MAX];
|
||||
float rowSizes[GRID_ROW_COUNT_MAX];
|
||||
float rowPositions[GRID_COLUMN_COUNT_MAX];
|
||||
|
||||
/** Pointer to any custom user data */
|
||||
void *user;
|
||||
|
||||
/** Callback to listen for when children are resized */
|
||||
gridchildresizecallback_t *onResize;
|
||||
/** Cached size of the grid */
|
||||
float width, height;
|
||||
} grid_t;
|
@ -7,17 +7,27 @@
|
||||
|
||||
#pragma once
|
||||
#include "../libs.h"
|
||||
#include "grid.h"
|
||||
|
||||
/** Generic callback for menu events */
|
||||
/** The maximum number of items a menu can hold */
|
||||
#define MENU_ITEMS_MAX 32
|
||||
|
||||
/** Callback for when menu events are fired. */
|
||||
typedef void menucallback_t(void *user, uint8_t i);
|
||||
|
||||
/** Structure for a menu */
|
||||
typedef struct {
|
||||
grid_t grid;
|
||||
uint8_t x;
|
||||
uint8_t y;
|
||||
uint8_t width;
|
||||
uint8_t height;
|
||||
} menuitem_t;
|
||||
|
||||
typedef struct {
|
||||
menuitem_t items[MENU_ITEMS_MAX];
|
||||
uint8_t itemCount;
|
||||
uint8_t selected;
|
||||
uint8_t cursorX;
|
||||
uint8_t cursorY;
|
||||
|
||||
void *user;
|
||||
menucallback_t *onSelect;
|
||||
} menu_t;
|
||||
} menu_t;
|
@ -11,23 +11,20 @@
|
||||
#include "label.h"
|
||||
#include "rectangle.h"
|
||||
|
||||
/** Colour of the selection box for the text menu */
|
||||
#define TEXTMENU_SELECTION_COLOR ((pixel_t){.r=0xFF,.g=0xFF,.b=0xFF,.a=0x64})
|
||||
|
||||
/** Callback type for when an item is selected */
|
||||
typedef void textmenucallback_t(void *user, uint8_t i, char *text);
|
||||
|
||||
typedef struct {
|
||||
float x, y;
|
||||
float width, height;
|
||||
} textmenulabelinfo_t;
|
||||
|
||||
typedef struct {
|
||||
menu_t menu;
|
||||
char *texts[GRID_CHILD_COUNT];
|
||||
|
||||
grid_t grid;
|
||||
font_t *font;
|
||||
label_t labels[GRID_CHILD_COUNT];
|
||||
rectangle_t rectangle;
|
||||
textmenulabelinfo_t labelInfo[GRID_CHILD_COUNT];
|
||||
|
||||
char *texts[MENU_ITEMS_MAX];
|
||||
label_t labels[MENU_ITEMS_MAX];
|
||||
|
||||
textmenucallback_t *onSelect;
|
||||
void *user;
|
||||
|
Reference in New Issue
Block a user