Skip to content

Commit

Permalink
added container example
Browse files Browse the repository at this point in the history
  • Loading branch information
ColleagueRiley committed Mar 1, 2024
1 parent 2901e27 commit fe15387
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
6 changes: 6 additions & 0 deletions examples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ all:
make text
make glfw
make button
make container

debug:
gcc basic.c $(LIBS) $(ARGS) -o basic
Expand All @@ -41,6 +42,7 @@ debug:
gcc text.c $(LIBS) $(ARGS) -o text
gcc glVer.c $(LIBS) $(ARGS) -o glVer
gcc button.c $(LIBS) $(ARGS) -o button
gcc container.c $(LIBS) $(ARGS) -o container

./events
./shapes
Expand All @@ -49,6 +51,7 @@ debug:
./glVer
./basic
./button
./container

glfw:
gcc glfw.c -lglfw -lm -I../ -o glfw
Expand All @@ -74,5 +77,8 @@ basic:
button:
gcc button.c $(LIBS) $(ARGS) -o button

container:
gcc container.c $(LIBS) $(ARGS) -o container

clean:
rm -f events glfw shapes textures RSGL.o *.exe
80 changes: 80 additions & 0 deletions examples/container.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#define RSGL_NO_AUDIO
#define RSGL_IMPLEMENTATION
#include "RSGL.h"

int main() {
RSGL_window* win = RSGL_createWindow("name", (RSGL_rect){500, 500, 500, 500}, RSGL_CENTER);

/* generic button */
RSGL_button generic = RSGL_initButton();
/* this can be a rect or polygon */
RSGL_button_setRect(&generic, RSGL_RECT(50, 50, 100, 50));

RSGL_setFont(RSGL_loadFont("SansPosterBold.ttf"));

RSGL_button_setText(&generic, "generic", 8, RSGL_CIRCLE(0, 0, 15), RSGL_RGB(100, 100, 100));
RSGL_button_alignText(&generic, RSGL_ALIGN_CENTER | RSGL_ALIGN_MIDDLE);

RSGL_button_setStyle(&generic, RSGL_STYLE_DARK | RSGL_STYLE_ROUNDED);

RSGL_button comboBox = RSGL_initButton();
char* combos[3] = {"comboBox 0", "comboBox 1", "comboBox 2"};
RSGL_button_setCombo(&comboBox, combos, 3);

/* this can be a rect or polygon */
RSGL_button_setRect(&comboBox, RSGL_RECT(200, 50, 200, 50));
RSGL_button_setText(&comboBox, "", 11, RSGL_CIRCLE(0, 0, 15), RSGL_RGB(100, 100, 100));
RSGL_button_alignText(&comboBox, RSGL_ALIGN_LEFT | RSGL_ALIGN_MIDDLE);
RSGL_button_setStyle(&comboBox, RSGL_STYLE_DARK | RSGL_STYLE_COMBOBOX);

/* generic toggle button */
RSGL_button genericToggle = RSGL_initButton();
RSGL_button_setPolygon(&genericToggle, RSGL_RECT(50, 125, 100, 50), 36);

RSGL_button_setStyle(&genericToggle, RSGL_STYLE_DARK | RSGL_STYLE_TOGGLE | RSGL_STYLE_ROUNDED);

/* generic checkbox button */
RSGL_button checkbox = RSGL_initButton();
RSGL_button_setRect(&checkbox, RSGL_RECT(50, 250, 50, 50));
RSGL_button_setStyle(&checkbox, RSGL_STYLE_DARK | RSGL_STYLE_CHECKBOX);

/* generic radio buttons */
RSGL_button radioButtons = RSGL_initButton();
RSGL_button_setPolygon(&radioButtons, RSGL_RECT(50, 320, 15, 15), 36);
RSGL_button_setRadioCount(&radioButtons, 3);
RSGL_button_setStyle(&radioButtons, RSGL_STYLE_DARK | RSGL_STYLE_RADIO);

RSGL_button null = RSGL_nullButton();

RSGL_button buttons[] = {
null, generic, null,
checkbox, null, generic,
null, null, null,
radioButtons, null, null,
comboBox,
};

RSGL_container container = RSGL_initContainer(RSGL_RECT(50, 50, 300, 400), buttons, 13);
RSGL_container_setStyle(&container, RSGL_STYLE_DARK | RSGL_STYLE_ROUNDED | RSGL_STYLE_CONTAINER);

bool running = true;
while (running) {
while (RSGL_window_checkEvent(win)) {
if (win->event.type == RSGL_quit) {
running = false;
break;
}

if (win->event.type == RSGL_mouseButtonReleased && win->event.button == RSGL_mouseRight)
RSGL_container_setPos(&container, win->event.point);

RSGL_container_update(&container, win->event);
}

RSGL_drawContainer(container);

RSGL_window_clear(win, RSGL_RGB(20, 20, 60));
}

RSGL_window_close(win);
}

0 comments on commit fe15387

Please sign in to comment.