kettek2/wiki/games/newsboy/Newsboy_0x00/engine/Ui.h

88 lines
2.5 KiB
C

#ifndef UI_H
#define UI_H
#include <SDL2/SDL.h>
#include "Primitives.h"
#include "Text.h"
// state flaga
#define UI_SELECTED 1
#define UI_ACTIVE 2
// property flags
#define UI_BORDER 1
#define UI_RELATIVE 2 // relative positioning if within another element
struct Ui_Colors {
SDL_Color fg; // default fg (text/border)
SDL_Color bg; // default bg
SDL_Color a_fg; // active foreground(text/border)
SDL_Color a_bg; // active background
SDL_Color f_fg; // focused fg
SDL_Color f_bg; // focused bg
};
struct List {
struct Box box;
int page; // current page
int items_per_page; // bad name?
int count; // count of items
int selected;
struct Button **items; // item ptr, can be TextInput, Button, etc.
struct Ui_Colors *colors;
};
struct List *newList(struct Ui_Colors *colors);
int freeList(struct List *list);
int initList(struct List *list);
int addListItem(struct List *list, struct Button *item);
int remListIndex(struct List *list, int index);
int remListItem(struct List *list, struct Button *item);
int freeListItems(struct List *list);
int prepList(struct List *list);
int renderList(struct List *list);
struct Box getListItemBox(struct List *list, int i);
struct Box getListItemBoxAbs(struct List *list, int i);
struct Button {
struct Box box;
struct Glyphs *glyphs;
char *text;
int p_flags; // property flag
int flags;
struct Ui_Colors *colors;
};
struct Button *newButton(struct Glyphs *glyphs, struct Ui_Colors *colors, const char *string);
int freeButton(struct Button *button);
int setButtonText(struct Button *button, const char *string);
int renderButton(struct Button *button);
struct TextInput {
struct Box box;
struct Glyphs *glyphs;
int cursor;
char *text;
int flags;
int p_flags;
struct Ui_Colors *colors;
};
struct TextInput *newTextInput(struct Glyphs *glyphs, struct Ui_Colors *colors, int width);
int freeTextInput(struct TextInput *input);
int insertTextInput(struct TextInput *text_input, const char *string);
int deleteTextInput(struct TextInput *text_input, int start, int length);
int setTextInputText(struct TextInput *text_input, const char *string, ...);
int renderTextInput(struct TextInput *input);
struct Textt {
struct Box box;
struct Glyphs *glyphs;
char *text;
int flags;
int p_flags;
struct Ui_Colors *colors;
};
struct Textt *newTextt(struct Glyphs *glyphs, struct Ui_Colors *colors, const char *string);
int freeTextt(struct Textt *text);
int setTextt(struct Textt *text, const char *string, ...);
int addTexttChar(struct Textt *text, char ch);
int renderTextt(struct Textt *text);
#endif