mirror of
https://github.com/nicbarker/clay.git
synced 2025-04-20 13:18:03 +00:00
Continued clay bindings
This commit is contained in:
parent
f0fec168a2
commit
409bf1c3bf
5
bindings/jai/.gitignore
vendored
5
bindings/jai/.gitignore
vendored
@ -1,4 +1,5 @@
|
|||||||
.build/
|
.build/
|
||||||
examples/clay_official_website.exe
|
examples/introducing_clay_video_demo/main.exe
|
||||||
examples/clay_official_website.pdb
|
examples/introducing_clay_video_demo/main.pdb
|
||||||
|
examples/introducing_clay_video_demo/main.rdi
|
||||||
source/clay.h
|
source/clay.h
|
Binary file not shown.
@ -54,9 +54,9 @@ raylib_initialize :: (width: s32, height: s32, $$title: string, flags: Raylib.Co
|
|||||||
Raylib.InitWindow(width, height, c_string_title);
|
Raylib.InitWindow(width, height, c_string_title);
|
||||||
}
|
}
|
||||||
|
|
||||||
clay_raylib_render :: (render_commands: *Clay.RenderCommandArray) {
|
clay_raylib_render :: (render_commands: Clay.RenderCommandArray) {
|
||||||
for 0..render_commands.length - 1 {
|
for 0..render_commands.length - 1 {
|
||||||
render_command := Clay.RenderCommandArray_Get(render_commands, cast(s32) it);
|
render_command := Clay.RenderCommandArray_Get(*render_commands, cast(s32) it);
|
||||||
bounding_box := render_command.boundingBox;
|
bounding_box := render_command.boundingBox;
|
||||||
|
|
||||||
if #complete render_command.commandType == {
|
if #complete render_command.commandType == {
|
||||||
|
@ -30,7 +30,7 @@ to_jai_string :: (str: Clay.String) -> string {
|
|||||||
|
|
||||||
handle_clay_errors :: (error_data: Clay.ErrorData) #c_call {
|
handle_clay_errors :: (error_data: Clay.ErrorData) #c_call {
|
||||||
push_context {
|
push_context {
|
||||||
print("%", to_jai_string(error_data.errorText));
|
log_error("Clay Error : %", to_jai_string(error_data.errorText));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,15 +39,65 @@ main :: () {
|
|||||||
raylib_initialize(1024, 768, "Introducing Clay Demo", flags);
|
raylib_initialize(1024, 768, "Introducing Clay Demo", flags);
|
||||||
|
|
||||||
clay_required_memory := Clay.MinMemorySize();
|
clay_required_memory := Clay.MinMemorySize();
|
||||||
clay_memory := Clay.CreateArenaWithCapacityAndMemory(clay_required_memory, alloc(clay_required_memory));
|
memory := NewArray(clay_required_memory, u8);
|
||||||
|
clay_memory := Clay.CreateArenaWithCapacityAndMemory(clay_required_memory, memory.data);
|
||||||
Clay.Initialize(
|
Clay.Initialize(
|
||||||
clay_memory,
|
clay_memory,
|
||||||
Clay.Dimensions.{cast(float, Raylib.GetScreenWidth()), cast(float, Raylib.GetScreenHeight())},
|
Clay.Dimensions.{cast(float, Raylib.GetScreenWidth()), cast(float, Raylib.GetScreenHeight())},
|
||||||
.{handle_clay_errors, 0}
|
.{handle_clay_errors, 0}
|
||||||
);
|
);
|
||||||
|
|
||||||
Clay.SetMeasureTextFunction(raylib_measure_text);
|
Clay.SetMeasureTextFunction(raylib_measure_text);
|
||||||
g_raylib_fonts[FONT_ID_BODY_16] = .{
|
g_raylib_fonts[FONT_ID_BODY_16] = .{
|
||||||
FONT_ID_BODY_16,
|
FONT_ID_BODY_16,
|
||||||
Raylib.LoadFontEx("resources/Roboto-Regular.ttf", 48, null, 400),
|
Raylib.LoadFontEx("resources/Roboto-Regular.ttf", 48, null, 400),
|
||||||
};
|
};
|
||||||
|
Raylib.SetTextureFilter(g_raylib_fonts[FONT_ID_BODY_16].font.texture, .BILINEAR);
|
||||||
|
|
||||||
|
while !Raylib.WindowShouldClose() {
|
||||||
|
Clay.SetLayoutDimensions(.{
|
||||||
|
cast(float, Raylib.GetScreenWidth()),
|
||||||
|
cast(float, Raylib.GetScreenHeight()),
|
||||||
|
});
|
||||||
|
|
||||||
|
mouse_position := Raylib.GetMousePosition();
|
||||||
|
scroll_delta := Raylib.GetMouseWheelMoveV();
|
||||||
|
Clay.SetPointerState(mouse_position, Raylib.IsMouseButtonDown(0));
|
||||||
|
Clay.UpdateScrollContainers(true, scroll_delta, Raylib.GetFrameTime());
|
||||||
|
|
||||||
|
layout_expand := Clay.Sizing.{
|
||||||
|
Clay.SizingGrow(),
|
||||||
|
Clay.SizingGrow(),
|
||||||
|
};
|
||||||
|
|
||||||
|
content_background_config := Clay.RectangleElementConfig.{
|
||||||
|
color = .{90, 90, 90, 255},
|
||||||
|
cornerRadius = .{8, 8, 8, 8},
|
||||||
|
};
|
||||||
|
|
||||||
|
Clay.BeginLayout();
|
||||||
|
if Clay.UI(
|
||||||
|
Clay.ID("OuterContainer"),
|
||||||
|
Clay.Layout(.{
|
||||||
|
layoutDirection = .TOP_TO_BOTTOM,
|
||||||
|
sizing = Clay.Sizing.{
|
||||||
|
Clay.SizingGrow(),
|
||||||
|
Clay.SizingGrow(),
|
||||||
|
},
|
||||||
|
padding = .{16, 16},
|
||||||
|
childGap = 16,
|
||||||
|
}),
|
||||||
|
Clay.Rectangle(.{color = .{43, 41, 51, 255}})
|
||||||
|
) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
render_commands := Clay.EndLayout();
|
||||||
|
|
||||||
|
Raylib.BeginDrawing();
|
||||||
|
Raylib.ClearBackground(Raylib.BLACK);
|
||||||
|
clay_raylib_render(render_commands);
|
||||||
|
Raylib.EndDrawing();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Binary file not shown.
@ -5,13 +5,6 @@ SOURCE_PATH :: "source";
|
|||||||
// These have custom declaration in module.jai
|
// These have custom declaration in module.jai
|
||||||
DECLARATIONS_TO_OMIT :: string.[
|
DECLARATIONS_TO_OMIT :: string.[
|
||||||
"Clay_Vector2",
|
"Clay_Vector2",
|
||||||
// "Clay_Color",
|
|
||||||
];
|
|
||||||
|
|
||||||
// These types must be included because they are referenced by public types
|
|
||||||
PRIVATE_DECLARATION_TO_INCLUDE :: string.[
|
|
||||||
"Clay__SizingType",
|
|
||||||
"Clay__ElementConfigType"
|
|
||||||
];
|
];
|
||||||
|
|
||||||
#if AT_COMPILE_TIME {
|
#if AT_COMPILE_TIME {
|
||||||
@ -40,7 +33,7 @@ generate_bindings :: (args: [] string, minimum_os_version: type_of(Compiler.Buil
|
|||||||
|
|
||||||
could_copy := FileUtils.copy_file("../../clay.h", "source/clay.h");
|
could_copy := FileUtils.copy_file("../../clay.h", "source/clay.h");
|
||||||
if !could_copy then return false;
|
if !could_copy then return false;
|
||||||
defer File.file_delete("source/clay.h");
|
defer if !compile_debug then File.file_delete("source/clay.h");
|
||||||
|
|
||||||
if compile {
|
if compile {
|
||||||
source_file := tprint("%/clay.c", SOURCE_PATH);
|
source_file := tprint("%/clay.c", SOURCE_PATH);
|
||||||
@ -49,20 +42,21 @@ generate_bindings :: (args: [] string, minimum_os_version: type_of(Compiler.Buil
|
|||||||
#if OS == .WINDOWS {
|
#if OS == .WINDOWS {
|
||||||
File.make_directory_if_it_does_not_exist("clay-jai/windows", true);
|
File.make_directory_if_it_does_not_exist("clay-jai/windows", true);
|
||||||
|
|
||||||
// success &&= BuildCpp.build_cpp_static_lib("clay-jai/windows/clay", source_file, extra=.["/w"], debug=compile_debug);
|
|
||||||
|
|
||||||
command := ifx compile_debug {
|
command := ifx compile_debug {
|
||||||
|
write_string("Compiling debug...\n");
|
||||||
Process.break_command_into_strings("clang -g -gcodeview -c source\\clay.c");
|
Process.break_command_into_strings("clang -g -gcodeview -c source\\clay.c");
|
||||||
} else {
|
} else {
|
||||||
|
write_string("Compiling release...\n");
|
||||||
Process.break_command_into_strings("clang -O3 -c source\\clay.c");
|
Process.break_command_into_strings("clang -O3 -c source\\clay.c");
|
||||||
}
|
}
|
||||||
result := Process.run_command(..command, capture_and_return_output=true, print_captured_output=true);
|
result := Process.run_command(..command, capture_and_return_output=true, print_captured_output=true);
|
||||||
if result.exit_code != 0 then return false;
|
if result.exit_code != 0 then return false;
|
||||||
defer File.file_delete("clay.o");
|
defer File.file_delete("clay.o");
|
||||||
|
|
||||||
command = Process.break_command_into_strings("llvm-ar -rc clay-jai/windows/clay.lib clay.o");
|
write_string("Linking...\n");
|
||||||
|
command = Process.break_command_into_strings("llvm-ar -rcs clay-jai/windows/clay.lib clay.o");
|
||||||
result = Process.run_command(..command, capture_and_return_output=true, print_captured_output=true);
|
result = Process.run_command(..command, capture_and_return_output=true, print_captured_output=true);
|
||||||
// if result.exit_code != 0 then return false;
|
if result.exit_code != 0 then return false;
|
||||||
} else {
|
} else {
|
||||||
// TODO MacOS
|
// TODO MacOS
|
||||||
// TODO Linux
|
// TODO Linux
|
||||||
@ -70,6 +64,7 @@ generate_bindings :: (args: [] string, minimum_os_version: type_of(Compiler.Buil
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !success then return false;
|
if !success then return false;
|
||||||
|
write_string("Succesfully built clay\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
output_filename: string;
|
output_filename: string;
|
||||||
@ -108,9 +103,8 @@ clay_visitor :: (decl: *Generator.Declaration, parent_decl: *Generator.Declarati
|
|||||||
return .STOP;
|
return .STOP;
|
||||||
}
|
}
|
||||||
|
|
||||||
if String.begins_with(decl.name, "Clay__") && !array_find(PRIVATE_DECLARATION_TO_INCLUDE, decl.name) {
|
if String.begins_with(decl.name, "Clay__") {
|
||||||
decl.decl_flags |= .OMIT_FROM_OUTPUT;
|
decl.output_name = String.slice(decl.name, 5, decl.name.count - 5);
|
||||||
return .STOP;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,9 +1,50 @@
|
|||||||
|
|
||||||
Vector2 :: Math.Vector2;
|
Vector2 :: Math.Vector2;
|
||||||
|
|
||||||
|
make_string :: (str: string) -> String {
|
||||||
|
return .{cast(u64, str.count), str.data};
|
||||||
|
}
|
||||||
|
|
||||||
|
UI :: (id: ElementId, layout: LayoutConfig, configs: ..ElementConfig, $call := #caller_code) -> bool #must #expand {
|
||||||
|
_OpenElement();
|
||||||
|
_AttachId(id);
|
||||||
|
_AttachLayoutConfig(_StoreLayoutConfig(layout));
|
||||||
|
for configs _AttachElementConfig(it.config, it.type);
|
||||||
|
_ElementPostConfiguration();
|
||||||
|
|
||||||
|
// TODO Fix the need to have to add the namespace here
|
||||||
|
#insert,scope(call) #code defer Clay._CloseElement();;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// `defer _CloseElement();
|
||||||
|
}
|
||||||
|
|
||||||
|
ID :: (label: string, index: u32 = 0) -> ElementId {
|
||||||
|
return _HashString(make_string(label), index, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
Layout :: (config: LayoutConfig) -> LayoutConfig {
|
||||||
|
// We can just return the config because the layout is attached and stored in the UI function
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
|
||||||
|
Rectangle :: (config: RectangleElementConfig) -> ElementConfig {
|
||||||
|
return .{
|
||||||
|
type = .RECTANGLE,
|
||||||
|
config.rectangleElementConfig = _StoreRectangleElementConfig(config)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
SizingGrow :: (size_min_max: SizingMinMax = .{}) -> SizingAxis {
|
||||||
|
return .{type = .GROW, size = .{minMax = size_min_max}};
|
||||||
|
}
|
||||||
|
|
||||||
#scope_module
|
#scope_module
|
||||||
|
|
||||||
Math :: #import "Math";
|
Math :: #import "Math";
|
||||||
|
Compiler :: #import "Compiler";
|
||||||
|
ProgramPrint :: #import "Program_Print";
|
||||||
|
|
||||||
#if OS == .WINDOWS {
|
#if OS == .WINDOWS {
|
||||||
#load "windows.jai";
|
#load "windows.jai";
|
||||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user