feat: initial
This commit is contained in:
commit
80e1b84cb4
14 changed files with 7302 additions and 0 deletions
59
src/library.c
Normal file
59
src/library.c
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
#include "library.h"
|
||||
#include "clay.h"
|
||||
|
||||
bool static sidebar_open = true;
|
||||
|
||||
Clay_Color const SIDEBAR_COLOR = {120.f, 120.f, 120.f, 255.f};
|
||||
|
||||
Clay_LayoutConfig const SIDEBAR_LAYOUT = {
|
||||
.sizing={
|
||||
.height=CLAY_SIZING_GROW(),
|
||||
.width=CLAY_SIZING_FIXED(300)
|
||||
},
|
||||
.layoutDirection=CLAY_TOP_TO_BOTTOM
|
||||
};
|
||||
|
||||
Clay_RectangleElementConfig const SIDEBAR_RECTANGLE = {
|
||||
.color=SIDEBAR_COLOR,
|
||||
};
|
||||
|
||||
static
|
||||
void render_composit_library_sidebar() {
|
||||
CLAY(CLAY_ID("Sidebar"),
|
||||
CLAY_LAYOUT(SIDEBAR_LAYOUT),
|
||||
CLAY_RECTANGLE(SIDEBAR_RECTANGLE)
|
||||
) {
|
||||
CLAY(CLAY_ID("SidebarTab"),
|
||||
CLAY_FLOATING({
|
||||
.attachment={
|
||||
.element=CLAY_ATTACH_POINT_LEFT_TOP,
|
||||
.parent=CLAY_ATTACH_POINT_RIGHT_TOP
|
||||
}
|
||||
}),
|
||||
CLAY_LAYOUT({
|
||||
.sizing={.width=CLAY_SIZING_FIXED(10), .height=CLAY_SIZING_FIXED(40)},
|
||||
}),
|
||||
CLAY_RECTANGLE({
|
||||
.color=SIDEBAR_COLOR,
|
||||
.cornerRadius={
|
||||
.topRight=16,
|
||||
.bottomRight=16,
|
||||
.topLeft=16,
|
||||
.bottomLeft=16
|
||||
}
|
||||
})
|
||||
) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
void render_composit_library_content() {
|
||||
CLAY(CLAY_ID("Content")) {
|
||||
}
|
||||
}
|
||||
|
||||
void render_composit_library() {
|
||||
render_composit_library_sidebar();
|
||||
render_composit_library_content();
|
||||
}
|
||||
6
src/library.h
Normal file
6
src/library.h
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
#ifndef LIBRARY_H
|
||||
#define LIBRARY_H
|
||||
|
||||
extern void render_composit_library();
|
||||
|
||||
#endif // !LIBRARY_H
|
||||
78
src/main.c
Normal file
78
src/main.c
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
#include "styles.h"
|
||||
#include "clay_renderer_raylib.c"
|
||||
#include "raylib.h"
|
||||
#include "library.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define CLAY_IMPLEMENTATION
|
||||
#include "clay.h"
|
||||
|
||||
Clay_LayoutConfig const APPLICATION_LAYOUT = {
|
||||
.sizing={
|
||||
.width=CLAY_SIZING_GROW(),
|
||||
.height=CLAY_SIZING_GROW()
|
||||
},
|
||||
.childGap=16,
|
||||
.layoutDirection=CLAY_LEFT_TO_RIGHT
|
||||
};
|
||||
|
||||
Color const BACKGROUND_COLOR = {220.f, 226.f, 233.f, 255.f};
|
||||
|
||||
bool static clay_debug_enabled = false;
|
||||
|
||||
void handle_clay_errors(Clay_ErrorData error) {
|
||||
printf("Clay Error: %s\n", error.errorText.chars);
|
||||
abort();
|
||||
}
|
||||
|
||||
void init_clay(Clay_Arena *o_arena) {
|
||||
uint64_t memory_required = Clay_MinMemorySize();
|
||||
*o_arena = Clay_CreateArenaWithCapacityAndMemory(memory_required, malloc(memory_required));
|
||||
Clay_SetMeasureTextFunction(Raylib_MeasureText);
|
||||
Clay_Initialize(*o_arena,
|
||||
(Clay_Dimensions){
|
||||
(float)GetScreenWidth(),
|
||||
(float)GetScreenHeight()},
|
||||
(Clay_ErrorHandler){handle_clay_errors});
|
||||
Clay_Raylib_Initialize(1920, 1080, "DataComp", FLAG_VSYNC_HINT | FLAG_WINDOW_RESIZABLE | FLAG_WINDOW_HIGHDPI | FLAG_MSAA_4X_HINT);
|
||||
Raylib_fonts[0] = (Raylib_Font){
|
||||
.font = LoadFontEx("resources/Inter-Regular.ttf", 48, NULL, 400),
|
||||
.fontId = 0
|
||||
};
|
||||
SetTextureFilter(Raylib_fonts[0].font.texture, TEXTURE_FILTER_BILINEAR);
|
||||
}
|
||||
|
||||
Clay_RenderCommandArray create_layout() {
|
||||
Clay_BeginLayout();
|
||||
CLAY(CLAY_ID("ApplicationContainer"),
|
||||
CLAY_LAYOUT(APPLICATION_LAYOUT)) {
|
||||
render_composit_library();
|
||||
}
|
||||
return Clay_EndLayout();
|
||||
}
|
||||
|
||||
void update_ui() {
|
||||
if(IsKeyPressed(KEY_D) && IsKeyDown(KEY_LEFT_CONTROL))
|
||||
Clay_SetDebugModeEnabled(clay_debug_enabled = !clay_debug_enabled);
|
||||
Vector2 const scroll_delta = GetMouseWheelMoveV();
|
||||
Vector2 const mouse_position = GetMousePosition();
|
||||
Clay_SetPointerState((Clay_Vector2){mouse_position.x, mouse_position.y}, IsMouseButtonDown(0));
|
||||
Clay_SetLayoutDimensions((Clay_Dimensions){.width=(float)GetScreenWidth(), .height=(float)GetScreenHeight()});
|
||||
Clay_UpdateScrollContainers(true, (Clay_Vector2){scroll_delta.x, scroll_delta.y}, GetFrameTime());
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
Clay_Arena clay_mem;
|
||||
init_clay(&clay_mem);
|
||||
while(!WindowShouldClose()) {
|
||||
update_ui();
|
||||
Clay_RenderCommandArray commands = create_layout();
|
||||
BeginDrawing();
|
||||
ClearBackground(BACKGROUND_COLOR);
|
||||
Clay_Raylib_Render(commands);
|
||||
EndDrawing();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
3
src/styles.c
Normal file
3
src/styles.c
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
#include "styles.h"
|
||||
|
||||
Clay_Color const TRANSPARENT = {0.f, 0.f, 0.f, 0.f};
|
||||
8
src/styles.h
Normal file
8
src/styles.h
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#ifndef DATACOMP_STYLES_H
|
||||
#define DATACOMP_STYLES_H
|
||||
|
||||
#include "clay.h"
|
||||
|
||||
extern Clay_Color const TRANSPARENT;
|
||||
|
||||
#endif // !DATACOMP_STYLES_H
|
||||
Loading…
Add table
Add a link
Reference in a new issue