mirror of
https://github.com/nicbarker/clay.git
synced 2025-04-21 05:38:04 +00:00
Compare commits
22 Commits
9ff56768c4
...
db049b10c8
Author | SHA1 | Date | |
---|---|---|---|
|
db049b10c8 | ||
|
eb46688b82 | ||
|
87efc49f52 | ||
|
be99977da6 | ||
|
f950d317c9 | ||
|
c44d6b9309 | ||
|
2cfab84034 | ||
|
31bf0ad2dd | ||
|
f8b13b5978 | ||
|
9bc743fd12 | ||
|
672927d387 | ||
|
b7e1d69ca6 | ||
|
e9522005db | ||
|
409bf1c3bf | ||
|
f0fec168a2 | ||
|
bc31e8d332 | ||
|
697adce4a9 | ||
|
1936afd184 | ||
|
678bcf2ad0 | ||
|
11e3f91220 | ||
|
eb1ee390bb | ||
|
4699018599 |
@ -9,6 +9,8 @@ option(CLAY_INCLUDE_CPP_EXAMPLE "Build C++ example" OFF)
|
|||||||
option(CLAY_INCLUDE_RAYLIB_EXAMPLES "Build raylib examples" OFF)
|
option(CLAY_INCLUDE_RAYLIB_EXAMPLES "Build raylib examples" OFF)
|
||||||
option(CLAY_INCLUDE_SDL2_EXAMPLES "Build SDL 2 examples" OFF)
|
option(CLAY_INCLUDE_SDL2_EXAMPLES "Build SDL 2 examples" OFF)
|
||||||
option(CLAY_INCLUDE_SDL3_EXAMPLES "Build SDL 3 examples" OFF)
|
option(CLAY_INCLUDE_SDL3_EXAMPLES "Build SDL 3 examples" OFF)
|
||||||
|
option(CLAY_INCLUDE_WIN32_GDI_EXAMPLES "Build Win32 GDI examples" OFF)
|
||||||
|
option(CLAY_INCLUDE_SOKOL_EXAMPLES "Build Sokol examples" OFF)
|
||||||
|
|
||||||
message(STATUS "CLAY_INCLUDE_DEMOS: ${CLAY_INCLUDE_DEMOS}")
|
message(STATUS "CLAY_INCLUDE_DEMOS: ${CLAY_INCLUDE_DEMOS}")
|
||||||
|
|
||||||
@ -36,6 +38,16 @@ endif ()
|
|||||||
if(NOT MSVC AND (CLAY_INCLUDE_ALL_EXAMPLES OR CLAY_INCLUDE_SDL3_EXAMPLES))
|
if(NOT MSVC AND (CLAY_INCLUDE_ALL_EXAMPLES OR CLAY_INCLUDE_SDL3_EXAMPLES))
|
||||||
add_subdirectory("examples/SDL3-simple-demo")
|
add_subdirectory("examples/SDL3-simple-demo")
|
||||||
endif()
|
endif()
|
||||||
|
if(CLAY_INCLUDE_ALL_EXAMPLES OR CLAY_INCLUDE_SOKOL_EXAMPLES)
|
||||||
|
add_subdirectory("examples/sokol-video-demo")
|
||||||
|
add_subdirectory("examples/sokol-corner-radius")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(WIN32) # Build only for Win or Wine
|
||||||
|
if(CLAY_INCLUDE_ALL_EXAMPLES OR CLAY_INCLUDE_WIN32_GDI_EXAMPLES)
|
||||||
|
add_subdirectory("examples/win32_gdi")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
# add_subdirectory("examples/cairo-pdf-rendering") Some issue with github actions populating cairo, disable for now
|
# add_subdirectory("examples/cairo-pdf-rendering") Some issue with github actions populating cairo, disable for now
|
||||||
|
|
||||||
|
5
bindings/jai/.gitignore
vendored
Normal file
5
bindings/jai/.gitignore
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
.build/
|
||||||
|
main.exe
|
||||||
|
main.pdb
|
||||||
|
main.rdi
|
||||||
|
main
|
116
bindings/jai/README.md
Normal file
116
bindings/jai/README.md
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
### Jai Language Bindings
|
||||||
|
|
||||||
|
This directory contains bindings for the [Jai](https://jai.community/t/overview-of-jai/128) programming language, as well as an example implementation of the Clay demo from the video in Jai.
|
||||||
|
|
||||||
|
If you haven't taken a look at the [full documentation for clay](https://github.com/nicbarker/clay/blob/main/README.md), it's recommended that you take a look there first to familiarise yourself with the general concepts. This README is abbreviated and applies to using clay in Jai specifically.
|
||||||
|
|
||||||
|
The **most notable difference** between the C API and the Jai bindings is the use of for statements to create the scope for declaring child elements. This is done using some [for_expansion](https://jai.community/t/loops/147) magic.
|
||||||
|
When using the equivalent of the [Element Macros](https://github.com/nicbarker/clay/blob/main/README.md#element-macros):
|
||||||
|
|
||||||
|
```C
|
||||||
|
// C form of element macros
|
||||||
|
// Parent element with 8px of padding
|
||||||
|
CLAY(CLAY_LAYOUT({ .padding = 8 })) {
|
||||||
|
// Child element 1
|
||||||
|
CLAY_TEXT(CLAY_STRING("Hello World"), CLAY_TEXT_CONFIG({ .fontSize = 16 }));
|
||||||
|
// Child element 2 with red background
|
||||||
|
CLAY(CLAY_RECTANGLE({ .color = COLOR_RED })) {
|
||||||
|
// etc
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
```Jai
|
||||||
|
// Jai form of element macros
|
||||||
|
// Parent element with 8px of padding
|
||||||
|
for Clay.Element(Clay.Layout(.{padding = 8})) {
|
||||||
|
// Child element 1
|
||||||
|
Clay.Text("Hello World", Clay.TextConfig(.{fontSize = 16}));
|
||||||
|
// Child element 2 with red background
|
||||||
|
for Clay.Element(Clay.Rectangle(.{color = COLOR_RED})) {
|
||||||
|
// etc
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
> [!WARNING]
|
||||||
|
> For now, the Jai and Odin bindings are missing the OnHover() and Hovered() functions.
|
||||||
|
> You can you PointerOver instead, an example of that is in `examples/introducing_clay_video_demo`.
|
||||||
|
|
||||||
|
### Quick Start
|
||||||
|
|
||||||
|
1. Download the clay-jai directory and copy it into your modules folder.
|
||||||
|
|
||||||
|
```Jai
|
||||||
|
Clay :: #import "clay-jai";
|
||||||
|
```
|
||||||
|
|
||||||
|
1. Ask clay for how much static memory it needs using [Clay.MinMemorySize()](https://github.com/nicbarker/clay/blob/main/README.md#clay_minmemorysize), create an Arena for it to use with [Clay.CreateArenaWithCapacityAndMemory()](https://github.com/nicbarker/clay/blob/main/README.md#clay_createarenawithcapacityandmemory), and initialize it with [Clay.Initialize()](https://github.com/nicbarker/clay/blob/main/README.md#clay_initialize).
|
||||||
|
|
||||||
|
```Jai
|
||||||
|
clay_required_memory := Clay.MinMemorySize();
|
||||||
|
memory := alloc(clay_required_memory);
|
||||||
|
clay_memory := Clay.CreateArenaWithCapacityAndMemory(clay_required_memory, memory);
|
||||||
|
Clay.Initialize(
|
||||||
|
clay_memory,
|
||||||
|
Clay.Dimensions.{cast(float, GetScreenWidth()), cast(float, GetScreenHeight())},
|
||||||
|
.{handle_clay_errors, 0}
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
||||||
|
3. Provide a `measure_text(text, config)` proc marked with `#c_call` with [Clay.SetMeasureTextFunction(function)](https://github.com/nicbarker/clay/blob/main/README.md#clay_setmeasuretextfunction) so that clay can measure and wrap text.
|
||||||
|
|
||||||
|
```Jai
|
||||||
|
// Example measure text function
|
||||||
|
measure_text :: (text: *Clay.String, config: *Clay.TextElementConfig) -> Clay.Dimensions #c_call {
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tell clay how to measure text
|
||||||
|
Clay.SetMeasureTextFunction(measure_text)
|
||||||
|
```
|
||||||
|
|
||||||
|
4. **Optional** - Call [Clay.SetPointerPosition(pointerPosition)](https://github.com/nicbarker/clay/blob/main/README.md#clay_setpointerposition) if you want to use mouse interactions.
|
||||||
|
|
||||||
|
```Jai
|
||||||
|
// Update internal pointer position for handling mouseover / click / touch events
|
||||||
|
Clay.SetPointerPosition(.{ mousePositionX, mousePositionY })
|
||||||
|
```
|
||||||
|
|
||||||
|
5. Call [Clay.BeginLayout(screenWidth, screenHeight)](https://github.com/nicbarker/clay/blob/main/README.md#clay_beginlayout) and declare your layout using the provided macros.
|
||||||
|
|
||||||
|
```Jai
|
||||||
|
// An example function to begin the "root" of your layout tree
|
||||||
|
CreateLayout :: () -> Clay.RenderCommandArray {
|
||||||
|
Clay.BeginLayout(windowWidth, windowHeight);
|
||||||
|
|
||||||
|
for Clay.Element(
|
||||||
|
Clay.ID("OuterContainer"),
|
||||||
|
Clay.Layout(.{
|
||||||
|
sizing = .{Clay.SizingGrow(), Clay.SizingGrow()},
|
||||||
|
padding = .{16, 16},
|
||||||
|
childGap = 16
|
||||||
|
}),
|
||||||
|
Clay.Rectangle(.{color = .{250, 250, 255, 255}}),
|
||||||
|
) {
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
1. Call [Clay.EndLayout()](https://github.com/nicbarker/clay/blob/main/README.md#clay_endlayout) and process the resulting [Clay.RenderCommandArray](https://github.com/nicbarker/clay/blob/main/README.md#clay_rendercommandarray) in your choice of renderer.
|
||||||
|
|
||||||
|
```Jai
|
||||||
|
render_commands: Clay.RenderCommandArray = Clay.EndLayout();
|
||||||
|
|
||||||
|
for 0..render_commands.length - 1 {
|
||||||
|
render_command := Clay.RenderCommandArray_Get(*render_commands, cast(s32) it);
|
||||||
|
|
||||||
|
if #complete render_command.commandType == {
|
||||||
|
case .RECTANGLE;
|
||||||
|
DrawRectangle(render_command.boundingBox, render_command.config.rectangleElementConfig.color)
|
||||||
|
// ... Implement handling of other command types
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Please see the [full C documentation for clay](https://github.com/nicbarker/clay/blob/main/README.md) for API details. All public C functions and Macros have Jai binding equivalents, generally of the form `CLAY_RECTANGLE` (C) -> `Clay.Rectangle` (Jai)
|
1
bindings/jai/clay-jai/.gitignore
vendored
Normal file
1
bindings/jai/clay-jai/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
source/clay.h
|
164
bindings/jai/clay-jai/generate.jai
Normal file
164
bindings/jai/clay-jai/generate.jai
Normal file
@ -0,0 +1,164 @@
|
|||||||
|
AT_COMPILE_TIME :: true;
|
||||||
|
|
||||||
|
SOURCE_PATH :: "source";
|
||||||
|
|
||||||
|
DECLARATIONS_TO_OMIT :: string.[
|
||||||
|
// These have custom declaration in module.jai
|
||||||
|
"Clay_Vector2",
|
||||||
|
"Clay__ElementConfigType",
|
||||||
|
"Clay__AlignClay__ElementConfigType",
|
||||||
|
"Clay_Border",
|
||||||
|
"Clay__AlignClay_Border",
|
||||||
|
"Clay_BorderElementConfig",
|
||||||
|
"Clay__AlignClay_BorderElementConfig",
|
||||||
|
|
||||||
|
// These are not supported yet
|
||||||
|
"Clay_OnHover",
|
||||||
|
"Clay_Hovered",
|
||||||
|
];
|
||||||
|
|
||||||
|
#if AT_COMPILE_TIME {
|
||||||
|
#if !#exists(JAILS_DIAGNOSTICS_BUILD) {
|
||||||
|
#run,stallable {
|
||||||
|
Compiler.set_build_options_dc(.{do_output=false});
|
||||||
|
options := Compiler.get_build_options();
|
||||||
|
args := options.compile_time_command_line;
|
||||||
|
if !generate_bindings(args, options.minimum_os_version) {
|
||||||
|
Compiler.compiler_set_workspace_status(.FAILED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
#import "System";
|
||||||
|
|
||||||
|
main :: () {
|
||||||
|
set_working_directory(path_strip_filename(get_path_of_running_executable()));
|
||||||
|
if !generate_bindings(get_command_line_arguments(), #run get_build_options().minimum_os_version) {
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
generate_bindings :: (args: [] string, minimum_os_version: type_of(Compiler.Build_Options.minimum_os_version)) -> bool {
|
||||||
|
compile := array_find(args, "-compile");
|
||||||
|
compile_debug := array_find(args, "-debug");
|
||||||
|
|
||||||
|
could_copy := FileUtils.copy_file("../../../clay.h", "source/clay.h");
|
||||||
|
if !could_copy then return false;
|
||||||
|
defer if !compile_debug then File.file_delete("source/clay.h");
|
||||||
|
|
||||||
|
if compile {
|
||||||
|
source_file := tprint("%/clay.c", SOURCE_PATH);
|
||||||
|
|
||||||
|
success := true;
|
||||||
|
#if OS == .WINDOWS {
|
||||||
|
// TODO try to use BuildCpp module again
|
||||||
|
File.make_directory_if_it_does_not_exist("windows", true);
|
||||||
|
|
||||||
|
command := ifx compile_debug {
|
||||||
|
write_string("Compiling debug...\n");
|
||||||
|
Process.break_command_into_strings("clang -g -gcodeview -c source\\clay.c");
|
||||||
|
} else {
|
||||||
|
write_string("Compiling release...\n");
|
||||||
|
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);
|
||||||
|
if result.exit_code != 0 then return false;
|
||||||
|
defer File.file_delete("clay.o");
|
||||||
|
|
||||||
|
write_string("Linking...\n");
|
||||||
|
command = Process.break_command_into_strings("llvm-ar -rcs windows/clay.lib clay.o");
|
||||||
|
result = Process.run_command(..command, capture_and_return_output=true, print_captured_output=true);
|
||||||
|
if result.exit_code != 0 then return false;
|
||||||
|
} else #if OS == .LINUX {
|
||||||
|
File.make_directory_if_it_does_not_exist("linux", true);
|
||||||
|
|
||||||
|
could_build := BuildCpp.build_cpp_static_lib("linux/clay", "source/clay.c",
|
||||||
|
debug = compile_debug,
|
||||||
|
);
|
||||||
|
assert(could_build);
|
||||||
|
} else {
|
||||||
|
// TODO MacOS
|
||||||
|
assert(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if !success then return false;
|
||||||
|
write_string("Succesfully built clay\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
output_filename: string;
|
||||||
|
options: Generator.Generate_Bindings_Options;
|
||||||
|
{
|
||||||
|
write_string("Generating bindings...\n");
|
||||||
|
|
||||||
|
using options;
|
||||||
|
|
||||||
|
#if OS == .WINDOWS {
|
||||||
|
array_add(*libpaths, "windows");
|
||||||
|
output_filename = "windows.jai";
|
||||||
|
} else #if OS == .LINUX {
|
||||||
|
array_add(*libpaths, "linux");
|
||||||
|
output_filename = "linux.jai";
|
||||||
|
} else {
|
||||||
|
assert(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
array_add(*libnames, "clay");
|
||||||
|
array_add(*include_paths, SOURCE_PATH);
|
||||||
|
array_add(*source_files, tprint("%/clay.h", SOURCE_PATH));
|
||||||
|
array_add(*strip_prefixes, "Clay_");
|
||||||
|
|
||||||
|
auto_detect_enum_prefixes = true;
|
||||||
|
log_stripped_declarations = true;
|
||||||
|
generate_compile_time_struct_checks = true;
|
||||||
|
|
||||||
|
visitor = clay_visitor;
|
||||||
|
}
|
||||||
|
|
||||||
|
could_generate := Generator.generate_bindings(options, output_filename);
|
||||||
|
|
||||||
|
return could_generate;
|
||||||
|
}
|
||||||
|
|
||||||
|
clay_visitor :: (decl: *Generator.Declaration, parent_decl: *Generator.Declaration) -> Generator.Declaration_Visit_Result {
|
||||||
|
if !parent_decl {
|
||||||
|
if array_find(DECLARATIONS_TO_OMIT, decl.name) {
|
||||||
|
decl.decl_flags |= .OMIT_FROM_OUTPUT;
|
||||||
|
return .STOP;
|
||||||
|
}
|
||||||
|
|
||||||
|
// We don't want the align and wrapper strucs
|
||||||
|
if String.begins_with(decl.name, "Clay__Align") || String.ends_with(decl.name, "Wrapper") {
|
||||||
|
decl.decl_flags |= .OMIT_FROM_OUTPUT;
|
||||||
|
return .STOP;
|
||||||
|
}
|
||||||
|
|
||||||
|
if String.begins_with(decl.name, "Clay__") {
|
||||||
|
// The way bindings generator strip prefixes mean that something like `Clay__Foo` will be turned to `Foo`
|
||||||
|
// but what we want is `_Foo`
|
||||||
|
decl.output_name = String.slice(decl.name, 5, decl.name.count - 5);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return .RECURSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
#scope_file
|
||||||
|
|
||||||
|
using Basic :: #import "Basic";
|
||||||
|
Generator :: #import "Bindings_Generator";
|
||||||
|
Compiler :: #import "Compiler";
|
||||||
|
File :: #import "File";
|
||||||
|
FileUtils :: #import "File_Utilities";
|
||||||
|
BuildCpp :: #import "BuildCpp";
|
||||||
|
Process :: #import "Process";
|
||||||
|
String :: #import "String";
|
||||||
|
|
||||||
|
#if OS == .WINDOWS {
|
||||||
|
Windows :: #import "Windows";
|
||||||
|
WindowsResources :: #import "Windows_Resources";
|
||||||
|
getenv :: Windows.getenv;
|
||||||
|
} else {
|
||||||
|
Posix :: #import "POSIX";
|
||||||
|
getenv :: Posix.getenv;
|
||||||
|
}
|
711
bindings/jai/clay-jai/linux.jai
Normal file
711
bindings/jai/clay-jai/linux.jai
Normal file
@ -0,0 +1,711 @@
|
|||||||
|
//
|
||||||
|
// This file was auto-generated using the following command:
|
||||||
|
//
|
||||||
|
// jai generate.jai - -compile
|
||||||
|
//
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Utility Structs -------------------------
|
||||||
|
// Note: Clay_String is not guaranteed to be null terminated. It may be if created from a literal C string,
|
||||||
|
// but it is also used to represent slices.
|
||||||
|
String :: struct {
|
||||||
|
length: s32;
|
||||||
|
chars: *u8;
|
||||||
|
}
|
||||||
|
|
||||||
|
_StringArray :: struct {
|
||||||
|
capacity: s32;
|
||||||
|
length: s32;
|
||||||
|
internalArray: *String;
|
||||||
|
}
|
||||||
|
|
||||||
|
Context :: struct {}
|
||||||
|
|
||||||
|
Arena :: struct {
|
||||||
|
nextAllocation: u64;
|
||||||
|
capacity: u64;
|
||||||
|
memory: *u8;
|
||||||
|
}
|
||||||
|
|
||||||
|
Dimensions :: struct {
|
||||||
|
width: float;
|
||||||
|
height: float;
|
||||||
|
}
|
||||||
|
|
||||||
|
Color :: struct {
|
||||||
|
r: float;
|
||||||
|
g: float;
|
||||||
|
b: float;
|
||||||
|
a: float;
|
||||||
|
}
|
||||||
|
|
||||||
|
BoundingBox :: struct {
|
||||||
|
x: float;
|
||||||
|
y: float;
|
||||||
|
width: float;
|
||||||
|
height: float;
|
||||||
|
}
|
||||||
|
|
||||||
|
// baseId + offset = id
|
||||||
|
ElementId :: struct {
|
||||||
|
id: u32;
|
||||||
|
offset: u32;
|
||||||
|
baseId: u32;
|
||||||
|
stringId: String;
|
||||||
|
}
|
||||||
|
|
||||||
|
CornerRadius :: struct {
|
||||||
|
topLeft: float;
|
||||||
|
topRight: float;
|
||||||
|
bottomLeft: float;
|
||||||
|
bottomRight: float;
|
||||||
|
}
|
||||||
|
|
||||||
|
LayoutDirection :: enum u8 {
|
||||||
|
LEFT_TO_RIGHT :: 0;
|
||||||
|
TOP_TO_BOTTOM :: 1;
|
||||||
|
CLAY_LEFT_TO_RIGHT :: LEFT_TO_RIGHT;
|
||||||
|
CLAY_TOP_TO_BOTTOM :: TOP_TO_BOTTOM;
|
||||||
|
}
|
||||||
|
|
||||||
|
LayoutAlignmentX :: enum u8 {
|
||||||
|
LEFT :: 0;
|
||||||
|
RIGHT :: 1;
|
||||||
|
CENTER :: 2;
|
||||||
|
CLAY_ALIGN_X_LEFT :: LEFT;
|
||||||
|
CLAY_ALIGN_X_RIGHT :: RIGHT;
|
||||||
|
CLAY_ALIGN_X_CENTER :: CENTER;
|
||||||
|
}
|
||||||
|
|
||||||
|
LayoutAlignmentY :: enum u8 {
|
||||||
|
TOP :: 0;
|
||||||
|
BOTTOM :: 1;
|
||||||
|
CENTER :: 2;
|
||||||
|
CLAY_ALIGN_Y_TOP :: TOP;
|
||||||
|
CLAY_ALIGN_Y_BOTTOM :: BOTTOM;
|
||||||
|
CLAY_ALIGN_Y_CENTER :: CENTER;
|
||||||
|
}
|
||||||
|
|
||||||
|
_SizingType :: enum u8 {
|
||||||
|
FIT :: 0;
|
||||||
|
GROW :: 1;
|
||||||
|
PERCENT :: 2;
|
||||||
|
FIXED :: 3;
|
||||||
|
CLAY__SIZING_TYPE_FIT :: FIT;
|
||||||
|
CLAY__SIZING_TYPE_GROW :: GROW;
|
||||||
|
CLAY__SIZING_TYPE_PERCENT :: PERCENT;
|
||||||
|
CLAY__SIZING_TYPE_FIXED :: FIXED;
|
||||||
|
}
|
||||||
|
|
||||||
|
ChildAlignment :: struct {
|
||||||
|
x: LayoutAlignmentX;
|
||||||
|
y: LayoutAlignmentY;
|
||||||
|
}
|
||||||
|
|
||||||
|
SizingMinMax :: struct {
|
||||||
|
min: float;
|
||||||
|
max: float;
|
||||||
|
}
|
||||||
|
|
||||||
|
SizingAxis :: struct {
|
||||||
|
size: union {
|
||||||
|
minMax: SizingMinMax;
|
||||||
|
percent: float;
|
||||||
|
};
|
||||||
|
type: _SizingType;
|
||||||
|
}
|
||||||
|
|
||||||
|
Sizing :: struct {
|
||||||
|
width: SizingAxis;
|
||||||
|
height: SizingAxis;
|
||||||
|
}
|
||||||
|
|
||||||
|
Padding :: struct {
|
||||||
|
x: u16;
|
||||||
|
y: u16;
|
||||||
|
}
|
||||||
|
|
||||||
|
LayoutConfig :: struct {
|
||||||
|
sizing: Sizing;
|
||||||
|
padding: Padding;
|
||||||
|
childGap: u16;
|
||||||
|
childAlignment: ChildAlignment;
|
||||||
|
layoutDirection: LayoutDirection;
|
||||||
|
}
|
||||||
|
|
||||||
|
CLAY_LAYOUT_DEFAULT: LayoutConfig #elsewhere clay;
|
||||||
|
|
||||||
|
// Rectangle
|
||||||
|
// NOTE: Not declared in the typedef as an ifdef inside macro arguments is UB
|
||||||
|
RectangleElementConfig :: struct {
|
||||||
|
color: Color;
|
||||||
|
cornerRadius: CornerRadius;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Text
|
||||||
|
TextElementConfigWrapMode :: enum u32 {
|
||||||
|
WORDS :: 0;
|
||||||
|
NEWLINES :: 1;
|
||||||
|
NONE :: 2;
|
||||||
|
CLAY_TEXT_WRAP_WORDS :: WORDS;
|
||||||
|
CLAY_TEXT_WRAP_NEWLINES :: NEWLINES;
|
||||||
|
CLAY_TEXT_WRAP_NONE :: NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
TextElementConfig :: struct {
|
||||||
|
textColor: Color;
|
||||||
|
fontId: u16;
|
||||||
|
fontSize: u16;
|
||||||
|
letterSpacing: u16;
|
||||||
|
lineHeight: u16;
|
||||||
|
wrapMode: TextElementConfigWrapMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Image
|
||||||
|
ImageElementConfig :: struct {
|
||||||
|
imageData: *void;
|
||||||
|
sourceDimensions: Dimensions;
|
||||||
|
}
|
||||||
|
|
||||||
|
FloatingAttachPointType :: enum u8 {
|
||||||
|
LEFT_TOP :: 0;
|
||||||
|
LEFT_CENTER :: 1;
|
||||||
|
LEFT_BOTTOM :: 2;
|
||||||
|
CENTER_TOP :: 3;
|
||||||
|
CENTER_CENTER :: 4;
|
||||||
|
CENTER_BOTTOM :: 5;
|
||||||
|
RIGHT_TOP :: 6;
|
||||||
|
RIGHT_CENTER :: 7;
|
||||||
|
RIGHT_BOTTOM :: 8;
|
||||||
|
CLAY_ATTACH_POINT_LEFT_TOP :: LEFT_TOP;
|
||||||
|
CLAY_ATTACH_POINT_LEFT_CENTER :: LEFT_CENTER;
|
||||||
|
CLAY_ATTACH_POINT_LEFT_BOTTOM :: LEFT_BOTTOM;
|
||||||
|
CLAY_ATTACH_POINT_CENTER_TOP :: CENTER_TOP;
|
||||||
|
CLAY_ATTACH_POINT_CENTER_CENTER :: CENTER_CENTER;
|
||||||
|
CLAY_ATTACH_POINT_CENTER_BOTTOM :: CENTER_BOTTOM;
|
||||||
|
CLAY_ATTACH_POINT_RIGHT_TOP :: RIGHT_TOP;
|
||||||
|
CLAY_ATTACH_POINT_RIGHT_CENTER :: RIGHT_CENTER;
|
||||||
|
CLAY_ATTACH_POINT_RIGHT_BOTTOM :: RIGHT_BOTTOM;
|
||||||
|
}
|
||||||
|
|
||||||
|
FloatingAttachPoints :: struct {
|
||||||
|
element: FloatingAttachPointType;
|
||||||
|
parent: FloatingAttachPointType;
|
||||||
|
}
|
||||||
|
|
||||||
|
PointerCaptureMode :: enum u32 {
|
||||||
|
CAPTURE :: 0;
|
||||||
|
PASSTHROUGH :: 1;
|
||||||
|
CLAY_POINTER_CAPTURE_MODE_CAPTURE :: CAPTURE;
|
||||||
|
CLAY_POINTER_CAPTURE_MODE_PASSTHROUGH :: PASSTHROUGH;
|
||||||
|
}
|
||||||
|
|
||||||
|
FloatingElementConfig :: struct {
|
||||||
|
offset: Vector2;
|
||||||
|
expand: Dimensions;
|
||||||
|
zIndex: u16;
|
||||||
|
parentId: u32;
|
||||||
|
attachment: FloatingAttachPoints;
|
||||||
|
pointerCaptureMode: PointerCaptureMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Custom
|
||||||
|
CustomElementConfig :: struct {
|
||||||
|
customData: *void;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scroll
|
||||||
|
ScrollElementConfig :: struct {
|
||||||
|
horizontal: bool;
|
||||||
|
vertical: bool;
|
||||||
|
}
|
||||||
|
|
||||||
|
ElementConfigUnion :: union {
|
||||||
|
rectangleElementConfig: *RectangleElementConfig;
|
||||||
|
textElementConfig: *TextElementConfig;
|
||||||
|
imageElementConfig: *ImageElementConfig;
|
||||||
|
floatingElementConfig: *FloatingElementConfig;
|
||||||
|
customElementConfig: *CustomElementConfig;
|
||||||
|
scrollElementConfig: *ScrollElementConfig;
|
||||||
|
borderElementConfig: *BorderElementConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
ElementConfig :: struct {
|
||||||
|
type: ElementConfigType;
|
||||||
|
config: ElementConfigUnion;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Miscellaneous Structs & Enums ---------------------------------
|
||||||
|
ScrollContainerData :: struct {
|
||||||
|
// Note: This is a pointer to the real internal scroll position, mutating it may cause a change in final layout.
|
||||||
|
// Intended for use with external functionality that modifies scroll position, such as scroll bars or auto scrolling.
|
||||||
|
scrollPosition: *Vector2;
|
||||||
|
scrollContainerDimensions: Dimensions;
|
||||||
|
contentDimensions: Dimensions;
|
||||||
|
config: ScrollElementConfig;
|
||||||
|
found: bool;
|
||||||
|
}
|
||||||
|
|
||||||
|
RenderCommandType :: enum u8 {
|
||||||
|
NONE :: 0;
|
||||||
|
RECTANGLE :: 1;
|
||||||
|
BORDER :: 2;
|
||||||
|
TEXT :: 3;
|
||||||
|
IMAGE :: 4;
|
||||||
|
SCISSOR_START :: 5;
|
||||||
|
SCISSOR_END :: 6;
|
||||||
|
CUSTOM :: 7;
|
||||||
|
CLAY_RENDER_COMMAND_TYPE_NONE :: NONE;
|
||||||
|
CLAY_RENDER_COMMAND_TYPE_RECTANGLE :: RECTANGLE;
|
||||||
|
CLAY_RENDER_COMMAND_TYPE_BORDER :: BORDER;
|
||||||
|
CLAY_RENDER_COMMAND_TYPE_TEXT :: TEXT;
|
||||||
|
CLAY_RENDER_COMMAND_TYPE_IMAGE :: IMAGE;
|
||||||
|
CLAY_RENDER_COMMAND_TYPE_SCISSOR_START :: SCISSOR_START;
|
||||||
|
CLAY_RENDER_COMMAND_TYPE_SCISSOR_END :: SCISSOR_END;
|
||||||
|
CLAY_RENDER_COMMAND_TYPE_CUSTOM :: CUSTOM;
|
||||||
|
}
|
||||||
|
|
||||||
|
RenderCommand :: struct {
|
||||||
|
boundingBox: BoundingBox;
|
||||||
|
config: ElementConfigUnion;
|
||||||
|
text: String; // TODO I wish there was a way to avoid having to have this on every render command
|
||||||
|
id: u32;
|
||||||
|
commandType: RenderCommandType;
|
||||||
|
}
|
||||||
|
|
||||||
|
RenderCommandArray :: struct {
|
||||||
|
capacity: s32;
|
||||||
|
length: s32;
|
||||||
|
internalArray: *RenderCommand;
|
||||||
|
}
|
||||||
|
|
||||||
|
PointerDataInteractionState :: enum u32 {
|
||||||
|
PRESSED_THIS_FRAME :: 0;
|
||||||
|
PRESSED :: 1;
|
||||||
|
RELEASED_THIS_FRAME :: 2;
|
||||||
|
RELEASED :: 3;
|
||||||
|
CLAY_POINTER_DATA_PRESSED_THIS_FRAME :: PRESSED_THIS_FRAME;
|
||||||
|
CLAY_POINTER_DATA_PRESSED :: PRESSED;
|
||||||
|
CLAY_POINTER_DATA_RELEASED_THIS_FRAME :: RELEASED_THIS_FRAME;
|
||||||
|
CLAY_POINTER_DATA_RELEASED :: RELEASED;
|
||||||
|
}
|
||||||
|
|
||||||
|
PointerData :: struct {
|
||||||
|
position: Vector2;
|
||||||
|
state: PointerDataInteractionState;
|
||||||
|
}
|
||||||
|
|
||||||
|
ErrorType :: enum u32 {
|
||||||
|
TEXT_MEASUREMENT_FUNCTION_NOT_PROVIDED :: 0;
|
||||||
|
ARENA_CAPACITY_EXCEEDED :: 1;
|
||||||
|
ELEMENTS_CAPACITY_EXCEEDED :: 2;
|
||||||
|
TEXT_MEASUREMENT_CAPACITY_EXCEEDED :: 3;
|
||||||
|
DUPLICATE_ID :: 4;
|
||||||
|
FLOATING_CONTAINER_PARENT_NOT_FOUND :: 5;
|
||||||
|
INTERNAL_ERROR :: 6;
|
||||||
|
CLAY_ERROR_TYPE_TEXT_MEASUREMENT_FUNCTION_NOT_PROVIDED :: TEXT_MEASUREMENT_FUNCTION_NOT_PROVIDED;
|
||||||
|
CLAY_ERROR_TYPE_ARENA_CAPACITY_EXCEEDED :: ARENA_CAPACITY_EXCEEDED;
|
||||||
|
CLAY_ERROR_TYPE_ELEMENTS_CAPACITY_EXCEEDED :: ELEMENTS_CAPACITY_EXCEEDED;
|
||||||
|
CLAY_ERROR_TYPE_TEXT_MEASUREMENT_CAPACITY_EXCEEDED :: TEXT_MEASUREMENT_CAPACITY_EXCEEDED;
|
||||||
|
CLAY_ERROR_TYPE_DUPLICATE_ID :: DUPLICATE_ID;
|
||||||
|
CLAY_ERROR_TYPE_FLOATING_CONTAINER_PARENT_NOT_FOUND :: FLOATING_CONTAINER_PARENT_NOT_FOUND;
|
||||||
|
CLAY_ERROR_TYPE_INTERNAL_ERROR :: INTERNAL_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
ErrorData :: struct {
|
||||||
|
errorType: ErrorType;
|
||||||
|
errorText: String;
|
||||||
|
userData: u64;
|
||||||
|
}
|
||||||
|
|
||||||
|
ErrorHandler :: struct {
|
||||||
|
errorHandlerFunction: #type (errorText: ErrorData) -> void #c_call;
|
||||||
|
userData: u64;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Function Forward Declarations ---------------------------------
|
||||||
|
// Public API functions ---
|
||||||
|
MinMemorySize :: () -> u32 #foreign clay "Clay_MinMemorySize";
|
||||||
|
CreateArenaWithCapacityAndMemory :: (capacity: u32, offset: *void) -> Arena #foreign clay "Clay_CreateArenaWithCapacityAndMemory";
|
||||||
|
SetPointerState :: (position: Vector2, pointerDown: bool) -> void #foreign clay "Clay_SetPointerState";
|
||||||
|
Initialize :: (arena: Arena, layoutDimensions: Dimensions, errorHandler: ErrorHandler) -> *Context #foreign clay "Clay_Initialize";
|
||||||
|
GetCurrentContext :: () -> *Context #foreign clay "Clay_GetCurrentContext";
|
||||||
|
SetCurrentContext :: (_context: *Context) -> void #foreign clay "Clay_SetCurrentContext";
|
||||||
|
UpdateScrollContainers :: (enableDragScrolling: bool, scrollDelta: Vector2, deltaTime: float) -> void #foreign clay "Clay_UpdateScrollContainers";
|
||||||
|
SetLayoutDimensions :: (dimensions: Dimensions) -> void #foreign clay "Clay_SetLayoutDimensions";
|
||||||
|
BeginLayout :: () -> void #foreign clay "Clay_BeginLayout";
|
||||||
|
EndLayout :: () -> RenderCommandArray #foreign clay "Clay_EndLayout";
|
||||||
|
GetElementId :: (idString: String) -> ElementId #foreign clay "Clay_GetElementId";
|
||||||
|
GetElementIdWithIndex :: (idString: String, index: u32) -> ElementId #foreign clay "Clay_GetElementIdWithIndex";
|
||||||
|
|
||||||
|
PointerOver :: (elementId: ElementId) -> bool #foreign clay "Clay_PointerOver";
|
||||||
|
GetScrollContainerData :: (id: ElementId) -> ScrollContainerData #foreign clay "Clay_GetScrollContainerData";
|
||||||
|
SetMeasureTextFunction :: (measureTextFunction: #type (text: *String, config: *TextElementConfig) -> Dimensions #c_call) -> void #foreign clay "Clay_SetMeasureTextFunction";
|
||||||
|
SetQueryScrollOffsetFunction :: (queryScrollOffsetFunction: #type (elementId: u32) -> Vector2 #c_call) -> void #foreign clay "Clay_SetQueryScrollOffsetFunction";
|
||||||
|
RenderCommandArray_Get :: (array: *RenderCommandArray, index: s32) -> *RenderCommand #foreign clay "Clay_RenderCommandArray_Get";
|
||||||
|
SetDebugModeEnabled :: (enabled: bool) -> void #foreign clay "Clay_SetDebugModeEnabled";
|
||||||
|
IsDebugModeEnabled :: () -> bool #foreign clay "Clay_IsDebugModeEnabled";
|
||||||
|
SetCullingEnabled :: (enabled: bool) -> void #foreign clay "Clay_SetCullingEnabled";
|
||||||
|
GetMaxElementCount :: () -> s32 #foreign clay "Clay_GetMaxElementCount";
|
||||||
|
SetMaxElementCount :: (maxElementCount: s32) -> void #foreign clay "Clay_SetMaxElementCount";
|
||||||
|
GetMaxMeasureTextCacheWordCount :: () -> s32 #foreign clay "Clay_GetMaxMeasureTextCacheWordCount";
|
||||||
|
SetMaxMeasureTextCacheWordCount :: (maxMeasureTextCacheWordCount: s32) -> void #foreign clay "Clay_SetMaxMeasureTextCacheWordCount";
|
||||||
|
|
||||||
|
// Internal API functions required by macros
|
||||||
|
_OpenElement :: () -> void #foreign clay "Clay__OpenElement";
|
||||||
|
_CloseElement :: () -> void #foreign clay "Clay__CloseElement";
|
||||||
|
_StoreLayoutConfig :: (config: LayoutConfig) -> *LayoutConfig #foreign clay "Clay__StoreLayoutConfig";
|
||||||
|
_ElementPostConfiguration :: () -> void #foreign clay "Clay__ElementPostConfiguration";
|
||||||
|
_AttachId :: (id: ElementId) -> void #foreign clay "Clay__AttachId";
|
||||||
|
_AttachLayoutConfig :: (config: *LayoutConfig) -> void #foreign clay "Clay__AttachLayoutConfig";
|
||||||
|
_AttachElementConfig :: (config: ElementConfigUnion, type: ElementConfigType) -> void #foreign clay "Clay__AttachElementConfig";
|
||||||
|
_StoreRectangleElementConfig :: (config: RectangleElementConfig) -> *RectangleElementConfig #foreign clay "Clay__StoreRectangleElementConfig";
|
||||||
|
_StoreTextElementConfig :: (config: TextElementConfig) -> *TextElementConfig #foreign clay "Clay__StoreTextElementConfig";
|
||||||
|
_StoreImageElementConfig :: (config: ImageElementConfig) -> *ImageElementConfig #foreign clay "Clay__StoreImageElementConfig";
|
||||||
|
_StoreFloatingElementConfig :: (config: FloatingElementConfig) -> *FloatingElementConfig #foreign clay "Clay__StoreFloatingElementConfig";
|
||||||
|
_StoreCustomElementConfig :: (config: CustomElementConfig) -> *CustomElementConfig #foreign clay "Clay__StoreCustomElementConfig";
|
||||||
|
_StoreScrollElementConfig :: (config: ScrollElementConfig) -> *ScrollElementConfig #foreign clay "Clay__StoreScrollElementConfig";
|
||||||
|
_StoreBorderElementConfig :: (config: BorderElementConfig) -> *BorderElementConfig #foreign clay "Clay__StoreBorderElementConfig";
|
||||||
|
_HashString :: (key: String, offset: u32, seed: u32) -> ElementId #foreign clay "Clay__HashString";
|
||||||
|
_OpenTextElement :: (text: String, textConfig: *TextElementConfig) -> void #foreign clay "Clay__OpenTextElement";
|
||||||
|
_GetParentElementId :: () -> u32 #foreign clay "Clay__GetParentElementId";
|
||||||
|
|
||||||
|
_debugViewHighlightColor: Color #elsewhere clay "Clay__debugViewHighlightColor";
|
||||||
|
_debugViewWidth: u32 #elsewhere clay "Clay__debugViewWidth";
|
||||||
|
|
||||||
|
#scope_file
|
||||||
|
|
||||||
|
#import "Basic"; // For assert
|
||||||
|
|
||||||
|
clay :: #library,no_dll "linux/clay";
|
||||||
|
|
||||||
|
#run {
|
||||||
|
{
|
||||||
|
instance: String;
|
||||||
|
assert(((cast(*void)(*instance.length)) - cast(*void)(*instance)) == 0, "String.length has unexpected offset % instead of 0", ((cast(*void)(*instance.length)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(String.length)) == 4, "String.length has unexpected size % instead of 4", size_of(type_of(String.length)));
|
||||||
|
assert(((cast(*void)(*instance.chars)) - cast(*void)(*instance)) == 8, "String.chars has unexpected offset % instead of 8", ((cast(*void)(*instance.chars)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(String.chars)) == 8, "String.chars has unexpected size % instead of 8", size_of(type_of(String.chars)));
|
||||||
|
assert(size_of(String) == 16, "String has size % instead of 16", size_of(String));
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
instance: _StringArray;
|
||||||
|
assert(((cast(*void)(*instance.capacity)) - cast(*void)(*instance)) == 0, "_StringArray.capacity has unexpected offset % instead of 0", ((cast(*void)(*instance.capacity)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(_StringArray.capacity)) == 4, "_StringArray.capacity has unexpected size % instead of 4", size_of(type_of(_StringArray.capacity)));
|
||||||
|
assert(((cast(*void)(*instance.length)) - cast(*void)(*instance)) == 4, "_StringArray.length has unexpected offset % instead of 4", ((cast(*void)(*instance.length)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(_StringArray.length)) == 4, "_StringArray.length has unexpected size % instead of 4", size_of(type_of(_StringArray.length)));
|
||||||
|
assert(((cast(*void)(*instance.internalArray)) - cast(*void)(*instance)) == 8, "_StringArray.internalArray has unexpected offset % instead of 8", ((cast(*void)(*instance.internalArray)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(_StringArray.internalArray)) == 8, "_StringArray.internalArray has unexpected size % instead of 8", size_of(type_of(_StringArray.internalArray)));
|
||||||
|
assert(size_of(_StringArray) == 16, "_StringArray has size % instead of 16", size_of(_StringArray));
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
instance: Arena;
|
||||||
|
assert(((cast(*void)(*instance.nextAllocation)) - cast(*void)(*instance)) == 0, "Arena.nextAllocation has unexpected offset % instead of 0", ((cast(*void)(*instance.nextAllocation)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(Arena.nextAllocation)) == 8, "Arena.nextAllocation has unexpected size % instead of 8", size_of(type_of(Arena.nextAllocation)));
|
||||||
|
assert(((cast(*void)(*instance.capacity)) - cast(*void)(*instance)) == 8, "Arena.capacity has unexpected offset % instead of 8", ((cast(*void)(*instance.capacity)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(Arena.capacity)) == 8, "Arena.capacity has unexpected size % instead of 8", size_of(type_of(Arena.capacity)));
|
||||||
|
assert(((cast(*void)(*instance.memory)) - cast(*void)(*instance)) == 16, "Arena.memory has unexpected offset % instead of 16", ((cast(*void)(*instance.memory)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(Arena.memory)) == 8, "Arena.memory has unexpected size % instead of 8", size_of(type_of(Arena.memory)));
|
||||||
|
assert(size_of(Arena) == 24, "Arena has size % instead of 24", size_of(Arena));
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
instance: Dimensions;
|
||||||
|
assert(((cast(*void)(*instance.width)) - cast(*void)(*instance)) == 0, "Dimensions.width has unexpected offset % instead of 0", ((cast(*void)(*instance.width)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(Dimensions.width)) == 4, "Dimensions.width has unexpected size % instead of 4", size_of(type_of(Dimensions.width)));
|
||||||
|
assert(((cast(*void)(*instance.height)) - cast(*void)(*instance)) == 4, "Dimensions.height has unexpected offset % instead of 4", ((cast(*void)(*instance.height)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(Dimensions.height)) == 4, "Dimensions.height has unexpected size % instead of 4", size_of(type_of(Dimensions.height)));
|
||||||
|
assert(size_of(Dimensions) == 8, "Dimensions has size % instead of 8", size_of(Dimensions));
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
instance: Color;
|
||||||
|
assert(((cast(*void)(*instance.r)) - cast(*void)(*instance)) == 0, "Color.r has unexpected offset % instead of 0", ((cast(*void)(*instance.r)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(Color.r)) == 4, "Color.r has unexpected size % instead of 4", size_of(type_of(Color.r)));
|
||||||
|
assert(((cast(*void)(*instance.g)) - cast(*void)(*instance)) == 4, "Color.g has unexpected offset % instead of 4", ((cast(*void)(*instance.g)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(Color.g)) == 4, "Color.g has unexpected size % instead of 4", size_of(type_of(Color.g)));
|
||||||
|
assert(((cast(*void)(*instance.b)) - cast(*void)(*instance)) == 8, "Color.b has unexpected offset % instead of 8", ((cast(*void)(*instance.b)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(Color.b)) == 4, "Color.b has unexpected size % instead of 4", size_of(type_of(Color.b)));
|
||||||
|
assert(((cast(*void)(*instance.a)) - cast(*void)(*instance)) == 12, "Color.a has unexpected offset % instead of 12", ((cast(*void)(*instance.a)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(Color.a)) == 4, "Color.a has unexpected size % instead of 4", size_of(type_of(Color.a)));
|
||||||
|
assert(size_of(Color) == 16, "Color has size % instead of 16", size_of(Color));
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
instance: BoundingBox;
|
||||||
|
assert(((cast(*void)(*instance.x)) - cast(*void)(*instance)) == 0, "BoundingBox.x has unexpected offset % instead of 0", ((cast(*void)(*instance.x)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(BoundingBox.x)) == 4, "BoundingBox.x has unexpected size % instead of 4", size_of(type_of(BoundingBox.x)));
|
||||||
|
assert(((cast(*void)(*instance.y)) - cast(*void)(*instance)) == 4, "BoundingBox.y has unexpected offset % instead of 4", ((cast(*void)(*instance.y)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(BoundingBox.y)) == 4, "BoundingBox.y has unexpected size % instead of 4", size_of(type_of(BoundingBox.y)));
|
||||||
|
assert(((cast(*void)(*instance.width)) - cast(*void)(*instance)) == 8, "BoundingBox.width has unexpected offset % instead of 8", ((cast(*void)(*instance.width)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(BoundingBox.width)) == 4, "BoundingBox.width has unexpected size % instead of 4", size_of(type_of(BoundingBox.width)));
|
||||||
|
assert(((cast(*void)(*instance.height)) - cast(*void)(*instance)) == 12, "BoundingBox.height has unexpected offset % instead of 12", ((cast(*void)(*instance.height)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(BoundingBox.height)) == 4, "BoundingBox.height has unexpected size % instead of 4", size_of(type_of(BoundingBox.height)));
|
||||||
|
assert(size_of(BoundingBox) == 16, "BoundingBox has size % instead of 16", size_of(BoundingBox));
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
instance: ElementId;
|
||||||
|
assert(((cast(*void)(*instance.id)) - cast(*void)(*instance)) == 0, "ElementId.id has unexpected offset % instead of 0", ((cast(*void)(*instance.id)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(ElementId.id)) == 4, "ElementId.id has unexpected size % instead of 4", size_of(type_of(ElementId.id)));
|
||||||
|
assert(((cast(*void)(*instance.offset)) - cast(*void)(*instance)) == 4, "ElementId.offset has unexpected offset % instead of 4", ((cast(*void)(*instance.offset)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(ElementId.offset)) == 4, "ElementId.offset has unexpected size % instead of 4", size_of(type_of(ElementId.offset)));
|
||||||
|
assert(((cast(*void)(*instance.baseId)) - cast(*void)(*instance)) == 8, "ElementId.baseId has unexpected offset % instead of 8", ((cast(*void)(*instance.baseId)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(ElementId.baseId)) == 4, "ElementId.baseId has unexpected size % instead of 4", size_of(type_of(ElementId.baseId)));
|
||||||
|
assert(((cast(*void)(*instance.stringId)) - cast(*void)(*instance)) == 16, "ElementId.stringId has unexpected offset % instead of 16", ((cast(*void)(*instance.stringId)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(ElementId.stringId)) == 16, "ElementId.stringId has unexpected size % instead of 16", size_of(type_of(ElementId.stringId)));
|
||||||
|
assert(size_of(ElementId) == 32, "ElementId has size % instead of 32", size_of(ElementId));
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
instance: CornerRadius;
|
||||||
|
assert(((cast(*void)(*instance.topLeft)) - cast(*void)(*instance)) == 0, "CornerRadius.topLeft has unexpected offset % instead of 0", ((cast(*void)(*instance.topLeft)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(CornerRadius.topLeft)) == 4, "CornerRadius.topLeft has unexpected size % instead of 4", size_of(type_of(CornerRadius.topLeft)));
|
||||||
|
assert(((cast(*void)(*instance.topRight)) - cast(*void)(*instance)) == 4, "CornerRadius.topRight has unexpected offset % instead of 4", ((cast(*void)(*instance.topRight)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(CornerRadius.topRight)) == 4, "CornerRadius.topRight has unexpected size % instead of 4", size_of(type_of(CornerRadius.topRight)));
|
||||||
|
assert(((cast(*void)(*instance.bottomLeft)) - cast(*void)(*instance)) == 8, "CornerRadius.bottomLeft has unexpected offset % instead of 8", ((cast(*void)(*instance.bottomLeft)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(CornerRadius.bottomLeft)) == 4, "CornerRadius.bottomLeft has unexpected size % instead of 4", size_of(type_of(CornerRadius.bottomLeft)));
|
||||||
|
assert(((cast(*void)(*instance.bottomRight)) - cast(*void)(*instance)) == 12, "CornerRadius.bottomRight has unexpected offset % instead of 12", ((cast(*void)(*instance.bottomRight)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(CornerRadius.bottomRight)) == 4, "CornerRadius.bottomRight has unexpected size % instead of 4", size_of(type_of(CornerRadius.bottomRight)));
|
||||||
|
assert(size_of(CornerRadius) == 16, "CornerRadius has size % instead of 16", size_of(CornerRadius));
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
instance: ChildAlignment;
|
||||||
|
assert(((cast(*void)(*instance.x)) - cast(*void)(*instance)) == 0, "ChildAlignment.x has unexpected offset % instead of 0", ((cast(*void)(*instance.x)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(ChildAlignment.x)) == 1, "ChildAlignment.x has unexpected size % instead of 1", size_of(type_of(ChildAlignment.x)));
|
||||||
|
assert(((cast(*void)(*instance.y)) - cast(*void)(*instance)) == 1, "ChildAlignment.y has unexpected offset % instead of 1", ((cast(*void)(*instance.y)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(ChildAlignment.y)) == 1, "ChildAlignment.y has unexpected size % instead of 1", size_of(type_of(ChildAlignment.y)));
|
||||||
|
assert(size_of(ChildAlignment) == 2, "ChildAlignment has size % instead of 2", size_of(ChildAlignment));
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
instance: SizingMinMax;
|
||||||
|
assert(((cast(*void)(*instance.min)) - cast(*void)(*instance)) == 0, "SizingMinMax.min has unexpected offset % instead of 0", ((cast(*void)(*instance.min)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(SizingMinMax.min)) == 4, "SizingMinMax.min has unexpected size % instead of 4", size_of(type_of(SizingMinMax.min)));
|
||||||
|
assert(((cast(*void)(*instance.max)) - cast(*void)(*instance)) == 4, "SizingMinMax.max has unexpected offset % instead of 4", ((cast(*void)(*instance.max)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(SizingMinMax.max)) == 4, "SizingMinMax.max has unexpected size % instead of 4", size_of(type_of(SizingMinMax.max)));
|
||||||
|
assert(size_of(SizingMinMax) == 8, "SizingMinMax has size % instead of 8", size_of(SizingMinMax));
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
instance: SizingAxis;
|
||||||
|
assert(((cast(*void)(*instance.size)) - cast(*void)(*instance)) == 0, "SizingAxis.size has unexpected offset % instead of 0", ((cast(*void)(*instance.size)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(SizingAxis.size)) == 8, "SizingAxis.size has unexpected size % instead of 8", size_of(type_of(SizingAxis.size)));
|
||||||
|
assert(((cast(*void)(*instance.type)) - cast(*void)(*instance)) == 8, "SizingAxis.type has unexpected offset % instead of 8", ((cast(*void)(*instance.type)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(SizingAxis.type)) == 1, "SizingAxis.type has unexpected size % instead of 1", size_of(type_of(SizingAxis.type)));
|
||||||
|
assert(size_of(SizingAxis) == 12, "SizingAxis has size % instead of 12", size_of(SizingAxis));
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
instance: Sizing;
|
||||||
|
assert(((cast(*void)(*instance.width)) - cast(*void)(*instance)) == 0, "Sizing.width has unexpected offset % instead of 0", ((cast(*void)(*instance.width)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(Sizing.width)) == 12, "Sizing.width has unexpected size % instead of 12", size_of(type_of(Sizing.width)));
|
||||||
|
assert(((cast(*void)(*instance.height)) - cast(*void)(*instance)) == 12, "Sizing.height has unexpected offset % instead of 12", ((cast(*void)(*instance.height)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(Sizing.height)) == 12, "Sizing.height has unexpected size % instead of 12", size_of(type_of(Sizing.height)));
|
||||||
|
assert(size_of(Sizing) == 24, "Sizing has size % instead of 24", size_of(Sizing));
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
instance: Padding;
|
||||||
|
assert(((cast(*void)(*instance.x)) - cast(*void)(*instance)) == 0, "Padding.x has unexpected offset % instead of 0", ((cast(*void)(*instance.x)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(Padding.x)) == 2, "Padding.x has unexpected size % instead of 2", size_of(type_of(Padding.x)));
|
||||||
|
assert(((cast(*void)(*instance.y)) - cast(*void)(*instance)) == 2, "Padding.y has unexpected offset % instead of 2", ((cast(*void)(*instance.y)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(Padding.y)) == 2, "Padding.y has unexpected size % instead of 2", size_of(type_of(Padding.y)));
|
||||||
|
assert(size_of(Padding) == 4, "Padding has size % instead of 4", size_of(Padding));
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
instance: LayoutConfig;
|
||||||
|
assert(((cast(*void)(*instance.sizing)) - cast(*void)(*instance)) == 0, "LayoutConfig.sizing has unexpected offset % instead of 0", ((cast(*void)(*instance.sizing)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(LayoutConfig.sizing)) == 24, "LayoutConfig.sizing has unexpected size % instead of 24", size_of(type_of(LayoutConfig.sizing)));
|
||||||
|
assert(((cast(*void)(*instance.padding)) - cast(*void)(*instance)) == 24, "LayoutConfig.padding has unexpected offset % instead of 24", ((cast(*void)(*instance.padding)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(LayoutConfig.padding)) == 4, "LayoutConfig.padding has unexpected size % instead of 4", size_of(type_of(LayoutConfig.padding)));
|
||||||
|
assert(((cast(*void)(*instance.childGap)) - cast(*void)(*instance)) == 28, "LayoutConfig.childGap has unexpected offset % instead of 28", ((cast(*void)(*instance.childGap)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(LayoutConfig.childGap)) == 2, "LayoutConfig.childGap has unexpected size % instead of 2", size_of(type_of(LayoutConfig.childGap)));
|
||||||
|
assert(((cast(*void)(*instance.childAlignment)) - cast(*void)(*instance)) == 30, "LayoutConfig.childAlignment has unexpected offset % instead of 30", ((cast(*void)(*instance.childAlignment)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(LayoutConfig.childAlignment)) == 2, "LayoutConfig.childAlignment has unexpected size % instead of 2", size_of(type_of(LayoutConfig.childAlignment)));
|
||||||
|
assert(((cast(*void)(*instance.layoutDirection)) - cast(*void)(*instance)) == 32, "LayoutConfig.layoutDirection has unexpected offset % instead of 32", ((cast(*void)(*instance.layoutDirection)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(LayoutConfig.layoutDirection)) == 1, "LayoutConfig.layoutDirection has unexpected size % instead of 1", size_of(type_of(LayoutConfig.layoutDirection)));
|
||||||
|
assert(size_of(LayoutConfig) == 36, "LayoutConfig has size % instead of 36", size_of(LayoutConfig));
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
instance: RectangleElementConfig;
|
||||||
|
assert(((cast(*void)(*instance.color)) - cast(*void)(*instance)) == 0, "RectangleElementConfig.color has unexpected offset % instead of 0", ((cast(*void)(*instance.color)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(RectangleElementConfig.color)) == 16, "RectangleElementConfig.color has unexpected size % instead of 16", size_of(type_of(RectangleElementConfig.color)));
|
||||||
|
assert(((cast(*void)(*instance.cornerRadius)) - cast(*void)(*instance)) == 16, "RectangleElementConfig.cornerRadius has unexpected offset % instead of 16", ((cast(*void)(*instance.cornerRadius)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(RectangleElementConfig.cornerRadius)) == 16, "RectangleElementConfig.cornerRadius has unexpected size % instead of 16", size_of(type_of(RectangleElementConfig.cornerRadius)));
|
||||||
|
assert(size_of(RectangleElementConfig) == 32, "RectangleElementConfig has size % instead of 32", size_of(RectangleElementConfig));
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
instance: TextElementConfig;
|
||||||
|
assert(((cast(*void)(*instance.textColor)) - cast(*void)(*instance)) == 0, "TextElementConfig.textColor has unexpected offset % instead of 0", ((cast(*void)(*instance.textColor)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(TextElementConfig.textColor)) == 16, "TextElementConfig.textColor has unexpected size % instead of 16", size_of(type_of(TextElementConfig.textColor)));
|
||||||
|
assert(((cast(*void)(*instance.fontId)) - cast(*void)(*instance)) == 16, "TextElementConfig.fontId has unexpected offset % instead of 16", ((cast(*void)(*instance.fontId)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(TextElementConfig.fontId)) == 2, "TextElementConfig.fontId has unexpected size % instead of 2", size_of(type_of(TextElementConfig.fontId)));
|
||||||
|
assert(((cast(*void)(*instance.fontSize)) - cast(*void)(*instance)) == 18, "TextElementConfig.fontSize has unexpected offset % instead of 18", ((cast(*void)(*instance.fontSize)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(TextElementConfig.fontSize)) == 2, "TextElementConfig.fontSize has unexpected size % instead of 2", size_of(type_of(TextElementConfig.fontSize)));
|
||||||
|
assert(((cast(*void)(*instance.letterSpacing)) - cast(*void)(*instance)) == 20, "TextElementConfig.letterSpacing has unexpected offset % instead of 20", ((cast(*void)(*instance.letterSpacing)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(TextElementConfig.letterSpacing)) == 2, "TextElementConfig.letterSpacing has unexpected size % instead of 2", size_of(type_of(TextElementConfig.letterSpacing)));
|
||||||
|
assert(((cast(*void)(*instance.lineHeight)) - cast(*void)(*instance)) == 22, "TextElementConfig.lineHeight has unexpected offset % instead of 22", ((cast(*void)(*instance.lineHeight)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(TextElementConfig.lineHeight)) == 2, "TextElementConfig.lineHeight has unexpected size % instead of 2", size_of(type_of(TextElementConfig.lineHeight)));
|
||||||
|
assert(((cast(*void)(*instance.wrapMode)) - cast(*void)(*instance)) == 24, "TextElementConfig.wrapMode has unexpected offset % instead of 24", ((cast(*void)(*instance.wrapMode)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(TextElementConfig.wrapMode)) == 4, "TextElementConfig.wrapMode has unexpected size % instead of 4", size_of(type_of(TextElementConfig.wrapMode)));
|
||||||
|
assert(size_of(TextElementConfig) == 28, "TextElementConfig has size % instead of 28", size_of(TextElementConfig));
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
instance: ImageElementConfig;
|
||||||
|
assert(((cast(*void)(*instance.imageData)) - cast(*void)(*instance)) == 0, "ImageElementConfig.imageData has unexpected offset % instead of 0", ((cast(*void)(*instance.imageData)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(ImageElementConfig.imageData)) == 8, "ImageElementConfig.imageData has unexpected size % instead of 8", size_of(type_of(ImageElementConfig.imageData)));
|
||||||
|
assert(((cast(*void)(*instance.sourceDimensions)) - cast(*void)(*instance)) == 8, "ImageElementConfig.sourceDimensions has unexpected offset % instead of 8", ((cast(*void)(*instance.sourceDimensions)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(ImageElementConfig.sourceDimensions)) == 8, "ImageElementConfig.sourceDimensions has unexpected size % instead of 8", size_of(type_of(ImageElementConfig.sourceDimensions)));
|
||||||
|
assert(size_of(ImageElementConfig) == 16, "ImageElementConfig has size % instead of 16", size_of(ImageElementConfig));
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
instance: FloatingAttachPoints;
|
||||||
|
assert(((cast(*void)(*instance.element)) - cast(*void)(*instance)) == 0, "FloatingAttachPoints.element has unexpected offset % instead of 0", ((cast(*void)(*instance.element)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(FloatingAttachPoints.element)) == 1, "FloatingAttachPoints.element has unexpected size % instead of 1", size_of(type_of(FloatingAttachPoints.element)));
|
||||||
|
assert(((cast(*void)(*instance.parent)) - cast(*void)(*instance)) == 1, "FloatingAttachPoints.parent has unexpected offset % instead of 1", ((cast(*void)(*instance.parent)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(FloatingAttachPoints.parent)) == 1, "FloatingAttachPoints.parent has unexpected size % instead of 1", size_of(type_of(FloatingAttachPoints.parent)));
|
||||||
|
assert(size_of(FloatingAttachPoints) == 2, "FloatingAttachPoints has size % instead of 2", size_of(FloatingAttachPoints));
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
instance: FloatingElementConfig;
|
||||||
|
assert(((cast(*void)(*instance.offset)) - cast(*void)(*instance)) == 0, "FloatingElementConfig.offset has unexpected offset % instead of 0", ((cast(*void)(*instance.offset)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(FloatingElementConfig.offset)) == 8, "FloatingElementConfig.offset has unexpected size % instead of 8", size_of(type_of(FloatingElementConfig.offset)));
|
||||||
|
assert(((cast(*void)(*instance.expand)) - cast(*void)(*instance)) == 8, "FloatingElementConfig.expand has unexpected offset % instead of 8", ((cast(*void)(*instance.expand)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(FloatingElementConfig.expand)) == 8, "FloatingElementConfig.expand has unexpected size % instead of 8", size_of(type_of(FloatingElementConfig.expand)));
|
||||||
|
assert(((cast(*void)(*instance.zIndex)) - cast(*void)(*instance)) == 16, "FloatingElementConfig.zIndex has unexpected offset % instead of 16", ((cast(*void)(*instance.zIndex)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(FloatingElementConfig.zIndex)) == 2, "FloatingElementConfig.zIndex has unexpected size % instead of 2", size_of(type_of(FloatingElementConfig.zIndex)));
|
||||||
|
assert(((cast(*void)(*instance.parentId)) - cast(*void)(*instance)) == 20, "FloatingElementConfig.parentId has unexpected offset % instead of 20", ((cast(*void)(*instance.parentId)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(FloatingElementConfig.parentId)) == 4, "FloatingElementConfig.parentId has unexpected size % instead of 4", size_of(type_of(FloatingElementConfig.parentId)));
|
||||||
|
assert(((cast(*void)(*instance.attachment)) - cast(*void)(*instance)) == 24, "FloatingElementConfig.attachment has unexpected offset % instead of 24", ((cast(*void)(*instance.attachment)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(FloatingElementConfig.attachment)) == 2, "FloatingElementConfig.attachment has unexpected size % instead of 2", size_of(type_of(FloatingElementConfig.attachment)));
|
||||||
|
assert(((cast(*void)(*instance.pointerCaptureMode)) - cast(*void)(*instance)) == 28, "FloatingElementConfig.pointerCaptureMode has unexpected offset % instead of 28", ((cast(*void)(*instance.pointerCaptureMode)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(FloatingElementConfig.pointerCaptureMode)) == 4, "FloatingElementConfig.pointerCaptureMode has unexpected size % instead of 4", size_of(type_of(FloatingElementConfig.pointerCaptureMode)));
|
||||||
|
assert(size_of(FloatingElementConfig) == 32, "FloatingElementConfig has size % instead of 32", size_of(FloatingElementConfig));
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
instance: CustomElementConfig;
|
||||||
|
assert(((cast(*void)(*instance.customData)) - cast(*void)(*instance)) == 0, "CustomElementConfig.customData has unexpected offset % instead of 0", ((cast(*void)(*instance.customData)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(CustomElementConfig.customData)) == 8, "CustomElementConfig.customData has unexpected size % instead of 8", size_of(type_of(CustomElementConfig.customData)));
|
||||||
|
assert(size_of(CustomElementConfig) == 8, "CustomElementConfig has size % instead of 8", size_of(CustomElementConfig));
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
instance: ScrollElementConfig;
|
||||||
|
assert(((cast(*void)(*instance.horizontal)) - cast(*void)(*instance)) == 0, "ScrollElementConfig.horizontal has unexpected offset % instead of 0", ((cast(*void)(*instance.horizontal)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(ScrollElementConfig.horizontal)) == 1, "ScrollElementConfig.horizontal has unexpected size % instead of 1", size_of(type_of(ScrollElementConfig.horizontal)));
|
||||||
|
assert(((cast(*void)(*instance.vertical)) - cast(*void)(*instance)) == 1, "ScrollElementConfig.vertical has unexpected offset % instead of 1", ((cast(*void)(*instance.vertical)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(ScrollElementConfig.vertical)) == 1, "ScrollElementConfig.vertical has unexpected size % instead of 1", size_of(type_of(ScrollElementConfig.vertical)));
|
||||||
|
assert(size_of(ScrollElementConfig) == 2, "ScrollElementConfig has size % instead of 2", size_of(ScrollElementConfig));
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
instance: ElementConfigUnion;
|
||||||
|
assert(((cast(*void)(*instance.rectangleElementConfig)) - cast(*void)(*instance)) == 0, "ElementConfigUnion.rectangleElementConfig has unexpected offset % instead of 0", ((cast(*void)(*instance.rectangleElementConfig)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(ElementConfigUnion.rectangleElementConfig)) == 8, "ElementConfigUnion.rectangleElementConfig has unexpected size % instead of 8", size_of(type_of(ElementConfigUnion.rectangleElementConfig)));
|
||||||
|
assert(((cast(*void)(*instance.textElementConfig)) - cast(*void)(*instance)) == 0, "ElementConfigUnion.textElementConfig has unexpected offset % instead of 0", ((cast(*void)(*instance.textElementConfig)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(ElementConfigUnion.textElementConfig)) == 8, "ElementConfigUnion.textElementConfig has unexpected size % instead of 8", size_of(type_of(ElementConfigUnion.textElementConfig)));
|
||||||
|
assert(((cast(*void)(*instance.imageElementConfig)) - cast(*void)(*instance)) == 0, "ElementConfigUnion.imageElementConfig has unexpected offset % instead of 0", ((cast(*void)(*instance.imageElementConfig)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(ElementConfigUnion.imageElementConfig)) == 8, "ElementConfigUnion.imageElementConfig has unexpected size % instead of 8", size_of(type_of(ElementConfigUnion.imageElementConfig)));
|
||||||
|
assert(((cast(*void)(*instance.floatingElementConfig)) - cast(*void)(*instance)) == 0, "ElementConfigUnion.floatingElementConfig has unexpected offset % instead of 0", ((cast(*void)(*instance.floatingElementConfig)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(ElementConfigUnion.floatingElementConfig)) == 8, "ElementConfigUnion.floatingElementConfig has unexpected size % instead of 8", size_of(type_of(ElementConfigUnion.floatingElementConfig)));
|
||||||
|
assert(((cast(*void)(*instance.customElementConfig)) - cast(*void)(*instance)) == 0, "ElementConfigUnion.customElementConfig has unexpected offset % instead of 0", ((cast(*void)(*instance.customElementConfig)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(ElementConfigUnion.customElementConfig)) == 8, "ElementConfigUnion.customElementConfig has unexpected size % instead of 8", size_of(type_of(ElementConfigUnion.customElementConfig)));
|
||||||
|
assert(((cast(*void)(*instance.scrollElementConfig)) - cast(*void)(*instance)) == 0, "ElementConfigUnion.scrollElementConfig has unexpected offset % instead of 0", ((cast(*void)(*instance.scrollElementConfig)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(ElementConfigUnion.scrollElementConfig)) == 8, "ElementConfigUnion.scrollElementConfig has unexpected size % instead of 8", size_of(type_of(ElementConfigUnion.scrollElementConfig)));
|
||||||
|
assert(((cast(*void)(*instance.borderElementConfig)) - cast(*void)(*instance)) == 0, "ElementConfigUnion.borderElementConfig has unexpected offset % instead of 0", ((cast(*void)(*instance.borderElementConfig)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(ElementConfigUnion.borderElementConfig)) == 8, "ElementConfigUnion.borderElementConfig has unexpected size % instead of 8", size_of(type_of(ElementConfigUnion.borderElementConfig)));
|
||||||
|
assert(size_of(ElementConfigUnion) == 8, "ElementConfigUnion has size % instead of 8", size_of(ElementConfigUnion));
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
instance: ElementConfig;
|
||||||
|
assert(((cast(*void)(*instance.type)) - cast(*void)(*instance)) == 0, "ElementConfig.type has unexpected offset % instead of 0", ((cast(*void)(*instance.type)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(ElementConfig.type)) == 1, "ElementConfig.type has unexpected size % instead of 1", size_of(type_of(ElementConfig.type)));
|
||||||
|
assert(((cast(*void)(*instance.config)) - cast(*void)(*instance)) == 8, "ElementConfig.config has unexpected offset % instead of 8", ((cast(*void)(*instance.config)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(ElementConfig.config)) == 8, "ElementConfig.config has unexpected size % instead of 8", size_of(type_of(ElementConfig.config)));
|
||||||
|
assert(size_of(ElementConfig) == 16, "ElementConfig has size % instead of 16", size_of(ElementConfig));
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
instance: ScrollContainerData;
|
||||||
|
assert(((cast(*void)(*instance.scrollPosition)) - cast(*void)(*instance)) == 0, "ScrollContainerData.scrollPosition has unexpected offset % instead of 0", ((cast(*void)(*instance.scrollPosition)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(ScrollContainerData.scrollPosition)) == 8, "ScrollContainerData.scrollPosition has unexpected size % instead of 8", size_of(type_of(ScrollContainerData.scrollPosition)));
|
||||||
|
assert(((cast(*void)(*instance.scrollContainerDimensions)) - cast(*void)(*instance)) == 8, "ScrollContainerData.scrollContainerDimensions has unexpected offset % instead of 8", ((cast(*void)(*instance.scrollContainerDimensions)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(ScrollContainerData.scrollContainerDimensions)) == 8, "ScrollContainerData.scrollContainerDimensions has unexpected size % instead of 8", size_of(type_of(ScrollContainerData.scrollContainerDimensions)));
|
||||||
|
assert(((cast(*void)(*instance.contentDimensions)) - cast(*void)(*instance)) == 16, "ScrollContainerData.contentDimensions has unexpected offset % instead of 16", ((cast(*void)(*instance.contentDimensions)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(ScrollContainerData.contentDimensions)) == 8, "ScrollContainerData.contentDimensions has unexpected size % instead of 8", size_of(type_of(ScrollContainerData.contentDimensions)));
|
||||||
|
assert(((cast(*void)(*instance.config)) - cast(*void)(*instance)) == 24, "ScrollContainerData.config has unexpected offset % instead of 24", ((cast(*void)(*instance.config)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(ScrollContainerData.config)) == 2, "ScrollContainerData.config has unexpected size % instead of 2", size_of(type_of(ScrollContainerData.config)));
|
||||||
|
assert(((cast(*void)(*instance.found)) - cast(*void)(*instance)) == 26, "ScrollContainerData.found has unexpected offset % instead of 26", ((cast(*void)(*instance.found)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(ScrollContainerData.found)) == 1, "ScrollContainerData.found has unexpected size % instead of 1", size_of(type_of(ScrollContainerData.found)));
|
||||||
|
assert(size_of(ScrollContainerData) == 32, "ScrollContainerData has size % instead of 32", size_of(ScrollContainerData));
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
instance: RenderCommand;
|
||||||
|
assert(((cast(*void)(*instance.boundingBox)) - cast(*void)(*instance)) == 0, "RenderCommand.boundingBox has unexpected offset % instead of 0", ((cast(*void)(*instance.boundingBox)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(RenderCommand.boundingBox)) == 16, "RenderCommand.boundingBox has unexpected size % instead of 16", size_of(type_of(RenderCommand.boundingBox)));
|
||||||
|
assert(((cast(*void)(*instance.config)) - cast(*void)(*instance)) == 16, "RenderCommand.config has unexpected offset % instead of 16", ((cast(*void)(*instance.config)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(RenderCommand.config)) == 8, "RenderCommand.config has unexpected size % instead of 8", size_of(type_of(RenderCommand.config)));
|
||||||
|
assert(((cast(*void)(*instance.text)) - cast(*void)(*instance)) == 24, "RenderCommand.text has unexpected offset % instead of 24", ((cast(*void)(*instance.text)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(RenderCommand.text)) == 16, "RenderCommand.text has unexpected size % instead of 16", size_of(type_of(RenderCommand.text)));
|
||||||
|
assert(((cast(*void)(*instance.id)) - cast(*void)(*instance)) == 40, "RenderCommand.id has unexpected offset % instead of 40", ((cast(*void)(*instance.id)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(RenderCommand.id)) == 4, "RenderCommand.id has unexpected size % instead of 4", size_of(type_of(RenderCommand.id)));
|
||||||
|
assert(((cast(*void)(*instance.commandType)) - cast(*void)(*instance)) == 44, "RenderCommand.commandType has unexpected offset % instead of 44", ((cast(*void)(*instance.commandType)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(RenderCommand.commandType)) == 1, "RenderCommand.commandType has unexpected size % instead of 1", size_of(type_of(RenderCommand.commandType)));
|
||||||
|
assert(size_of(RenderCommand) == 48, "RenderCommand has size % instead of 48", size_of(RenderCommand));
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
instance: RenderCommandArray;
|
||||||
|
assert(((cast(*void)(*instance.capacity)) - cast(*void)(*instance)) == 0, "RenderCommandArray.capacity has unexpected offset % instead of 0", ((cast(*void)(*instance.capacity)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(RenderCommandArray.capacity)) == 4, "RenderCommandArray.capacity has unexpected size % instead of 4", size_of(type_of(RenderCommandArray.capacity)));
|
||||||
|
assert(((cast(*void)(*instance.length)) - cast(*void)(*instance)) == 4, "RenderCommandArray.length has unexpected offset % instead of 4", ((cast(*void)(*instance.length)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(RenderCommandArray.length)) == 4, "RenderCommandArray.length has unexpected size % instead of 4", size_of(type_of(RenderCommandArray.length)));
|
||||||
|
assert(((cast(*void)(*instance.internalArray)) - cast(*void)(*instance)) == 8, "RenderCommandArray.internalArray has unexpected offset % instead of 8", ((cast(*void)(*instance.internalArray)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(RenderCommandArray.internalArray)) == 8, "RenderCommandArray.internalArray has unexpected size % instead of 8", size_of(type_of(RenderCommandArray.internalArray)));
|
||||||
|
assert(size_of(RenderCommandArray) == 16, "RenderCommandArray has size % instead of 16", size_of(RenderCommandArray));
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
instance: PointerData;
|
||||||
|
assert(((cast(*void)(*instance.position)) - cast(*void)(*instance)) == 0, "PointerData.position has unexpected offset % instead of 0", ((cast(*void)(*instance.position)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(PointerData.position)) == 8, "PointerData.position has unexpected size % instead of 8", size_of(type_of(PointerData.position)));
|
||||||
|
assert(((cast(*void)(*instance.state)) - cast(*void)(*instance)) == 8, "PointerData.state has unexpected offset % instead of 8", ((cast(*void)(*instance.state)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(PointerData.state)) == 4, "PointerData.state has unexpected size % instead of 4", size_of(type_of(PointerData.state)));
|
||||||
|
assert(size_of(PointerData) == 12, "PointerData has size % instead of 12", size_of(PointerData));
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
instance: ErrorData;
|
||||||
|
assert(((cast(*void)(*instance.errorType)) - cast(*void)(*instance)) == 0, "ErrorData.errorType has unexpected offset % instead of 0", ((cast(*void)(*instance.errorType)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(ErrorData.errorType)) == 4, "ErrorData.errorType has unexpected size % instead of 4", size_of(type_of(ErrorData.errorType)));
|
||||||
|
assert(((cast(*void)(*instance.errorText)) - cast(*void)(*instance)) == 8, "ErrorData.errorText has unexpected offset % instead of 8", ((cast(*void)(*instance.errorText)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(ErrorData.errorText)) == 16, "ErrorData.errorText has unexpected size % instead of 16", size_of(type_of(ErrorData.errorText)));
|
||||||
|
assert(((cast(*void)(*instance.userData)) - cast(*void)(*instance)) == 24, "ErrorData.userData has unexpected offset % instead of 24", ((cast(*void)(*instance.userData)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(ErrorData.userData)) == 8, "ErrorData.userData has unexpected size % instead of 8", size_of(type_of(ErrorData.userData)));
|
||||||
|
assert(size_of(ErrorData) == 32, "ErrorData has size % instead of 32", size_of(ErrorData));
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
instance: ErrorHandler;
|
||||||
|
assert(((cast(*void)(*instance.errorHandlerFunction)) - cast(*void)(*instance)) == 0, "ErrorHandler.errorHandlerFunction has unexpected offset % instead of 0", ((cast(*void)(*instance.errorHandlerFunction)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(ErrorHandler.errorHandlerFunction)) == 8, "ErrorHandler.errorHandlerFunction has unexpected size % instead of 8", size_of(type_of(ErrorHandler.errorHandlerFunction)));
|
||||||
|
assert(((cast(*void)(*instance.userData)) - cast(*void)(*instance)) == 8, "ErrorHandler.userData has unexpected offset % instead of 8", ((cast(*void)(*instance.userData)) - cast(*void)(*instance)));
|
||||||
|
assert(size_of(type_of(ErrorHandler.userData)) == 8, "ErrorHandler.userData has unexpected size % instead of 8", size_of(type_of(ErrorHandler.userData)));
|
||||||
|
assert(size_of(ErrorHandler) == 16, "ErrorHandler has size % instead of 16", size_of(ErrorHandler));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
BIN
bindings/jai/clay-jai/linux/clay.a
Normal file
BIN
bindings/jai/clay-jai/linux/clay.a
Normal file
Binary file not shown.
296
bindings/jai/clay-jai/module.jai
Normal file
296
bindings/jai/clay-jai/module.jai
Normal file
@ -0,0 +1,296 @@
|
|||||||
|
/*
|
||||||
|
These bindings adapt the CLAY macro using some for_expansion trickery, allowing a syntax similar to the one in the Odin bindings.
|
||||||
|
I'll try to explain here why I did it that way.
|
||||||
|
|
||||||
|
In Odin, they can mark the procedure with deferred_none, allowing to call a proc after the current one, which works well with ifs.
|
||||||
|
|
||||||
|
@(require_results, deferred_none = _CloseElement)
|
||||||
|
UI :: proc(configs: ..TypedConfig) -> bool {}
|
||||||
|
|
||||||
|
You can then use it like so :
|
||||||
|
|
||||||
|
if UI(Layout(), etc..) {Children ...}
|
||||||
|
|
||||||
|
So I tried to replicate this in Jai. The first thing I did was to try making a macro returning a bool with a backticked defer in it.
|
||||||
|
|
||||||
|
UI :: (configs: ..TypedConfig) -> bool #must #expand {
|
||||||
|
`defer EndElement();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
But this doesn't work if you have two elements side to side, as the end of the first element will be called after the start and the end of the second one.
|
||||||
|
|
||||||
|
Another option used in these bindings : https://github.com/nick-celestin-zizic/clay-jai is to have that defer like above and have the macro return nothing. You can then use it like that :
|
||||||
|
|
||||||
|
{ UI(Layout()); Children(); }
|
||||||
|
|
||||||
|
But I'm not a big fan of that since it's possible to forget the scope braces or to put the children before the element.
|
||||||
|
|
||||||
|
TODO This part is wrong... delete it and write the code that works
|
||||||
|
|
||||||
|
Another option to consider is to pass a code block to a macro that puts it between the start and the end.
|
||||||
|
|
||||||
|
UI :: (id: ElementId, layout: LayoutConfig, configs: ..ElementConfig, $code: Code) {
|
||||||
|
OpenElement();
|
||||||
|
...
|
||||||
|
#insert code;
|
||||||
|
CloseElement();
|
||||||
|
}
|
||||||
|
|
||||||
|
UI(..., #code {
|
||||||
|
Children();
|
||||||
|
});
|
||||||
|
|
||||||
|
However this prevents to refer to variables from the previous scope, and it's also a bit akward to type.
|
||||||
|
|
||||||
|
The final solution I found, inspired by the fact that CLAY uses a for loop behind the scene, was to use Jai's for_expansions.
|
||||||
|
Here is how it works :
|
||||||
|
|
||||||
|
InternalElementConfigArray :: struct {
|
||||||
|
configs: [] TypedConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
Element :: (configs: ..TypedConfig) -> InternalElementConfigArray #expand {
|
||||||
|
return .{configs};
|
||||||
|
}
|
||||||
|
|
||||||
|
for_expansion :: (configs_array: InternalElementConfigArray, body: Code, _: For_Flags) #expand {
|
||||||
|
Jai forces the definition of these
|
||||||
|
`it_index := 0;
|
||||||
|
`it := 0;
|
||||||
|
_OpenElement();
|
||||||
|
...
|
||||||
|
#insert body;
|
||||||
|
_CloseElement();
|
||||||
|
}
|
||||||
|
|
||||||
|
As you can see it's kinda similar to the previous one, but doesn't have the limitation on refering to variable from the calling scope.
|
||||||
|
Element builds an InternalElementConfigArray that has an array to the TypedConfigs, which will be passed to the for_expansion when placed after a for (this is a Jai feature).
|
||||||
|
This then allows to write something like :
|
||||||
|
|
||||||
|
for Element(Layout()) { Children(); }
|
||||||
|
|
||||||
|
With the downside that it's not obvious why the for is there before reading the documentation.
|
||||||
|
*/
|
||||||
|
|
||||||
|
Vector2 :: Math.Vector2;
|
||||||
|
|
||||||
|
ElementConfigType :: enum u8 {
|
||||||
|
NONE :: 0;
|
||||||
|
RECTANGLE :: 1;
|
||||||
|
BORDER_CONTAINER :: 2;
|
||||||
|
FLOATING_CONTAINER :: 4;
|
||||||
|
SCROLL_CONTAINER :: 8;
|
||||||
|
IMAGE :: 16;
|
||||||
|
TEXT :: 32;
|
||||||
|
CUSTOM :: 64;
|
||||||
|
CLAY__ELEMENT_CONFIG_TYPE_NONE :: NONE;
|
||||||
|
CLAY__ELEMENT_CONFIG_TYPE_RECTANGLE :: RECTANGLE;
|
||||||
|
CLAY__ELEMENT_CONFIG_TYPE_BORDER_CONTAINER :: BORDER_CONTAINER;
|
||||||
|
CLAY__ELEMENT_CONFIG_TYPE_FLOATING_CONTAINER :: FLOATING_CONTAINER;
|
||||||
|
CLAY__ELEMENT_CONFIG_TYPE_SCROLL_CONTAINER :: SCROLL_CONTAINER;
|
||||||
|
CLAY__ELEMENT_CONFIG_TYPE_IMAGE :: IMAGE;
|
||||||
|
CLAY__ELEMENT_CONFIG_TYPE_TEXT :: TEXT;
|
||||||
|
CLAY__ELEMENT_CONFIG_TYPE_CUSTOM :: CUSTOM;
|
||||||
|
|
||||||
|
// Jai bindings specific types, please don't assume any value in those
|
||||||
|
// a it might change if the enums above overlap with it
|
||||||
|
// TODO Check if these values need to be powers of two
|
||||||
|
ID :: 250;
|
||||||
|
LAYOUT :: 251;
|
||||||
|
}
|
||||||
|
|
||||||
|
// This is passed to UI so that we can omit layout
|
||||||
|
TypedConfig :: struct {
|
||||||
|
type: ElementConfigType;
|
||||||
|
config: *void;
|
||||||
|
id: ElementId;
|
||||||
|
}
|
||||||
|
|
||||||
|
BorderData :: struct {
|
||||||
|
width: u32;
|
||||||
|
color: Color;
|
||||||
|
}
|
||||||
|
|
||||||
|
BorderElementConfig :: struct {
|
||||||
|
left: BorderData;
|
||||||
|
right: BorderData;
|
||||||
|
top: BorderData;
|
||||||
|
bottom: BorderData;
|
||||||
|
betweenChildren: BorderData;
|
||||||
|
cornerRadius: CornerRadius;
|
||||||
|
}
|
||||||
|
|
||||||
|
make_string :: (str: string) -> String {
|
||||||
|
clay_string := String.{cast(s32, str.count), str.data};
|
||||||
|
return clay_string;
|
||||||
|
}
|
||||||
|
|
||||||
|
global_counter := 0;
|
||||||
|
|
||||||
|
for_expansion :: (configs_array: InternalElementConfigArray, body: Code, _: For_Flags) #expand {
|
||||||
|
// Jai forces the definition of these
|
||||||
|
`it_index := 0;
|
||||||
|
`it := 0;
|
||||||
|
|
||||||
|
_OpenElement();
|
||||||
|
for config : configs_array.configs {
|
||||||
|
if config.type == {
|
||||||
|
case .ID;
|
||||||
|
_AttachId(config.id);
|
||||||
|
case .LAYOUT;
|
||||||
|
_AttachLayoutConfig(cast(*LayoutConfig, config.config));
|
||||||
|
case;
|
||||||
|
// config.config is a *void, it stores the address of the pointer that is stored in the union
|
||||||
|
// as ElementConfigUnion is a union of structs. We can't cast pointers directly to structs,
|
||||||
|
// we first cast the address of the *void and then dereference it.
|
||||||
|
// Maybe there's a cast modifier to avoid this, but I don't know it (no_check and trunc didn't work).
|
||||||
|
_AttachElementConfig(cast(*ElementConfigUnion, *config.config).*, config.type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ElementPostConfiguration();
|
||||||
|
|
||||||
|
#insert body;
|
||||||
|
|
||||||
|
_CloseElement();
|
||||||
|
}
|
||||||
|
|
||||||
|
Element :: (configs: ..TypedConfig) -> InternalElementConfigArray #expand {
|
||||||
|
return .{configs};
|
||||||
|
}
|
||||||
|
|
||||||
|
ID :: (label: string, index: u32 = 0) -> TypedConfig {
|
||||||
|
return .{type = .ID, id = _HashString(make_string(label), index, 0)};
|
||||||
|
}
|
||||||
|
|
||||||
|
Layout :: (config: LayoutConfig) -> TypedConfig {
|
||||||
|
return .{type = .LAYOUT, config = _StoreLayoutConfig(config)};
|
||||||
|
}
|
||||||
|
|
||||||
|
Rectangle :: (config: RectangleElementConfig) -> TypedConfig {
|
||||||
|
return .{
|
||||||
|
type = .RECTANGLE,
|
||||||
|
config = _StoreRectangleElementConfig(config)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
Floating :: (config: FloatingElementConfig) -> TypedConfig {
|
||||||
|
return .{type = .FLOATING_CONTAINER, config = _StoreFloatingElementConfig(config)};
|
||||||
|
}
|
||||||
|
|
||||||
|
Scroll :: (config: ScrollElementConfig) -> TypedConfig {
|
||||||
|
return .{type = .SCROLL_CONTAINER, config = _StoreScrollElementConfig(config)};
|
||||||
|
}
|
||||||
|
|
||||||
|
Image :: (config: ImageElementConfig) -> TypedConfig {
|
||||||
|
return .{type = .IMAGE, config = _StoreImageElementConfig(config)};
|
||||||
|
}
|
||||||
|
|
||||||
|
Custom :: (config: CustomElementConfig) -> TypedConfig {
|
||||||
|
return .{type = .CUSTOM, config = _StoreCustomElementConfig(config)};
|
||||||
|
}
|
||||||
|
|
||||||
|
Border :: (config: BorderElementConfig) -> TypedConfig {
|
||||||
|
return .{type = .BORDER, _StoreBorderElementConfig(config)};
|
||||||
|
}
|
||||||
|
|
||||||
|
BorderOutside :: (outside_borders: BorderData) -> TypedConfig {
|
||||||
|
return .{
|
||||||
|
type = .BORDER,
|
||||||
|
config = _StoreBorderElementConfig(BorderElementConfig.{
|
||||||
|
left = outside_borders,
|
||||||
|
right = outside_borders,
|
||||||
|
top = outside_borders,
|
||||||
|
bottom = outside_borders,
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
BorderOutsideRadius :: (outside_borders: BorderData, radius: float) -> TypedConfig {
|
||||||
|
return .{
|
||||||
|
type = .BORDER,
|
||||||
|
config = _StoreBorderElementConfig(.{
|
||||||
|
left = outside_borders,
|
||||||
|
right = outside_borders,
|
||||||
|
top = outside_borders,
|
||||||
|
bottom = outside_borders,
|
||||||
|
cornerRadius = .{radius, radius, radius, radius},
|
||||||
|
})
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
BorderAll :: (all_borders: BorderData) -> TypedConfig {
|
||||||
|
return .{
|
||||||
|
type = .BORDER,
|
||||||
|
config = _StoreBorderElementConfig(.{
|
||||||
|
left = all_borders,
|
||||||
|
right = all_borders,
|
||||||
|
top = all_borders,
|
||||||
|
bottom = all_borders,
|
||||||
|
betweenChildren = all_borders,
|
||||||
|
})
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
BorderAllRadius :: (all_borders: BorderData, radius: float) -> TypedConfig {
|
||||||
|
return .{
|
||||||
|
type = .BORDER,
|
||||||
|
config = _StoreBorderElementConfig(.{
|
||||||
|
left = all_borders,
|
||||||
|
right = all_borders,
|
||||||
|
top = all_borders,
|
||||||
|
bottom = all_borders,
|
||||||
|
cornerRadius = .{radius, radius, radius, radius},
|
||||||
|
})
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
CornerRadiusAll :: (radius: float) -> CornerRadius {
|
||||||
|
return .{radius, radius, radius, radius};
|
||||||
|
}
|
||||||
|
|
||||||
|
Text :: (text: string, config: *TextElementConfig) {
|
||||||
|
_OpenTextElement(make_string(text), config);
|
||||||
|
}
|
||||||
|
|
||||||
|
TextConfig :: (config: TextElementConfig) -> *TextElementConfig {
|
||||||
|
return _StoreTextElementConfig(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
SizingFit :: (size_min_max: SizingMinMax) -> SizingAxis {
|
||||||
|
return .{type = .FIT, size = .{minMax = size_min_max}};
|
||||||
|
}
|
||||||
|
|
||||||
|
SizingGrow :: (size_min_max: SizingMinMax = .{}) -> SizingAxis {
|
||||||
|
return .{type = .GROW, size = .{minMax = size_min_max}};
|
||||||
|
}
|
||||||
|
|
||||||
|
SizingFixed :: (size: float) -> SizingAxis {
|
||||||
|
return .{type = .FIXED, size = .{minMax = .{size, size}}};
|
||||||
|
}
|
||||||
|
|
||||||
|
SizingPercent :: (size_percent: float) -> SizingAxis {
|
||||||
|
return .{type = .PERCENT, size = .{percent = size_percent}};
|
||||||
|
}
|
||||||
|
|
||||||
|
GetElementId :: (str: string) -> ElementId {
|
||||||
|
return GetElementId(make_string(str));
|
||||||
|
}
|
||||||
|
|
||||||
|
#scope_module
|
||||||
|
|
||||||
|
Math :: #import "Math";
|
||||||
|
Compiler :: #import "Compiler";
|
||||||
|
ProgramPrint :: #import "Program_Print";
|
||||||
|
|
||||||
|
InternalElementConfigArray :: struct {
|
||||||
|
configs: [] TypedConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if OS == .WINDOWS {
|
||||||
|
#load "windows.jai";
|
||||||
|
} else #if OS == .LINUX {
|
||||||
|
#load "linux.jai";
|
||||||
|
} else {
|
||||||
|
assert(false);
|
||||||
|
}
|
2
bindings/jai/clay-jai/source/clay.c
Normal file
2
bindings/jai/clay-jai/source/clay.c
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
#define CLAY_IMPLEMENTATION
|
||||||
|
#include "clay.h"
|
1293
bindings/jai/clay-jai/windows.jai
Normal file
1293
bindings/jai/clay-jai/windows.jai
Normal file
File diff suppressed because it is too large
Load Diff
BIN
bindings/jai/clay-jai/windows/clay.lib
Normal file
BIN
bindings/jai/clay-jai/windows/clay.lib
Normal file
Binary file not shown.
@ -0,0 +1,241 @@
|
|||||||
|
|
||||||
|
RaylibFont :: struct {
|
||||||
|
font_id: u16;
|
||||||
|
font: Raylib.Font;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_raylib_fonts: [10]RaylibFont;
|
||||||
|
|
||||||
|
to_raylib_color :: (color: Clay.Color) -> Raylib.Color {
|
||||||
|
return .{cast(u8) color.r, cast(u8) color.g, cast(u8) color.b, cast(u8) color.a};
|
||||||
|
}
|
||||||
|
|
||||||
|
raylib_measure_text :: (text: *Clay.String, config: *Clay.TextElementConfig) -> Clay.Dimensions #c_call {
|
||||||
|
text_size := Clay.Dimensions.{0, 0};
|
||||||
|
|
||||||
|
max_text_width: float = 0;
|
||||||
|
line_text_width: float = 0;
|
||||||
|
|
||||||
|
text_height := cast(float)config.fontSize;
|
||||||
|
font_to_use := g_raylib_fonts[config.fontId].font;
|
||||||
|
|
||||||
|
if text.length > 0 {
|
||||||
|
for 0..(text.length - 1) {
|
||||||
|
if text.chars[it] == #char "\n" {
|
||||||
|
max_text_width = c_max(max_text_width, line_text_width);
|
||||||
|
line_text_width = 0;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
index := cast(s32, text.chars[it]) - 32;
|
||||||
|
if font_to_use.glyphs[index].advanceX != 0 {
|
||||||
|
line_text_width += cast(float) font_to_use.glyphs[index].advanceX;
|
||||||
|
} else {
|
||||||
|
line_text_width += (font_to_use.recs[index].width + cast(float) font_to_use.glyphs[index].offsetX);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
max_text_width = c_max(max_text_width, line_text_width);
|
||||||
|
text_size.width = max_text_width / 2;
|
||||||
|
text_size.height = text_height;
|
||||||
|
|
||||||
|
return text_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
raylib_initialize :: (width: s32, height: s32, $$title: string, flags: Raylib.ConfigFlags) {
|
||||||
|
c_string_title: *u8;
|
||||||
|
#if is_constant(title) {
|
||||||
|
// Constant strings in Jai are null-terminated
|
||||||
|
c_string_title = title.data;
|
||||||
|
} else {
|
||||||
|
c_string_title = to_c_string(title);
|
||||||
|
}
|
||||||
|
|
||||||
|
Raylib.SetConfigFlags(flags);
|
||||||
|
Raylib.InitWindow(width, height, c_string_title);
|
||||||
|
}
|
||||||
|
|
||||||
|
clay_raylib_render :: (render_commands: Clay.RenderCommandArray) {
|
||||||
|
for 0..render_commands.length - 1 {
|
||||||
|
render_command := Clay.RenderCommandArray_Get(*render_commands, cast(s32) it);
|
||||||
|
bounding_box := render_command.boundingBox;
|
||||||
|
|
||||||
|
if #complete render_command.commandType == {
|
||||||
|
case .NONE;
|
||||||
|
case .TEXT;
|
||||||
|
text := string.{
|
||||||
|
cast(s64) render_command.text.length,
|
||||||
|
render_command.text.chars,
|
||||||
|
};
|
||||||
|
c_string_text := temp_c_string(text);
|
||||||
|
|
||||||
|
font_to_use: Raylib.Font = g_raylib_fonts[render_command.config.textElementConfig.fontId].font;
|
||||||
|
Raylib.DrawTextEx(
|
||||||
|
font_to_use,
|
||||||
|
c_string_text,
|
||||||
|
.{bounding_box.x, bounding_box.y},
|
||||||
|
cast(float) render_command.config.textElementConfig.fontSize,
|
||||||
|
cast(float) render_command.config.textElementConfig.letterSpacing,
|
||||||
|
to_raylib_color(render_command.config.textElementConfig.textColor),
|
||||||
|
);
|
||||||
|
case .IMAGE;
|
||||||
|
// TODO image handling
|
||||||
|
image_texture := cast(*Raylib.Texture2D, render_command.config.imageElementConfig.imageData).*;
|
||||||
|
Raylib.DrawTextureEx(
|
||||||
|
image_texture,
|
||||||
|
.{bounding_box.x, bounding_box.y},
|
||||||
|
0,
|
||||||
|
bounding_box.width / cast(float) image_texture.width,
|
||||||
|
Raylib.WHITE
|
||||||
|
);
|
||||||
|
case .SCISSOR_START;
|
||||||
|
Raylib.BeginScissorMode(
|
||||||
|
cast(s32, round(bounding_box.x)),
|
||||||
|
cast(s32, round(bounding_box.y)),
|
||||||
|
cast(s32, round(bounding_box.width)),
|
||||||
|
cast(s32, round(bounding_box.height)),
|
||||||
|
);
|
||||||
|
case .SCISSOR_END;
|
||||||
|
Raylib.EndScissorMode();
|
||||||
|
case .RECTANGLE;
|
||||||
|
config := render_command.config.rectangleElementConfig;
|
||||||
|
if config.cornerRadius.topLeft > 0 {
|
||||||
|
radius := (config.cornerRadius.topLeft * 2.0) / min(bounding_box.width, bounding_box.height);
|
||||||
|
Raylib.DrawRectangleRounded(
|
||||||
|
.{bounding_box.x, bounding_box.y, bounding_box.width, bounding_box.height},
|
||||||
|
radius,
|
||||||
|
8,
|
||||||
|
to_raylib_color(config.color),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
Raylib.DrawRectangle(
|
||||||
|
cast(s32, bounding_box.x),
|
||||||
|
cast(s32, bounding_box.y),
|
||||||
|
cast(s32, bounding_box.width),
|
||||||
|
cast(s32, bounding_box.height),
|
||||||
|
to_raylib_color(config.color),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
case .BORDER;
|
||||||
|
config := render_command.config.borderElementConfig;
|
||||||
|
|
||||||
|
// Left border
|
||||||
|
if config.left.width > 0 {
|
||||||
|
Raylib.DrawRectangle(
|
||||||
|
cast(s32, round(bounding_box.x)),
|
||||||
|
cast(s32, round(bounding_box.y + config.cornerRadius.topLeft)),
|
||||||
|
cast(s32, config.left.width),
|
||||||
|
cast(s32, round(bounding_box.height - config.cornerRadius.topLeft - config.cornerRadius.bottomLeft)),
|
||||||
|
to_raylib_color(config.right.color),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Right border
|
||||||
|
if config.right.width > 0 {
|
||||||
|
Raylib.DrawRectangle(
|
||||||
|
cast(s32, round(bounding_box.x + bounding_box.width - cast(float, config.right.width))),
|
||||||
|
cast(s32, round(bounding_box.y + config.cornerRadius.topRight)),
|
||||||
|
cast(s32, config.right.width),
|
||||||
|
cast(s32, round(bounding_box.height - config.cornerRadius.topRight - config.cornerRadius.bottomRight)),
|
||||||
|
to_raylib_color(config.right.color),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Top border
|
||||||
|
if config.top.width > 0 {
|
||||||
|
Raylib.DrawRectangle(
|
||||||
|
cast(s32, round(bounding_box.x + config.cornerRadius.topLeft)),
|
||||||
|
cast(s32, round(bounding_box.y)),
|
||||||
|
cast(s32, round(bounding_box.width - config.cornerRadius.topLeft - config.cornerRadius.topRight)),
|
||||||
|
cast(s32, config.top.width),
|
||||||
|
to_raylib_color(config.right.color),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bottom border
|
||||||
|
if config.bottom.width > 0 {
|
||||||
|
Raylib.DrawRectangle(
|
||||||
|
cast(s32, round(bounding_box.x + config.cornerRadius.bottomLeft)),
|
||||||
|
cast(s32, round(bounding_box.y + bounding_box.height - cast(float, config.bottom.width))),
|
||||||
|
cast(s32, round(bounding_box.width - config.cornerRadius.bottomLeft - config.cornerRadius.bottomRight)),
|
||||||
|
cast(s32, config.top.width),
|
||||||
|
to_raylib_color(config.right.color),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if config.cornerRadius.topLeft > 0 {
|
||||||
|
Raylib.DrawRing(
|
||||||
|
.{
|
||||||
|
round(bounding_box.x + config.cornerRadius.topLeft),
|
||||||
|
round(bounding_box.y + config.cornerRadius.topLeft),
|
||||||
|
},
|
||||||
|
round(config.cornerRadius.topLeft - cast(float, config.top.width)),
|
||||||
|
config.cornerRadius.topLeft,
|
||||||
|
180,
|
||||||
|
270,
|
||||||
|
10,
|
||||||
|
to_raylib_color(config.top.color),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if config.cornerRadius.topRight > 0 {
|
||||||
|
Raylib.DrawRing(
|
||||||
|
.{
|
||||||
|
round(bounding_box.x + bounding_box.width - config.cornerRadius.topRight),
|
||||||
|
round(bounding_box.y + config.cornerRadius.topRight),
|
||||||
|
},
|
||||||
|
round(config.cornerRadius.topRight - cast(float, config.top.width)),
|
||||||
|
config.cornerRadius.topRight,
|
||||||
|
270,
|
||||||
|
360,
|
||||||
|
10,
|
||||||
|
to_raylib_color(config.top.color),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if config.cornerRadius.bottomLeft > 0 {
|
||||||
|
Raylib.DrawRing(
|
||||||
|
.{
|
||||||
|
round(bounding_box.x + config.cornerRadius.bottomLeft),
|
||||||
|
round(bounding_box.y + bounding_box.height - config.cornerRadius.bottomLeft),
|
||||||
|
},
|
||||||
|
round(config.cornerRadius.bottomLeft - cast(float, config.bottom.width)),
|
||||||
|
config.cornerRadius.bottomLeft,
|
||||||
|
90,
|
||||||
|
180,
|
||||||
|
10,
|
||||||
|
to_raylib_color(config.bottom.color),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if config.cornerRadius.bottomRight > 0 {
|
||||||
|
Raylib.DrawRing(
|
||||||
|
.{
|
||||||
|
round(bounding_box.x + bounding_box.width - config.cornerRadius.bottomRight),
|
||||||
|
round(bounding_box.y + bounding_box.height - config.cornerRadius.bottomRight),
|
||||||
|
},
|
||||||
|
round(config.cornerRadius.bottomRight - cast(float, config.bottom.width)),
|
||||||
|
config.cornerRadius.bottomRight,
|
||||||
|
0.1,
|
||||||
|
90,
|
||||||
|
10,
|
||||||
|
to_raylib_color(config.bottom.color),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
case .CUSTOM;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#scope_file
|
||||||
|
|
||||||
|
round :: (x: float) -> float {
|
||||||
|
rounded_int := cast(int, x + 0.5 * ifx x < 0 then -1 else 1);
|
||||||
|
return cast(float, rounded_int);
|
||||||
|
}
|
||||||
|
|
||||||
|
c_max :: (a: $T, b: T) -> T #c_call {
|
||||||
|
if b < a return a;
|
||||||
|
return b;
|
||||||
|
}
|
293
bindings/jai/examples/introducing_clay_video_demo/main.jai
Normal file
293
bindings/jai/examples/introducing_clay_video_demo/main.jai
Normal file
@ -0,0 +1,293 @@
|
|||||||
|
using Basic :: #import "Basic";
|
||||||
|
|
||||||
|
Clay :: #import,file "../../clay-jai/module.jai";
|
||||||
|
Raylib :: #import "raylib-jai";
|
||||||
|
|
||||||
|
for_expansion :: Clay.for_expansion;;
|
||||||
|
|
||||||
|
#load "clay_renderer_raylib.jai";
|
||||||
|
|
||||||
|
FONT_ID_BODY_16 :: 0;
|
||||||
|
COLOR_WHITE :: Clay.Color.{255, 255, 255, 255};
|
||||||
|
|
||||||
|
window_width: s32 = 1024;
|
||||||
|
window_height: s32 = 768;
|
||||||
|
|
||||||
|
Document :: struct {
|
||||||
|
title: string;
|
||||||
|
contents: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
documents :: Document.[
|
||||||
|
.{"Squirrels", "The Secret Life of Squirrels: Nature's Clever Acrobats\nSquirrels are often overlooked creatures, dismissed as mere park inhabitants or backyard nuisances. Yet, beneath their fluffy tails and twitching noses lies an intricate world of cunning, agility, and survival tactics that are nothing short of fascinating. As one of the most common mammals in North America, squirrels have adapted to a wide range of environments from bustling urban centers to tranquil forests and have developed a variety of unique behaviors that continue to intrigue scientists and nature enthusiasts alike.\n\nMaster Tree Climbers\nAt the heart of a squirrel's skill set is its impressive ability to navigate trees with ease. Whether they're darting from branch to branch or leaping across wide gaps, squirrels possess an innate talent for acrobatics. Their powerful hind legs, which are longer than their front legs, give them remarkable jumping power. With a tail that acts as a counterbalance, squirrels can leap distances of up to ten times the length of their body, making them some of the best aerial acrobats in the animal kingdom.\nBut it's not just their agility that makes them exceptional climbers. Squirrels' sharp, curved claws allow them to grip tree bark with precision, while the soft pads on their feet provide traction on slippery surfaces. Their ability to run at high speeds and scale vertical trunks with ease is a testament to the evolutionary adaptations that have made them so successful in their arboreal habitats.\n\nFood Hoarders Extraordinaire\nSquirrels are often seen frantically gathering nuts, seeds, and even fungi in preparation for winter. While this behavior may seem like instinctual hoarding, it is actually a survival strategy that has been honed over millions of years. Known as \"scatter hoarding,\" squirrels store their food in a variety of hidden locations, often burying it deep in the soil or stashing it in hollowed-out tree trunks.\nInterestingly, squirrels have an incredible memory for the locations of their caches. Research has shown that they can remember thousands of hiding spots, often returning to them months later when food is scarce. However, they don't always recover every stash some forgotten caches eventually sprout into new trees, contributing to forest regeneration. This unintentional role as forest gardeners highlights the ecological importance of squirrels in their ecosystems.\n\nThe Great Squirrel Debate: Urban vs. Wild\nWhile squirrels are most commonly associated with rural or wooded areas, their adaptability has allowed them to thrive in urban environments as well. In cities, squirrels have become adept at finding food sources in places like parks, streets, and even garbage cans. However, their urban counterparts face unique challenges, including traffic, predators, and the lack of natural shelters. Despite these obstacles, squirrels in urban areas are often observed using human infrastructure such as buildings, bridges, and power lines as highways for their acrobatic escapades.\nThere is, however, a growing concern regarding the impact of urban life on squirrel populations. Pollution, deforestation, and the loss of natural habitats are making it more difficult for squirrels to find adequate food and shelter. As a result, conservationists are focusing on creating squirrel-friendly spaces within cities, with the goal of ensuring these resourceful creatures continue to thrive in both rural and urban landscapes.\n\nA Symbol of Resilience\nIn many cultures, squirrels are symbols of resourcefulness, adaptability, and preparation. Their ability to thrive in a variety of environments while navigating challenges with agility and grace serves as a reminder of the resilience inherent in nature. Whether you encounter them in a quiet forest, a city park, or your own backyard, squirrels are creatures that never fail to amaze with their endless energy and ingenuity.\nIn the end, squirrels may be small, but they are mighty in their ability to survive and thrive in a world that is constantly changing. So next time you spot one hopping across a branch or darting across your lawn, take a moment to appreciate the remarkable acrobat at work a true marvel of the natural world."},
|
||||||
|
.{"Lorem Ipsum", "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."},
|
||||||
|
.{"Vacuum Instructions", "Chapter 3: Getting Started - Unpacking and Setup\n\nCongratulations on your new SuperClean Pro 5000 vacuum cleaner! In this section, we will guide you through the simple steps to get your vacuum up and running. Before you begin, please ensure that you have all the components listed in the \"Package Contents\" section on page 2.\n\n1. Unboxing Your Vacuum\nCarefully remove the vacuum cleaner from the box. Avoid using sharp objects that could damage the product. Once removed, place the unit on a flat, stable surface to proceed with the setup. Inside the box, you should find:\n\n The main vacuum unit\n A telescoping extension wand\n A set of specialized cleaning tools (crevice tool, upholstery brush, etc.)\n A reusable dust bag (if applicable)\n A power cord with a 3-prong plug\n A set of quick-start instructions\n\n2. Assembling Your Vacuum\nBegin by attaching the extension wand to the main body of the vacuum cleaner. Line up the connectors and twist the wand into place until you hear a click. Next, select the desired cleaning tool and firmly attach it to the wand's end, ensuring it is securely locked in.\n\nFor models that require a dust bag, slide the bag into the compartment at the back of the vacuum, making sure it is properly aligned with the internal mechanism. If your vacuum uses a bagless system, ensure the dust container is correctly seated and locked in place before use.\n\n3. Powering On\nTo start the vacuum, plug the power cord into a grounded electrical outlet. Once plugged in, locate the power switch, usually positioned on the side of the handle or body of the unit, depending on your model. Press the switch to the \"On\" position, and you should hear the motor begin to hum. If the vacuum does not power on, check that the power cord is securely plugged in, and ensure there are no blockages in the power switch.\n\nNote: Before first use, ensure that the vacuum filter (if your model has one) is properly installed. If unsure, refer to \"Section 5: Maintenance\" for filter installation instructions."},
|
||||||
|
.{"Article 4", "Article 4"},
|
||||||
|
.{"Article 5", "Article 5"},
|
||||||
|
];
|
||||||
|
|
||||||
|
to_jai_string :: (str: Clay.String) -> string {
|
||||||
|
return .{data = str.chars, count = cast(s64, str.length)};
|
||||||
|
}
|
||||||
|
|
||||||
|
handle_clay_errors :: (error_data: Clay.ErrorData) #c_call {
|
||||||
|
push_context {
|
||||||
|
log_error(
|
||||||
|
"Clay Error [%]: % | %",
|
||||||
|
error_data.errorType,
|
||||||
|
to_jai_string(error_data.errorText),
|
||||||
|
error_data.userData
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
render_header_button :: (text: string) {
|
||||||
|
for Clay.Element(
|
||||||
|
Clay.Layout(.{padding = .{16, 8}}),
|
||||||
|
Clay.Rectangle(.{
|
||||||
|
color = .{140, 140, 140, 255},
|
||||||
|
cornerRadius = .{5, 5, 5, 5},
|
||||||
|
})
|
||||||
|
) {
|
||||||
|
Clay.Text(text, Clay.TextConfig(.{
|
||||||
|
fontId = FONT_ID_BODY_16,
|
||||||
|
fontSize = 16,
|
||||||
|
textColor = COLOR_WHITE,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
render_dropdown_menu_item :: (text: string) {
|
||||||
|
for Clay.Element(
|
||||||
|
Clay.Layout(.{padding = .{16, 16}})
|
||||||
|
) {
|
||||||
|
Clay.Text(text, Clay.TextConfig(.{
|
||||||
|
fontId = FONT_ID_BODY_16,
|
||||||
|
fontSize = 16,
|
||||||
|
textColor = COLOR_WHITE,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
selected_document_index : int = 0;
|
||||||
|
|
||||||
|
main :: () {
|
||||||
|
flags := Raylib.ConfigFlags.WINDOW_RESIZABLE | .MSAA_4X_HINT | .VSYNC_HINT;
|
||||||
|
raylib_initialize(1024, 768, "Introducing Clay Demo", flags);
|
||||||
|
|
||||||
|
// For some reason, on linux, this is 8 bytes off ???
|
||||||
|
clay_required_memory := Clay.MinMemorySize() + 8;
|
||||||
|
memory := alloc(clay_required_memory);
|
||||||
|
clay_memory := Clay.CreateArenaWithCapacityAndMemory(clay_required_memory, memory);
|
||||||
|
Clay.Initialize(
|
||||||
|
clay_memory,
|
||||||
|
Clay.Dimensions.{cast(float, Raylib.GetScreenWidth()), cast(float, Raylib.GetScreenHeight())},
|
||||||
|
.{handle_clay_errors, 0}
|
||||||
|
);
|
||||||
|
|
||||||
|
Clay.SetMeasureTextFunction(raylib_measure_text);
|
||||||
|
g_raylib_fonts[FONT_ID_BODY_16] = .{
|
||||||
|
FONT_ID_BODY_16,
|
||||||
|
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();
|
||||||
|
for Clay.Element(
|
||||||
|
Clay.ID("OuterContainer"),
|
||||||
|
Clay.Rectangle(.{color = .{43, 41, 51, 255}}),
|
||||||
|
Clay.Layout(.{
|
||||||
|
layoutDirection = .TOP_TO_BOTTOM,
|
||||||
|
sizing = layout_expand,
|
||||||
|
padding = .{16, 16},
|
||||||
|
childGap = 16,
|
||||||
|
}),
|
||||||
|
) {
|
||||||
|
for Clay.Element(
|
||||||
|
Clay.ID("HeaderBar"),
|
||||||
|
Clay.Rectangle(content_background_config),
|
||||||
|
Clay.Layout(.{
|
||||||
|
sizing = .{
|
||||||
|
height = Clay.SizingFixed(60),
|
||||||
|
width = Clay.SizingGrow(),
|
||||||
|
},
|
||||||
|
padding = .{16, 16},
|
||||||
|
childGap = 16,
|
||||||
|
childAlignment = .{
|
||||||
|
y = .CENTER,
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
) {
|
||||||
|
for Clay.Element(
|
||||||
|
Clay.ID("FileButton"),
|
||||||
|
Clay.Layout(.{padding = .{16, 8}}),
|
||||||
|
Clay.Rectangle(.{
|
||||||
|
color = .{140, 140, 140, 255},
|
||||||
|
cornerRadius = .{5, 5, 5, 5},
|
||||||
|
}),
|
||||||
|
) {
|
||||||
|
Clay.Text("File", Clay.TextConfig(.{
|
||||||
|
fontId = FONT_ID_BODY_16,
|
||||||
|
fontSize = 16,
|
||||||
|
textColor = COLOR_WHITE,
|
||||||
|
}));
|
||||||
|
|
||||||
|
file_menu_visible := Clay.PointerOver(Clay.GetElementId("FileButton")) ||
|
||||||
|
Clay.PointerOver(Clay.GetElementId("FileMenu"));
|
||||||
|
|
||||||
|
if file_menu_visible {
|
||||||
|
for Clay.Element(
|
||||||
|
Clay.ID("FileMenu"),
|
||||||
|
Clay.Floating(.{attachment = .{parent = .LEFT_BOTTOM}}),
|
||||||
|
Clay.Layout(.{padding = .{0, 8}})
|
||||||
|
) {
|
||||||
|
for Clay.Element(
|
||||||
|
Clay.Layout(.{
|
||||||
|
layoutDirection=.TOP_TO_BOTTOM,
|
||||||
|
sizing = .{width = Clay.SizingFixed(200)}
|
||||||
|
}),
|
||||||
|
Clay.Rectangle(.{
|
||||||
|
color = .{40, 40, 40, 255},
|
||||||
|
cornerRadius = .{8, 8, 8, 8}
|
||||||
|
})
|
||||||
|
) {
|
||||||
|
// Render dropdown items here
|
||||||
|
render_dropdown_menu_item("New");
|
||||||
|
render_dropdown_menu_item("Open");
|
||||||
|
render_dropdown_menu_item("Close");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Render header buttons
|
||||||
|
render_header_button("Edit");
|
||||||
|
for Clay.Element(Clay.Layout(.{
|
||||||
|
sizing = .{Clay.SizingGrow(), Clay.SizingGrow()}})) {}
|
||||||
|
render_header_button("Upload");
|
||||||
|
render_header_button("Media");
|
||||||
|
render_header_button("Support");
|
||||||
|
}
|
||||||
|
|
||||||
|
for Clay.Element(
|
||||||
|
Clay.ID("LowerContent"),
|
||||||
|
Clay.Layout(.{sizing = layout_expand, childGap = 16}),
|
||||||
|
) {
|
||||||
|
for Clay.Element(
|
||||||
|
Clay.ID("Sidebar"),
|
||||||
|
Clay.Rectangle(content_background_config),
|
||||||
|
Clay.Layout(.{
|
||||||
|
layoutDirection = .TOP_TO_BOTTOM,
|
||||||
|
padding = .{16, 16},
|
||||||
|
childGap = 8,
|
||||||
|
sizing = .{
|
||||||
|
width = Clay.SizingFixed(250),
|
||||||
|
height = Clay.SizingGrow(),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
) {
|
||||||
|
for document : documents {
|
||||||
|
sidebar_button_layout := Clay.LayoutConfig.{
|
||||||
|
sizing = .{width = Clay.SizingGrow()},
|
||||||
|
padding = .{16, 16},
|
||||||
|
};
|
||||||
|
|
||||||
|
if it_index == selected_document_index {
|
||||||
|
for Clay.Element(
|
||||||
|
Clay.Layout(sidebar_button_layout),
|
||||||
|
Clay.Rectangle(.{
|
||||||
|
color = .{120, 120, 120, 255},
|
||||||
|
cornerRadius = .{8, 8, 8, 8},
|
||||||
|
})
|
||||||
|
) {
|
||||||
|
Clay.Text(document.title, Clay.TextConfig(.{
|
||||||
|
fontId = FONT_ID_BODY_16,
|
||||||
|
fontSize = 20,
|
||||||
|
textColor = COLOR_WHITE,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
id := tprint("Parnets %", it_index);
|
||||||
|
is_hovered := Clay.PointerOver(Clay.GetElementId(id));
|
||||||
|
if is_hovered && Raylib.IsMouseButtonPressed(0) {
|
||||||
|
selected_document_index = it_index;
|
||||||
|
}
|
||||||
|
|
||||||
|
for Clay.Element(
|
||||||
|
Clay.ID(id)
|
||||||
|
) {
|
||||||
|
for Clay.Element(
|
||||||
|
Clay.Layout(sidebar_button_layout),
|
||||||
|
ifx is_hovered then Clay.Rectangle(.{
|
||||||
|
color = .{120, 120, 120, 120},
|
||||||
|
cornerRadius = .{8, 8, 8, 8},
|
||||||
|
}) else .{}
|
||||||
|
) {
|
||||||
|
Clay.Text(document.title, Clay.TextConfig(.{
|
||||||
|
fontId = FONT_ID_BODY_16,
|
||||||
|
fontSize = 20,
|
||||||
|
textColor = COLOR_WHITE
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for Clay.Element(
|
||||||
|
Clay.ID("MainContent"),
|
||||||
|
Clay.Rectangle(content_background_config),
|
||||||
|
Clay.Scroll(.{vertical = true}),
|
||||||
|
Clay.Layout(.{
|
||||||
|
layoutDirection = .TOP_TO_BOTTOM,
|
||||||
|
childGap = 16,
|
||||||
|
padding = .{16, 16},
|
||||||
|
sizing = layout_expand,
|
||||||
|
}),
|
||||||
|
) {
|
||||||
|
selected_document := documents[selected_document_index];
|
||||||
|
Clay.Text(selected_document.title, Clay.TextConfig(.{
|
||||||
|
fontId = FONT_ID_BODY_16,
|
||||||
|
fontSize = 24,
|
||||||
|
textColor = COLOR_WHITE,
|
||||||
|
}));
|
||||||
|
Clay.Text(selected_document.contents, Clay.TextConfig(.{
|
||||||
|
fontId = FONT_ID_BODY_16,
|
||||||
|
fontSize = 24,
|
||||||
|
textColor = COLOR_WHITE
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
render_commands := Clay.EndLayout();
|
||||||
|
|
||||||
|
Raylib.BeginDrawing();
|
||||||
|
Raylib.ClearBackground(Raylib.BLACK);
|
||||||
|
clay_raylib_render(render_commands);
|
||||||
|
Raylib.EndDrawing();
|
||||||
|
|
||||||
|
reset_temporary_storage();
|
||||||
|
}
|
||||||
|
}
|
4
bindings/jai/examples/introducing_clay_video_demo/modules/raylib-jai/.gitignore
vendored
Normal file
4
bindings/jai/examples/introducing_clay_video_demo/modules/raylib-jai/.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
.build
|
||||||
|
.vscode
|
||||||
|
raylib/
|
||||||
|
.DS_Store
|
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@ -0,0 +1,148 @@
|
|||||||
|
|
||||||
|
Vector2 :: Math.Vector2;
|
||||||
|
Vector3 :: Math.Vector3;
|
||||||
|
Vector4 :: Math.Vector4;
|
||||||
|
Quaternion :: Math.Quaternion;
|
||||||
|
Matrix :: Math.Matrix4;
|
||||||
|
PI :: Math.PI;
|
||||||
|
|
||||||
|
LIGHTGRAY :: Color.{ 200, 200, 200, 255 };
|
||||||
|
GRAY :: Color.{ 130, 130, 130, 255 };
|
||||||
|
DARKGRAY :: Color.{ 80, 80, 80, 255 };
|
||||||
|
YELLOW :: Color.{ 253, 249, 0, 255 };
|
||||||
|
GOLD :: Color.{ 255, 203, 0, 255 };
|
||||||
|
ORANGE :: Color.{ 255, 161, 0, 255 };
|
||||||
|
PINK :: Color.{ 255, 109, 194, 255 };
|
||||||
|
RED :: Color.{ 230, 41, 55, 255 };
|
||||||
|
MAROON :: Color.{ 190, 33, 55, 255 };
|
||||||
|
GREEN :: Color.{ 0, 228, 48, 255 };
|
||||||
|
LIME :: Color.{ 0, 158, 47, 255 };
|
||||||
|
DARKGREEN :: Color.{ 0, 117, 44, 255 };
|
||||||
|
SKYBLUE :: Color.{ 102, 191, 255, 255 };
|
||||||
|
BLUE :: Color.{ 0, 121, 241, 255 };
|
||||||
|
DARKBLUE :: Color.{ 0, 82, 172, 255 };
|
||||||
|
PURPLE :: Color.{ 200, 122, 255, 255 };
|
||||||
|
VIOLET :: Color.{ 135, 60, 190, 255 };
|
||||||
|
DARKPURPLE :: Color.{ 112, 31, 126, 255 };
|
||||||
|
BEIGE :: Color.{ 211, 176, 131, 255 };
|
||||||
|
BROWN :: Color.{ 127, 106, 79, 255 };
|
||||||
|
DARKBROWN :: Color.{ 76, 63, 47, 255 };
|
||||||
|
WHITE :: Color.{ 255, 255, 255, 255 };
|
||||||
|
BLACK :: Color.{ 0, 0, 0, 255 };
|
||||||
|
BLANK :: Color.{ 0, 0, 0, 0 };
|
||||||
|
MAGENTA :: Color.{ 255, 0, 255, 255 };
|
||||||
|
RAYWHITE :: Color.{ 245, 245, 245, 255 };
|
||||||
|
|
||||||
|
GetGamepadButtonPressed :: () -> GamepadButton #foreign raylib;
|
||||||
|
|
||||||
|
IsMouseButtonPressed :: (button: MouseButton) -> bool { return IsMouseButtonPressed(cast(s32) button); }
|
||||||
|
IsMouseButtonDown :: (button: MouseButton) -> bool { return IsMouseButtonDown(cast(s32) button); }
|
||||||
|
IsMouseButtonReleased :: (button: MouseButton) -> bool { return IsMouseButtonReleased(cast(s32) button); }
|
||||||
|
IsMouseButtonUp :: (button: MouseButton) -> bool { return IsMouseButtonUp(cast(s32) button); }
|
||||||
|
|
||||||
|
IsKeyPressed :: (key: KeyboardKey) -> bool { return IsKeyPressed(cast(s32) key); }
|
||||||
|
IsKeyPressedRepeat :: (key: KeyboardKey) -> bool { return IsKeyPressedRepeat(cast(s32) key); }
|
||||||
|
IsKeyDown :: (key: KeyboardKey) -> bool { return IsKeyDown(cast(s32) key); }
|
||||||
|
IsKeyReleased :: (key: KeyboardKey) -> bool { return IsKeyReleased(cast(s32) key); }
|
||||||
|
IsKeyUp :: (key: KeyboardKey) -> bool { return IsKeyUp(cast(s32) key); }
|
||||||
|
SetExitKey :: (key: KeyboardKey) -> void { return SetExitKey(cast(s32) key); }
|
||||||
|
|
||||||
|
SetConfigFlags :: (flags: ConfigFlags) -> void { return SetConfigFlags(cast(u32) flags); }
|
||||||
|
|
||||||
|
SetGesturesEnabled :: (flags: Gesture) -> void { return SetGesturesEnabled(cast(u32) flags); }
|
||||||
|
IsGestureDetected :: (gesture: Gesture) -> bool { return IsGestureDetected(cast(u32) gesture); }
|
||||||
|
|
||||||
|
IsWindowState :: (flag: ConfigFlags) -> bool { return IsWindowState(cast(u32) flag); }
|
||||||
|
SetWindowState :: (flags: ConfigFlags) -> void { return SetWindowState(cast(u32) flags); }
|
||||||
|
ClearWindowState :: (flags: ConfigFlags) -> void { return ClearWindowState(cast(u32) flags); }
|
||||||
|
|
||||||
|
UpdateCamera :: (camera: *Camera, mode: CameraMode) -> void { return UpdateCamera(camera, cast(s32) mode); }
|
||||||
|
|
||||||
|
SetTraceLogLevel :: (logLevel: TraceLogLevel) -> void { return SetTraceLogLevel(cast(s32) logLevel); }
|
||||||
|
TraceLog :: (logLevel: TraceLogLevel, text: string, __args: ..Any) { TraceLog(cast(s32) logLevel, text, __args); }
|
||||||
|
|
||||||
|
SetShaderValue :: (shader: Shader, locIndex: s32, value: *void, uniformType: ShaderUniformDataType) -> void {
|
||||||
|
return SetShaderValue(shader, locIndex, value, cast(s32) uniformType);
|
||||||
|
}
|
||||||
|
SetShaderValueV :: (shader: Shader, locIndex: s32, value: *void, uniformType: ShaderUniformDataType, count: s32) -> void {
|
||||||
|
return SetShaderValue(shader, locIndex, value, cast(s32) uniformType, count);
|
||||||
|
}
|
||||||
|
|
||||||
|
IsGamepadButtonPressed :: (gamepad: s32, button: GamepadButton) -> bool { return IsGamepadButtonPressed(gamepad, cast(s32) button); }
|
||||||
|
IsGamepadButtonDown :: (gamepad: s32, button: GamepadButton) -> bool { return IsGamepadButtonDown(gamepad, cast(s32) button); }
|
||||||
|
IsGamepadButtonReleased :: (gamepad: s32, button: GamepadButton) -> bool { return IsGamepadButtonReleased(gamepad, cast(s32) button); }
|
||||||
|
IsGamepadButtonUp :: (gamepad: s32, button: GamepadButton) -> bool { return IsGamepadButtonUp(gamepad, cast(s32) button); }
|
||||||
|
|
||||||
|
GetGamepadAxisMovement :: (gamepad: s32, axis: GamepadAxis) -> float { return GetGamepadAxisMovement(gamepad, cast(s32) axis); }
|
||||||
|
|
||||||
|
SetTextureFilter :: (texture: Texture2D, filter: TextureFilter) -> void { return SetTextureFilter(texture, cast(s32) filter); }
|
||||||
|
SetTextureWrap :: (texture: Texture2D, wrap: TextureWrap) -> void { return SetTextureWrap(textuer, cast(s32) wrap); }
|
||||||
|
|
||||||
|
BeginBlendMode :: (mode: BlendMode) -> void { return BeginBlendMode(cast(s32) mode); }
|
||||||
|
|
||||||
|
ImageFormat :: (image: *Image, newFormat: PixelFormat) -> void { return ImageFormat(image, cast(s32) newFormat); }
|
||||||
|
|
||||||
|
LoadImageRaw :: (fileName: *u8, width: s32, height: s32, format: PixelFormat, headerSize: s32) -> Image {
|
||||||
|
return LoadImageRaw(fileName, width, height, cast(s32) format, headerSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
LoadFontData :: (fileData: *u8, dataSize: s32, fontSize: s32, codepoints: *s32, codepointCount: s32, type: FontType) -> *GlyphInfo {
|
||||||
|
return LoadFontData(fileData, dataSize, fontSize, codepoints, codepointCount, cast(s32) type);
|
||||||
|
}
|
||||||
|
|
||||||
|
SetMouseCursor :: (cursor: MouseCursor) -> void { return SetMouseCursor(cast(s32) cursor); }
|
||||||
|
|
||||||
|
LoadTexture :: (data: *void, width: s32, height: s32, format: PixelFormat, mipmapCount: s32) -> u32 {
|
||||||
|
return LoadTexture(data, width, height, cast(s32) format, mipmapCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
FramebufferAttach :: (fboId: u32, texId: u32, attachType: FramebufferAttachType, texType: FramebufferAttachTextureType, mipLevel: s32) -> void {
|
||||||
|
return FramebufferAttach(fbiId, texId, cast(s32) attachType, cast(s32) texType, mipLevel);
|
||||||
|
}
|
||||||
|
|
||||||
|
SetUniform :: (locIndex: s32, value: *void, uniformType: ShaderUniformDataType, count: s32) -> void { return SetUniform(locIndex, value, cast(s32) uniformType, count); }
|
||||||
|
|
||||||
|
SetMaterialTexture :: (material: *Material, mapType: MaterialMapIndex, texture: Texture2D) -> void { return SetMaterialTexture(material, mapType, texture); }
|
||||||
|
|
||||||
|
Camera3D :: struct {
|
||||||
|
position: Vector3; // Camera position
|
||||||
|
target: Vector3; // Camera target it looks-at
|
||||||
|
up: Vector3; // Camera up vector (rotation over its axis)
|
||||||
|
fovy: float; // Camera field-of-view aperture in Y (degrees) in perspective, used as near plane width in orthographic
|
||||||
|
projection: CameraProjection; // Camera projection: CAMERA_PERSPECTIVE or CAMERA_ORTHOGRAPHIC
|
||||||
|
}
|
||||||
|
|
||||||
|
TraceLogCallback :: #type (logLevel: TraceLogLevel, text: *u8, args: .. Any) #c_call;
|
||||||
|
|
||||||
|
#scope_module
|
||||||
|
|
||||||
|
#if OS == .WINDOWS {
|
||||||
|
user32 :: #system_library,link_always "user32";
|
||||||
|
gdi32 :: #system_library,link_always "gdi32";
|
||||||
|
shell32 :: #system_library,link_always "shell32";
|
||||||
|
winmm :: #system_library,link_always "winmm";
|
||||||
|
|
||||||
|
raylib :: #library,no_dll "windows/raylib";
|
||||||
|
|
||||||
|
#load "windows.jai";
|
||||||
|
} else #if OS == .LINUX {
|
||||||
|
math :: #system_library,link_always "m";
|
||||||
|
raylib :: #library,no_dll "linux/raylib";
|
||||||
|
|
||||||
|
#load "linux.jai";
|
||||||
|
} else #if OS == .MACOS {
|
||||||
|
#system_library,link_always "Cocoa";
|
||||||
|
#system_library,link_always "OpenGL";
|
||||||
|
#system_library,link_always "CoreGraphics";
|
||||||
|
#system_library,link_always "AppKit";
|
||||||
|
#system_library,link_always "IOKit";
|
||||||
|
|
||||||
|
raylib :: #library,no_dll "macos/raylib";
|
||||||
|
|
||||||
|
#load "macos.jai";
|
||||||
|
} else {
|
||||||
|
assert(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
#import "Basic";
|
||||||
|
Math :: #import "Math";
|
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
10
examples/sokol-corner-radius/CMakeLists.txt
Normal file
10
examples/sokol-corner-radius/CMakeLists.txt
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.27)
|
||||||
|
project(sokol_corner_radius C)
|
||||||
|
|
||||||
|
if(CMAKE_SYSTEM_NAME STREQUAL Windows)
|
||||||
|
add_executable(sokol_corner_radius WIN32 main.c)
|
||||||
|
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT sokol_corner_radius)
|
||||||
|
else()
|
||||||
|
add_executable(sokol_corner_radius main.c)
|
||||||
|
endif()
|
||||||
|
target_link_libraries(sokol_corner_radius PUBLIC sokol)
|
110
examples/sokol-corner-radius/main.c
Normal file
110
examples/sokol-corner-radius/main.c
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
#include "sokol_app.h"
|
||||||
|
#include "sokol_gfx.h"
|
||||||
|
#include "sokol_glue.h"
|
||||||
|
#include "sokol_log.h"
|
||||||
|
|
||||||
|
#define CLAY_IMPLEMENTATION
|
||||||
|
#include "../../clay.h"
|
||||||
|
|
||||||
|
#include "util/sokol_gl.h"
|
||||||
|
#include "fontstash.h"
|
||||||
|
#include "util/sokol_fontstash.h"
|
||||||
|
#define SOKOL_CLAY_IMPL
|
||||||
|
#include "../../renderers/sokol/sokol_clay.h"
|
||||||
|
|
||||||
|
static void init() {
|
||||||
|
sg_setup(&(sg_desc){
|
||||||
|
.environment = sglue_environment(),
|
||||||
|
.logger.func = slog_func,
|
||||||
|
});
|
||||||
|
sgl_setup(&(sgl_desc_t){
|
||||||
|
.logger.func = slog_func,
|
||||||
|
});
|
||||||
|
sclay_setup();
|
||||||
|
uint64_t totalMemorySize = Clay_MinMemorySize();
|
||||||
|
Clay_Arena clayMemory = Clay_CreateArenaWithCapacityAndMemory(totalMemorySize, malloc(totalMemorySize));
|
||||||
|
Clay_Initialize(clayMemory, (Clay_Dimensions){ (float)sapp_width(), (float)sapp_height() }, (Clay_ErrorHandler){0});
|
||||||
|
Clay_SetMeasureTextFunction(sclay_measure_text, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
Clay_RenderCommandArray CornerRadiusTest(){
|
||||||
|
Clay_BeginLayout();
|
||||||
|
Clay_Sizing layoutExpand = {
|
||||||
|
.width = CLAY_SIZING_GROW(0),
|
||||||
|
.height = CLAY_SIZING_GROW(0)
|
||||||
|
};
|
||||||
|
CLAY({ .id = CLAY_ID("OuterContainer"),
|
||||||
|
.backgroundColor = {43, 41, 51, 255},
|
||||||
|
.layout = {
|
||||||
|
.layoutDirection = CLAY_TOP_TO_BOTTOM,
|
||||||
|
.sizing = layoutExpand,
|
||||||
|
.padding = {0, 0, 20, 20},
|
||||||
|
.childGap = 20
|
||||||
|
}
|
||||||
|
}) {
|
||||||
|
for(int i = 0; i < 6; ++i){
|
||||||
|
CLAY({ .id = CLAY_IDI("Row", i),
|
||||||
|
.layout = {
|
||||||
|
.layoutDirection = CLAY_LEFT_TO_RIGHT,
|
||||||
|
.sizing = layoutExpand,
|
||||||
|
.padding = {20, 20, 0, 0},
|
||||||
|
.childGap = 20
|
||||||
|
}
|
||||||
|
}) {
|
||||||
|
for(int j = 0; j < 6; ++j){
|
||||||
|
CLAY({ .id = CLAY_IDI("Tile", i*6+j),
|
||||||
|
.backgroundColor = {120, 140, 255, 128},
|
||||||
|
.cornerRadius = {(i%3)*15, (j%3)*15, (i/2)*15, (j/2)*15},
|
||||||
|
.border = {
|
||||||
|
.color = {120, 140, 255, 255},
|
||||||
|
.width = {3, 9, 6, 12, 0},
|
||||||
|
},
|
||||||
|
.layout = { .sizing = layoutExpand }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Clay_EndLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void frame() {
|
||||||
|
sclay_new_frame();
|
||||||
|
Clay_RenderCommandArray renderCommands = CornerRadiusTest();
|
||||||
|
|
||||||
|
sg_begin_pass(&(sg_pass){ .swapchain = sglue_swapchain() });
|
||||||
|
sgl_matrix_mode_modelview();
|
||||||
|
sgl_load_identity();
|
||||||
|
sclay_render(renderCommands, NULL);
|
||||||
|
sgl_draw();
|
||||||
|
sg_end_pass();
|
||||||
|
sg_commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void event(const sapp_event *ev) {
|
||||||
|
if(ev->type == SAPP_EVENTTYPE_KEY_DOWN && ev->key_code == SAPP_KEYCODE_D){
|
||||||
|
Clay_SetDebugModeEnabled(true);
|
||||||
|
} else {
|
||||||
|
sclay_handle_event(ev);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void cleanup() {
|
||||||
|
sclay_shutdown();
|
||||||
|
sgl_shutdown();
|
||||||
|
sg_shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
|
sapp_desc sokol_main(int argc, char **argv) {
|
||||||
|
return (sapp_desc){
|
||||||
|
.init_cb = init,
|
||||||
|
.frame_cb = frame,
|
||||||
|
.event_cb = event,
|
||||||
|
.cleanup_cb = cleanup,
|
||||||
|
.window_title = "Clay - Corner Radius Test",
|
||||||
|
.width = 800,
|
||||||
|
.height = 600,
|
||||||
|
.icon.sokol_default = true,
|
||||||
|
.logger.func = slog_func,
|
||||||
|
};
|
||||||
|
}
|
71
examples/sokol-video-demo/CMakeLists.txt
Normal file
71
examples/sokol-video-demo/CMakeLists.txt
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.27)
|
||||||
|
project(sokol_video_demo C)
|
||||||
|
|
||||||
|
include(FetchContent)
|
||||||
|
set(FETCHCONTENT_QUIET FALSE)
|
||||||
|
|
||||||
|
# Linux -pthread shenanigans
|
||||||
|
if (CMAKE_SYSTEM_NAME STREQUAL Linux)
|
||||||
|
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
||||||
|
find_package(Threads REQUIRED)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
FetchContent_Declare(
|
||||||
|
fontstash
|
||||||
|
GIT_REPOSITORY "https://github.com/memononen/fontstash.git"
|
||||||
|
GIT_TAG "b5ddc9741061343740d85d636d782ed3e07cf7be"
|
||||||
|
GIT_PROGRESS TRUE
|
||||||
|
GIT_SHALLOW TRUE
|
||||||
|
)
|
||||||
|
FetchContent_MakeAvailable(fontstash)
|
||||||
|
|
||||||
|
FetchContent_Declare(
|
||||||
|
sokol
|
||||||
|
GIT_REPOSITORY "https://github.com/floooh/sokol.git"
|
||||||
|
GIT_TAG "da9de496f938b7575eff7f01ab774d77469bd390"
|
||||||
|
GIT_PROGRESS TRUE
|
||||||
|
GIT_SHALLOW TRUE
|
||||||
|
)
|
||||||
|
FetchContent_MakeAvailable(sokol)
|
||||||
|
set(sokol_HEADERS
|
||||||
|
${sokol_SOURCE_DIR}/sokol_app.h
|
||||||
|
${sokol_SOURCE_DIR}/sokol_gfx.h
|
||||||
|
${sokol_SOURCE_DIR}/sokol_glue.h
|
||||||
|
${sokol_SOURCE_DIR}/sokol_log.h
|
||||||
|
${sokol_SOURCE_DIR}/util/sokol_gl.h
|
||||||
|
${fontstash_SOURCE_DIR}/src/fontstash.h
|
||||||
|
${sokol_SOURCE_DIR}/util/sokol_fontstash.h)
|
||||||
|
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
|
||||||
|
add_library(sokol STATIC sokol.c ${sokol_HEADERS})
|
||||||
|
target_compile_options(sokol PRIVATE -x objective-c)
|
||||||
|
target_link_libraries(sokol PUBLIC
|
||||||
|
"-framework QuartzCore"
|
||||||
|
"-framework Cocoa"
|
||||||
|
"-framework MetalKit"
|
||||||
|
"-framework Metal")
|
||||||
|
else()
|
||||||
|
add_library(sokol STATIC sokol.c ${sokol_HEADERS})
|
||||||
|
if (CMAKE_SYSTEM_NAME STREQUAL Linux)
|
||||||
|
target_compile_definitions(sokol PRIVATE SOKOL_GLCORE=1)
|
||||||
|
target_link_libraries(sokol INTERFACE X11 Xi Xcursor GL dl m)
|
||||||
|
target_link_libraries(sokol PUBLIC Threads::Threads)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
target_include_directories(sokol INTERFACE ${sokol_SOURCE_DIR} ${fontstash_SOURCE_DIR}/src
|
||||||
|
PRIVATE ${sokol_SOURCE_DIR} ${fontstash_SOURCE_DIR}/src)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if(CMAKE_SYSTEM_NAME STREQUAL Windows)
|
||||||
|
add_executable(sokol_video_demo WIN32 main.c)
|
||||||
|
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT sokol_video_demo)
|
||||||
|
else()
|
||||||
|
add_executable(sokol_video_demo main.c)
|
||||||
|
endif()
|
||||||
|
target_link_libraries(sokol_video_demo PUBLIC sokol)
|
||||||
|
|
||||||
|
add_custom_command(
|
||||||
|
TARGET sokol_video_demo POST_BUILD
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/resources
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/resources)
|
77
examples/sokol-video-demo/main.c
Normal file
77
examples/sokol-video-demo/main.c
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
#include "sokol_app.h"
|
||||||
|
#include "sokol_gfx.h"
|
||||||
|
#include "sokol_glue.h"
|
||||||
|
#include "sokol_log.h"
|
||||||
|
|
||||||
|
#define CLAY_IMPLEMENTATION
|
||||||
|
#include "../../clay.h"
|
||||||
|
|
||||||
|
#include "util/sokol_gl.h"
|
||||||
|
#include "fontstash.h"
|
||||||
|
#include "util/sokol_fontstash.h"
|
||||||
|
#define SOKOL_CLAY_IMPL
|
||||||
|
#include "../../renderers/sokol/sokol_clay.h"
|
||||||
|
|
||||||
|
#include "../shared-layouts/clay-video-demo.c"
|
||||||
|
|
||||||
|
static ClayVideoDemo_Data demoData;
|
||||||
|
static sclay_font_t fonts[1];
|
||||||
|
|
||||||
|
static void init() {
|
||||||
|
sg_setup(&(sg_desc){
|
||||||
|
.environment = sglue_environment(),
|
||||||
|
.logger.func = slog_func,
|
||||||
|
});
|
||||||
|
sgl_setup(&(sgl_desc_t){
|
||||||
|
.logger.func = slog_func,
|
||||||
|
});
|
||||||
|
sclay_setup();
|
||||||
|
uint64_t totalMemorySize = Clay_MinMemorySize();
|
||||||
|
Clay_Arena clayMemory = Clay_CreateArenaWithCapacityAndMemory(totalMemorySize, malloc(totalMemorySize));
|
||||||
|
Clay_Initialize(clayMemory, (Clay_Dimensions){ (float)sapp_width(), (float)sapp_height() }, (Clay_ErrorHandler){0});
|
||||||
|
fonts[FONT_ID_BODY_16] = sclay_add_font("resources/Roboto-Regular.ttf");
|
||||||
|
Clay_SetMeasureTextFunction(sclay_measure_text, &fonts);
|
||||||
|
demoData = ClayVideoDemo_Initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void frame() {
|
||||||
|
sclay_new_frame();
|
||||||
|
Clay_RenderCommandArray renderCommands = ClayVideoDemo_CreateLayout(&demoData);
|
||||||
|
|
||||||
|
sg_begin_pass(&(sg_pass){ .swapchain = sglue_swapchain() });
|
||||||
|
sgl_matrix_mode_modelview();
|
||||||
|
sgl_load_identity();
|
||||||
|
sclay_render(renderCommands, fonts);
|
||||||
|
sgl_draw();
|
||||||
|
sg_end_pass();
|
||||||
|
sg_commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void event(const sapp_event *ev) {
|
||||||
|
if(ev->type == SAPP_EVENTTYPE_KEY_DOWN && ev->key_code == SAPP_KEYCODE_D){
|
||||||
|
Clay_SetDebugModeEnabled(true);
|
||||||
|
} else {
|
||||||
|
sclay_handle_event(ev);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void cleanup() {
|
||||||
|
sclay_shutdown();
|
||||||
|
sgl_shutdown();
|
||||||
|
sg_shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
|
sapp_desc sokol_main(int argc, char **argv) {
|
||||||
|
return (sapp_desc){
|
||||||
|
.init_cb = init,
|
||||||
|
.frame_cb = frame,
|
||||||
|
.event_cb = event,
|
||||||
|
.cleanup_cb = cleanup,
|
||||||
|
.window_title = "Clay - Sokol Renderer Example",
|
||||||
|
.width = 800,
|
||||||
|
.height = 600,
|
||||||
|
.high_dpi = true,
|
||||||
|
.icon.sokol_default = true,
|
||||||
|
.logger.func = slog_func,
|
||||||
|
};
|
||||||
|
}
|
BIN
examples/sokol-video-demo/resources/Roboto-Regular.ttf
Normal file
BIN
examples/sokol-video-demo/resources/Roboto-Regular.ttf
Normal file
Binary file not shown.
24
examples/sokol-video-demo/sokol.c
Normal file
24
examples/sokol-video-demo/sokol.c
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#define SOKOL_IMPL
|
||||||
|
#if defined(_WIN32)
|
||||||
|
#define SOKOL_D3D11
|
||||||
|
#elif defined(__EMSCRIPTEN__)
|
||||||
|
#define SOKOL_GLES2
|
||||||
|
#elif defined(__APPLE__)
|
||||||
|
#define SOKOL_METAL
|
||||||
|
#else
|
||||||
|
#define SOKOL_GLCORE33
|
||||||
|
#endif
|
||||||
|
#include "sokol_app.h"
|
||||||
|
#include "sokol_gfx.h"
|
||||||
|
#include "sokol_time.h"
|
||||||
|
#include "sokol_fetch.h"
|
||||||
|
#include "sokol_glue.h"
|
||||||
|
#include "sokol_log.h"
|
||||||
|
|
||||||
|
#include "util/sokol_gl.h"
|
||||||
|
#include <stdio.h> // fontstash requires this
|
||||||
|
#include <stdlib.h> // fontstash requires this
|
||||||
|
#define FONTSTASH_IMPLEMENTATION
|
||||||
|
#include "fontstash.h"
|
||||||
|
#define SOKOL_FONTSTASH_IMPL
|
||||||
|
#include "util/sokol_fontstash.h"
|
15
examples/win32_gdi/CMakeLists.txt
Normal file
15
examples/win32_gdi/CMakeLists.txt
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.27)
|
||||||
|
project(win32_gdi C)
|
||||||
|
|
||||||
|
set(CMAKE_C_STANDARD 99)
|
||||||
|
|
||||||
|
add_executable(win32_gdi WIN32 main.c)
|
||||||
|
|
||||||
|
target_compile_options(win32_gdi PUBLIC)
|
||||||
|
target_include_directories(win32_gdi PUBLIC .)
|
||||||
|
|
||||||
|
add_custom_command(
|
||||||
|
TARGET win32_gdi POST_BUILD
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/resources
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/resources)
|
@ -25,6 +25,14 @@ void CenterWindow(HWND hWnd);
|
|||||||
|
|
||||||
long lastMsgTime = 0;
|
long lastMsgTime = 0;
|
||||||
bool ui_debug_mode;
|
bool ui_debug_mode;
|
||||||
|
HFONT fonts[1];
|
||||||
|
|
||||||
|
#ifndef RECTWIDTH
|
||||||
|
#define RECTWIDTH(rc) ((rc).right - (rc).left)
|
||||||
|
#endif
|
||||||
|
#ifndef RECTHEIGHT
|
||||||
|
#define RECTHEIGHT(rc) ((rc).bottom - (rc).top)
|
||||||
|
#endif
|
||||||
|
|
||||||
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||||
{
|
{
|
||||||
@ -113,7 +121,7 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|||||||
case WM_PAINT:
|
case WM_PAINT:
|
||||||
{
|
{
|
||||||
Clay_RenderCommandArray renderCommands = ClayVideoDemo_CreateLayout(&demo_data);
|
Clay_RenderCommandArray renderCommands = ClayVideoDemo_CreateLayout(&demo_data);
|
||||||
Clay_Win32_Render(hwnd, renderCommands);
|
Clay_Win32_Render(hwnd, renderCommands, fonts);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,7 +159,12 @@ int APIENTRY WinMain(
|
|||||||
uint64_t clayRequiredMemory = Clay_MinMemorySize();
|
uint64_t clayRequiredMemory = Clay_MinMemorySize();
|
||||||
Clay_Arena clayMemory = Clay_CreateArenaWithCapacityAndMemory(clayRequiredMemory, malloc(clayRequiredMemory));
|
Clay_Arena clayMemory = Clay_CreateArenaWithCapacityAndMemory(clayRequiredMemory, malloc(clayRequiredMemory));
|
||||||
Clay_Initialize(clayMemory, (Clay_Dimensions){.width = 800, .height = 600}, (Clay_ErrorHandler){HandleClayErrors}); // This final argument is new since the video was published
|
Clay_Initialize(clayMemory, (Clay_Dimensions){.width = 800, .height = 600}, (Clay_ErrorHandler){HandleClayErrors}); // This final argument is new since the video was published
|
||||||
Clay_SetMeasureTextFunction(Clay_Win32_MeasureText, NULL);
|
|
||||||
|
Clay_Win32_SetRendererFlags(CLAYGDI_RF_ALPHABLEND | CLAYGDI_RF_SMOOTHCORNERS);
|
||||||
|
|
||||||
|
// Initialize clay fonts and text drawing
|
||||||
|
fonts[FONT_ID_BODY_16] = Clay_Win32_SimpleCreateFont("resources/Roboto-Regular.ttf", "Roboto", -11, FW_NORMAL);
|
||||||
|
Clay_SetMeasureTextFunction(Clay_Win32_MeasureText, fonts);
|
||||||
|
|
||||||
ZeroMemory(&wc, sizeof wc);
|
ZeroMemory(&wc, sizeof wc);
|
||||||
wc.hInstance = hInstance;
|
wc.hInstance = hInstance;
|
||||||
@ -165,6 +178,10 @@ int APIENTRY WinMain(
|
|||||||
if (FALSE == RegisterClass(&wc))
|
if (FALSE == RegisterClass(&wc))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
// Calculate window rectangle by given client size
|
||||||
|
// TODO: AdjustWindowRectExForDpi for DPI support
|
||||||
|
RECT rcWindow = { .right = 800, .bottom = 600 };
|
||||||
|
AdjustWindowRect(&rcWindow, WS_OVERLAPPEDWINDOW, FALSE);
|
||||||
|
|
||||||
hwnd = CreateWindow(
|
hwnd = CreateWindow(
|
||||||
szAppName,
|
szAppName,
|
||||||
@ -172,8 +189,8 @@ int APIENTRY WinMain(
|
|||||||
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
|
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
|
||||||
CW_USEDEFAULT,
|
CW_USEDEFAULT,
|
||||||
CW_USEDEFAULT,
|
CW_USEDEFAULT,
|
||||||
800, // CW_USEDEFAULT,
|
RECTWIDTH(rcWindow), // CW_USEDEFAULT,
|
||||||
600, // CW_USEDEFAULT,
|
RECTHEIGHT(rcWindow), // CW_USEDEFAULT,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
hInstance,
|
hInstance,
|
||||||
|
BIN
examples/win32_gdi/resources/Roboto-Regular.ttf
Normal file
BIN
examples/win32_gdi/resources/Roboto-Regular.ttf
Normal file
Binary file not shown.
450
renderers/sokol/sokol_clay.h
Normal file
450
renderers/sokol/sokol_clay.h
Normal file
@ -0,0 +1,450 @@
|
|||||||
|
#ifndef SOKOL_CLAY_INCLUDED
|
||||||
|
#define SOKOL_CLAY_INCLUDED (1)
|
||||||
|
/*
|
||||||
|
sokol_clay.h -- drop-in Clay renderer for sokol_gfx.h
|
||||||
|
|
||||||
|
Do this:
|
||||||
|
#define SOKOL_CLAY_IMPL
|
||||||
|
|
||||||
|
before you include this file in *one* C file to create the
|
||||||
|
implementation.
|
||||||
|
|
||||||
|
Optionally provide the following configuration define both before including the
|
||||||
|
the declaration and implementation:
|
||||||
|
|
||||||
|
SOKOL_CLAY_NO_SOKOL_APP - don't depend on sokol_app.h (see below for details)
|
||||||
|
|
||||||
|
Include the following headers before sokol_clay.h (both before including
|
||||||
|
the declaration and implementation):
|
||||||
|
|
||||||
|
sokol_gl.h
|
||||||
|
sokol_fontstash.h
|
||||||
|
sokol_app.h (except SOKOL_CLAY_NO_SOKOL_APP)
|
||||||
|
clay.h
|
||||||
|
|
||||||
|
FEATURE OVERVIEW:
|
||||||
|
=================
|
||||||
|
sokol_clay.h implements the rendering and event-handling code for Clay
|
||||||
|
(https://github.com/nicbarker/clay) on top of sokol_gl.h and (optionally)
|
||||||
|
sokol_app.h.
|
||||||
|
|
||||||
|
Since sokol_fontstash.h already depends on sokol_gl.h, the rendering is
|
||||||
|
implemented using sokol_gl calls. (TODO: make fontstash optional?)
|
||||||
|
|
||||||
|
The sokol_app.h dependency is optional and used for input event handling.
|
||||||
|
If you only use sokol_gfx.h but not sokol_app.h in your application,
|
||||||
|
define SOKOL_CLAY_NO_SOKOL_APP before including the implementation
|
||||||
|
of sokol_clay.h, this will remove any dependency to sokol_app.h, but
|
||||||
|
you must call sclay_set_layout_dimensions and handle input yourself.
|
||||||
|
|
||||||
|
sokol_clay.h is not thread-safe, all calls must be made from the
|
||||||
|
same thread where sokol_gfx.h is running.
|
||||||
|
|
||||||
|
HOWTO:
|
||||||
|
======
|
||||||
|
|
||||||
|
--- To initialize sokol-clay, call sclay_setup(). This can be done
|
||||||
|
before or after Clay_Initialize.
|
||||||
|
|
||||||
|
--- Create an array of sclay_font_t and fill it by calling one of:
|
||||||
|
|
||||||
|
sclay_font_t sclay_add_font(const char *filename);
|
||||||
|
sclay_font_t sclay_add_font_mem(unsigned char *data, int dataLen);
|
||||||
|
|
||||||
|
The fontId value in Clay corresponds to indices in this array. After calling
|
||||||
|
Clay_Initialize but before calling any layout code, do this:
|
||||||
|
|
||||||
|
Clay_SetMeasureTextFunction(sclay_measure_text, &fonts);
|
||||||
|
|
||||||
|
where `fonts` is the abovementioned array.
|
||||||
|
|
||||||
|
--- At the start of a frame, call sclay_new_frame() if you're using sokol_app.h.
|
||||||
|
If you're not using sokol_app.h, call:
|
||||||
|
|
||||||
|
void sclay_set_layout_dimensions(Clay_Dimensions size, float dpi_scale);
|
||||||
|
|
||||||
|
at the start of the frame (or just when the window is resized.)
|
||||||
|
|
||||||
|
Either way, do some layout, then at the end of the frame call sclay_render:
|
||||||
|
|
||||||
|
sg_begin_pass(...)
|
||||||
|
// other rendering...
|
||||||
|
sclay_render(renderCommands, &fonts);
|
||||||
|
// other rendering...
|
||||||
|
sgl_draw();
|
||||||
|
sg_end_pass();
|
||||||
|
sg_commit();
|
||||||
|
|
||||||
|
One caveat: sclay_render assumes the default gl view matrix, and handles scaling
|
||||||
|
automatically. If you've adjusted the view matrix, remember to first call:
|
||||||
|
|
||||||
|
sgl_matrix_mode_modelview();
|
||||||
|
sgl_load_identity();
|
||||||
|
|
||||||
|
before calling sclay_render.
|
||||||
|
|
||||||
|
--- if you're using sokol_app.h, from inside the sokol_app.h event callback,
|
||||||
|
call:
|
||||||
|
|
||||||
|
void sclay_handle_event(const sapp_event* ev);
|
||||||
|
|
||||||
|
Unfortunately Clay does not currently provide feedback on whether a mouse
|
||||||
|
click was handled or not.
|
||||||
|
|
||||||
|
--- finally, on application shutdown, call
|
||||||
|
|
||||||
|
sclay_shutdown()
|
||||||
|
*/
|
||||||
|
#if !defined(SOKOL_CLAY_NO_SOKOL_APP) && !defined(SOKOL_APP_INCLUDED)
|
||||||
|
#error "Please include sokol_app.h before sokol_clay.h (or define SOKOL_CLAY_NO_SOKOL_APP)"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef int sclay_font_t;
|
||||||
|
|
||||||
|
void sclay_setup();
|
||||||
|
void sclay_shutdown();
|
||||||
|
|
||||||
|
sclay_font_t sclay_add_font(const char *filename);
|
||||||
|
sclay_font_t sclay_add_font_mem(unsigned char *data, int dataLen);
|
||||||
|
Clay_Dimensions sclay_measure_text(Clay_StringSlice text, Clay_TextElementConfig *config, void *userData);
|
||||||
|
|
||||||
|
#ifndef SOKOL_CLAY_NO_SOKOL_APP
|
||||||
|
void sclay_new_frame();
|
||||||
|
void sclay_handle_event(const sapp_event *ev);
|
||||||
|
#endif /* SOKOL_CLAY_NO_SOKOL_APP */
|
||||||
|
|
||||||
|
/* Use this if you don't call sclay_new_frame. `size` is the "virtual" size which
|
||||||
|
* your layout is relative to (ie. the actual framebuffer size divided by dpi_scale.)
|
||||||
|
* Set dpi_scale to 1 if you're not using high-dpi support. */
|
||||||
|
void sclay_set_layout_dimensions(Clay_Dimensions size, float dpi_scale);
|
||||||
|
|
||||||
|
void sclay_render(Clay_RenderCommandArray renderCommands, sclay_font_t *fonts);
|
||||||
|
|
||||||
|
#endif /* SOKOL_CLAY_INCLUDED */
|
||||||
|
|
||||||
|
#ifdef SOKOL_CLAY_IMPL
|
||||||
|
#define SOKOL_CLAY_IMPL_INCLUDED (1)
|
||||||
|
#ifndef SOKOL_GL_INCLUDED
|
||||||
|
#error "Please include sokol_gl.h before sokol_clay.h"
|
||||||
|
#endif
|
||||||
|
#ifndef SOKOL_FONTSTASH_INCLUDED
|
||||||
|
#error "Please include sokol_fontstash.h before sokol_clay.h"
|
||||||
|
#endif
|
||||||
|
#ifndef CLAY_HEADER
|
||||||
|
#error "Please include clay.h before sokol_clay.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
sgl_pipeline pip;
|
||||||
|
#ifndef SOKOL_CLAY_NO_SOKOL_APP
|
||||||
|
Clay_Vector2 mouse_pos, scroll;
|
||||||
|
bool mouse_down;
|
||||||
|
#endif
|
||||||
|
Clay_Dimensions size;
|
||||||
|
float dpi_scale;
|
||||||
|
FONScontext *fonts;
|
||||||
|
} _sclay_state_t;
|
||||||
|
static _sclay_state_t _sclay;
|
||||||
|
|
||||||
|
void sclay_setup() {
|
||||||
|
_sclay.pip = sgl_make_pipeline(&(sg_pipeline_desc){
|
||||||
|
.colors[0] = {
|
||||||
|
.blend = {
|
||||||
|
.enabled = true,
|
||||||
|
.src_factor_rgb = SG_BLENDFACTOR_SRC_ALPHA,
|
||||||
|
.dst_factor_rgb = SG_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
});
|
||||||
|
#ifndef SOKOL_CLAY_NO_SOKOL_APP
|
||||||
|
_sclay.mouse_pos = (Clay_Vector2){0, 0};
|
||||||
|
_sclay.scroll = (Clay_Vector2){0, 0};
|
||||||
|
_sclay.mouse_down = false;
|
||||||
|
#endif
|
||||||
|
_sclay.size = (Clay_Dimensions){1, 1};
|
||||||
|
_sclay.dpi_scale = 1;
|
||||||
|
_sclay.fonts = sfons_create(&(sfons_desc_t){ 0 });
|
||||||
|
//TODO clay error handler?
|
||||||
|
}
|
||||||
|
|
||||||
|
void sclay_shutdown() {
|
||||||
|
sgl_destroy_pipeline(_sclay.pip);
|
||||||
|
sfons_destroy(_sclay.fonts);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef SOKOL_CLAY_NO_SOKOL_APP
|
||||||
|
void sclay_handle_event(const sapp_event* ev) {
|
||||||
|
switch(ev->type){
|
||||||
|
case SAPP_EVENTTYPE_MOUSE_MOVE:
|
||||||
|
_sclay.mouse_pos.x = ev->mouse_x / _sclay.dpi_scale;
|
||||||
|
_sclay.mouse_pos.y = ev->mouse_y / _sclay.dpi_scale;
|
||||||
|
break;
|
||||||
|
case SAPP_EVENTTYPE_MOUSE_DOWN:
|
||||||
|
_sclay.mouse_down = true;
|
||||||
|
break;
|
||||||
|
case SAPP_EVENTTYPE_MOUSE_UP:
|
||||||
|
_sclay.mouse_down = false;
|
||||||
|
break;
|
||||||
|
case SAPP_EVENTTYPE_MOUSE_SCROLL:
|
||||||
|
_sclay.scroll.x += ev->scroll_x;
|
||||||
|
_sclay.scroll.y += ev->scroll_y;
|
||||||
|
break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void sclay_new_frame() {
|
||||||
|
sclay_set_layout_dimensions((Clay_Dimensions){ (float)sapp_width(), (float)sapp_height() },
|
||||||
|
sapp_dpi_scale());
|
||||||
|
Clay_SetPointerState(_sclay.mouse_pos, _sclay.mouse_down);
|
||||||
|
Clay_UpdateScrollContainers(true, _sclay.scroll, sapp_frame_duration());
|
||||||
|
_sclay.scroll = (Clay_Vector2){0, 0};
|
||||||
|
}
|
||||||
|
#endif /* SOKOL_CLAY_NO_SOKOL_APP */
|
||||||
|
|
||||||
|
void sclay_set_layout_dimensions(Clay_Dimensions size, float dpi_scale) {
|
||||||
|
size.width /= dpi_scale;
|
||||||
|
size.height /= dpi_scale;
|
||||||
|
_sclay.size = size;
|
||||||
|
if(_sclay.dpi_scale != dpi_scale){
|
||||||
|
_sclay.dpi_scale = dpi_scale;
|
||||||
|
Clay_ResetMeasureTextCache();
|
||||||
|
}
|
||||||
|
Clay_SetLayoutDimensions(size);
|
||||||
|
}
|
||||||
|
|
||||||
|
sclay_font_t sclay_add_font(const char *filename) {
|
||||||
|
//TODO log something if we get FONS_INVALID
|
||||||
|
return fonsAddFont(_sclay.fonts, "", filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
sclay_font_t sclay_add_font_mem(unsigned char *data, int dataLen) {
|
||||||
|
//TODO log something if we get FONS_INVALID
|
||||||
|
return fonsAddFontMem(_sclay.fonts, "", data, dataLen, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
Clay_Dimensions sclay_measure_text(Clay_StringSlice text, Clay_TextElementConfig *config, void *userData) {
|
||||||
|
sclay_font_t *fonts = (sclay_font_t *)userData;
|
||||||
|
if(!fonts) return (Clay_Dimensions){ 0 };
|
||||||
|
fonsSetFont(_sclay.fonts, fonts[config->fontId]);
|
||||||
|
fonsSetSize(_sclay.fonts, config->fontSize);
|
||||||
|
fonsSetSpacing(_sclay.fonts, config->letterSpacing);
|
||||||
|
float ascent, descent, lineh;
|
||||||
|
fonsVertMetrics(_sclay.fonts, &ascent, &descent, &lineh);
|
||||||
|
return (Clay_Dimensions) {
|
||||||
|
.width = fonsTextBounds(_sclay.fonts, 0, 0, text.chars, text.chars + text.length, NULL),
|
||||||
|
.height = ascent - descent
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
static void _draw_rect(float x, float y, float w, float h){
|
||||||
|
sgl_v2f(x, y);
|
||||||
|
sgl_v2f(x, y);
|
||||||
|
sgl_v2f(x+w, y);
|
||||||
|
sgl_v2f(x, y+h);
|
||||||
|
sgl_v2f(x+w, y+h);
|
||||||
|
sgl_v2f(x+w, y+h);
|
||||||
|
}
|
||||||
|
|
||||||
|
static float _SIN[16] = {
|
||||||
|
0.000000f, 0.104528f, 0.207912f, 0.309017f,
|
||||||
|
0.406737f, 0.500000f, 0.587785f, 0.669131f,
|
||||||
|
0.743145f, 0.809017f, 0.866025f, 0.913545f,
|
||||||
|
0.951057f, 0.978148f, 0.994522f, 1.000000f,
|
||||||
|
};
|
||||||
|
|
||||||
|
/* rx,ry = radius */
|
||||||
|
static void _draw_corner(float x, float y, float rx, float ry){
|
||||||
|
x -= rx;
|
||||||
|
y -= ry;
|
||||||
|
sgl_v2f(x, y);
|
||||||
|
for(int i = 0; i < 16; ++i){
|
||||||
|
sgl_v2f(x, y);
|
||||||
|
sgl_v2f(x+(rx*_SIN[15-i]), y+(ry*_SIN[i]));
|
||||||
|
}
|
||||||
|
sgl_v2f(x+(rx*_SIN[0]), y+(ry*_SIN[15]));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* rx,ry = radius ix,iy = inner radius */
|
||||||
|
static void _draw_corner_border(float x, float y, float rx, float ry, float ix, float iy){
|
||||||
|
x -= rx;
|
||||||
|
y -= ry;
|
||||||
|
sgl_v2f(x+(ix*_SIN[15]), y+(iy*_SIN[0]));
|
||||||
|
for(int i = 0; i < 16; ++i){
|
||||||
|
sgl_v2f(x+(ix*_SIN[15-i]), y+(iy*_SIN[i]));
|
||||||
|
sgl_v2f(x+(rx*_SIN[15-i]), y+(ry*_SIN[i]));
|
||||||
|
}
|
||||||
|
sgl_v2f(x+(rx*_SIN[0]), y+(ry*_SIN[15]));
|
||||||
|
}
|
||||||
|
|
||||||
|
void sclay_render(Clay_RenderCommandArray renderCommands, sclay_font_t *fonts) {
|
||||||
|
sgl_matrix_mode_modelview();
|
||||||
|
sgl_translate(-1.0f, 1.0f, 0.0f);
|
||||||
|
sgl_scale(2.0f/_sclay.size.width, -2.0f/_sclay.size.height, 1.0f);
|
||||||
|
sgl_disable_texture();
|
||||||
|
sgl_push_pipeline();
|
||||||
|
sgl_load_pipeline(_sclay.pip);
|
||||||
|
for (uint32_t i = 0; i < renderCommands.length; i++) {
|
||||||
|
Clay_RenderCommand *renderCommand = Clay_RenderCommandArray_Get(&renderCommands, i);
|
||||||
|
Clay_BoundingBox bbox = renderCommand->boundingBox;
|
||||||
|
switch (renderCommand->commandType) {
|
||||||
|
case CLAY_RENDER_COMMAND_TYPE_RECTANGLE: {
|
||||||
|
Clay_RectangleRenderData *config = &renderCommand->renderData.rectangle;
|
||||||
|
sgl_c4f(config->backgroundColor.r / 255.0f,
|
||||||
|
config->backgroundColor.g / 255.0f,
|
||||||
|
config->backgroundColor.b / 255.0f,
|
||||||
|
config->backgroundColor.a / 255.0f);
|
||||||
|
Clay_CornerRadius r = config->cornerRadius;
|
||||||
|
sgl_begin_triangle_strip();
|
||||||
|
if(r.topLeft > 0 || r.topRight > 0){
|
||||||
|
_draw_corner(bbox.x, bbox.y, -r.topLeft, -r.topLeft);
|
||||||
|
_draw_corner(bbox.x+bbox.width, bbox.y, r.topRight, -r.topRight);
|
||||||
|
_draw_rect(bbox.x+r.topLeft, bbox.y,
|
||||||
|
bbox.width-r.topLeft-r.topRight, CLAY__MAX(r.topLeft, r.topRight));
|
||||||
|
}
|
||||||
|
if(r.bottomLeft > 0 || r.bottomRight > 0){
|
||||||
|
_draw_corner(bbox.x, bbox.y+bbox.height, -r.bottomLeft, r.bottomLeft);
|
||||||
|
_draw_corner(bbox.x+bbox.width, bbox.y+bbox.height, r.bottomRight, r.bottomRight);
|
||||||
|
_draw_rect(bbox.x+r.bottomLeft,
|
||||||
|
bbox.y+bbox.height-CLAY__MAX(r.bottomLeft, r.bottomRight),
|
||||||
|
bbox.width-r.bottomLeft-r.bottomRight, CLAY__MAX(r.bottomLeft, r.bottomRight));
|
||||||
|
}
|
||||||
|
if(r.topLeft < r.bottomLeft){
|
||||||
|
if(r.topLeft < r.topRight){
|
||||||
|
_draw_rect(bbox.x, bbox.y+r.topLeft, r.topLeft, bbox.height-r.topLeft-r.bottomLeft);
|
||||||
|
_draw_rect(bbox.x+r.topLeft, bbox.y+r.topRight,
|
||||||
|
r.bottomLeft-r.topLeft, bbox.height-r.topRight-r.bottomLeft);
|
||||||
|
} else {
|
||||||
|
_draw_rect(bbox.x, bbox.y+r.topLeft, r.bottomLeft, bbox.height-r.topLeft-r.bottomLeft);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if(r.bottomLeft < r.bottomRight){
|
||||||
|
_draw_rect(bbox.x, bbox.y+r.topLeft, r.bottomLeft, bbox.height-r.topLeft-r.bottomLeft);
|
||||||
|
_draw_rect(bbox.x+r.bottomLeft, bbox.y+r.topLeft,
|
||||||
|
r.topLeft-r.bottomLeft, bbox.height-r.topLeft-r.bottomRight);
|
||||||
|
} else {
|
||||||
|
_draw_rect(bbox.x, bbox.y+r.topLeft, r.topLeft, bbox.height-r.topLeft-r.bottomLeft);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(r.topRight < r.bottomRight){
|
||||||
|
if(r.topRight < r.topLeft){
|
||||||
|
_draw_rect(bbox.x+bbox.width-r.bottomRight, bbox.y+r.topLeft,
|
||||||
|
r.bottomRight-r.topRight, bbox.height-r.topLeft-r.bottomRight);
|
||||||
|
_draw_rect(bbox.x+bbox.width-r.topRight, bbox.y+r.topRight,
|
||||||
|
r.topRight, bbox.height-r.topRight-r.bottomRight);
|
||||||
|
} else {
|
||||||
|
_draw_rect(bbox.x+bbox.width-r.bottomRight, bbox.y+r.topRight,
|
||||||
|
r.bottomRight, bbox.height-r.topRight-r.bottomRight);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if(r.bottomRight < r.bottomLeft){
|
||||||
|
_draw_rect(bbox.x+bbox.width-r.topRight, bbox.y+r.topRight,
|
||||||
|
r.topRight-r.bottomRight, bbox.height-r.topRight-r.bottomLeft);
|
||||||
|
_draw_rect(bbox.x+bbox.width-r.bottomRight, bbox.y+r.topRight,
|
||||||
|
r.bottomRight, bbox.height-r.topRight-r.bottomRight);
|
||||||
|
} else {
|
||||||
|
_draw_rect(bbox.x+bbox.width-r.topRight, bbox.y+r.topRight,
|
||||||
|
r.topRight, bbox.height-r.topRight-r.bottomRight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_draw_rect(bbox.x+CLAY__MAX(r.topLeft, r.bottomLeft),
|
||||||
|
bbox.y+CLAY__MAX(r.topLeft, r.topRight),
|
||||||
|
bbox.width-CLAY__MAX(r.topLeft, r.bottomLeft)-CLAY__MAX(r.topRight, r.bottomRight),
|
||||||
|
bbox.height-CLAY__MAX(r.topLeft, r.topRight)-CLAY__MAX(r.bottomLeft, r.bottomRight));
|
||||||
|
sgl_end();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case CLAY_RENDER_COMMAND_TYPE_TEXT: {
|
||||||
|
if(!fonts) break;
|
||||||
|
Clay_TextRenderData *config = &renderCommand->renderData.text;
|
||||||
|
Clay_StringSlice text = config->stringContents;
|
||||||
|
fonsSetFont(_sclay.fonts, fonts[config->fontId]);
|
||||||
|
uint32_t color = sfons_rgba(
|
||||||
|
config->textColor.r,
|
||||||
|
config->textColor.g,
|
||||||
|
config->textColor.b,
|
||||||
|
config->textColor.a);
|
||||||
|
fonsSetColor(_sclay.fonts, color);
|
||||||
|
fonsSetSpacing(_sclay.fonts, config->letterSpacing * _sclay.dpi_scale);
|
||||||
|
fonsSetAlign(_sclay.fonts, FONS_ALIGN_LEFT | FONS_ALIGN_TOP);
|
||||||
|
fonsSetSize(_sclay.fonts, config->fontSize * _sclay.dpi_scale);
|
||||||
|
sgl_matrix_mode_modelview();
|
||||||
|
sgl_push_matrix();
|
||||||
|
sgl_scale(1.0f/_sclay.dpi_scale, 1.0f/_sclay.dpi_scale, 1.0f);
|
||||||
|
fonsDrawText(_sclay.fonts, bbox.x*_sclay.dpi_scale, bbox.y*_sclay.dpi_scale,
|
||||||
|
text.chars, text.chars + text.length);
|
||||||
|
sgl_pop_matrix();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case CLAY_RENDER_COMMAND_TYPE_SCISSOR_START: {
|
||||||
|
sgl_scissor_rectf(bbox.x*_sclay.dpi_scale, bbox.y*_sclay.dpi_scale,
|
||||||
|
bbox.width*_sclay.dpi_scale, bbox.height*_sclay.dpi_scale,
|
||||||
|
true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case CLAY_RENDER_COMMAND_TYPE_SCISSOR_END: {
|
||||||
|
sgl_scissor_rectf(0, 0,
|
||||||
|
_sclay.size.width*_sclay.dpi_scale, _sclay.size.height*_sclay.dpi_scale,
|
||||||
|
true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case CLAY_RENDER_COMMAND_TYPE_IMAGE: {
|
||||||
|
//TODO
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case CLAY_RENDER_COMMAND_TYPE_BORDER: {
|
||||||
|
Clay_BorderRenderData *config = &renderCommand->renderData.border;
|
||||||
|
sgl_c4f(config->color.r / 255.0f,
|
||||||
|
config->color.g / 255.0f,
|
||||||
|
config->color.b / 255.0f,
|
||||||
|
config->color.a / 255.0f);
|
||||||
|
Clay_BorderWidth w = config->width;
|
||||||
|
Clay_CornerRadius r = config->cornerRadius;
|
||||||
|
sgl_begin_triangle_strip();
|
||||||
|
if(w.left > 0){
|
||||||
|
_draw_rect(bbox.x, bbox.y + r.topLeft,
|
||||||
|
w.left, bbox.height - r.topLeft - r.bottomLeft);
|
||||||
|
}
|
||||||
|
if(w.right > 0){
|
||||||
|
_draw_rect(bbox.x + bbox.width - w.right, bbox.y + r.topRight,
|
||||||
|
w.right, bbox.height - r.topRight - r.bottomRight);
|
||||||
|
}
|
||||||
|
if(w.top > 0){
|
||||||
|
_draw_rect(bbox.x + r.topLeft, bbox.y,
|
||||||
|
bbox.width - r.topLeft - r.topRight, w.top);
|
||||||
|
}
|
||||||
|
if(w.bottom > 0){
|
||||||
|
_draw_rect(bbox.x + r.bottomLeft, bbox.y + bbox.height - w.bottom,
|
||||||
|
bbox.width - r.bottomLeft - r.bottomRight, w.bottom);
|
||||||
|
}
|
||||||
|
if(r.topLeft > 0 && (w.top > 0 || w.left > 0)){
|
||||||
|
_draw_corner_border(bbox.x, bbox.y,
|
||||||
|
-r.topLeft, -r.topLeft,
|
||||||
|
-r.topLeft+w.left, -r.topLeft+w.top);
|
||||||
|
}
|
||||||
|
if(r.topRight > 0 && (w.top > 0 || w.right > 0)){
|
||||||
|
_draw_corner_border(bbox.x+bbox.width, bbox.y,
|
||||||
|
r.topRight, -r.topRight,
|
||||||
|
r.topRight-w.right, -r.topRight+w.top);
|
||||||
|
}
|
||||||
|
if(r.bottomLeft > 0 && (w.bottom > 0 || w.left > 0)){
|
||||||
|
_draw_corner_border(bbox.x, bbox.y+bbox.height,
|
||||||
|
-r.bottomLeft, r.bottomLeft,
|
||||||
|
-r.bottomLeft+w.left, r.bottomLeft-w.bottom);
|
||||||
|
}
|
||||||
|
if(r.bottomRight > 0 && (w.bottom > 0 || w.right > 0)){
|
||||||
|
_draw_corner_border(bbox.x+bbox.width, bbox.y+bbox.height,
|
||||||
|
r.bottomRight, r.bottomRight,
|
||||||
|
r.bottomRight-w.right, r.bottomRight-w.bottom);
|
||||||
|
}
|
||||||
|
sgl_end();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sgl_pop_pipeline();
|
||||||
|
sfons_flush(_sclay.fonts);
|
||||||
|
}
|
||||||
|
#endif /* SOKOL_CLAY_IMPL */
|
@ -1,11 +1,290 @@
|
|||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
|
|
||||||
|
#if !defined(CLAY_DISABLE_SIMD) && (defined(__x86_64__) || defined(_M_X64) || defined(_M_AMD64))
|
||||||
|
#include <immintrin.h> // AVX intrinsincs for faster sqrtf
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "../../clay.h"
|
#include "../../clay.h"
|
||||||
|
|
||||||
HDC renderer_hdcMem = {0};
|
HDC renderer_hdcMem = {0};
|
||||||
HBITMAP renderer_hbmMem = {0};
|
HBITMAP renderer_hbmMem = {0};
|
||||||
HANDLE renderer_hOld = {0};
|
HANDLE renderer_hOld = {0};
|
||||||
|
DWORD g_dwGdiRenderFlags;
|
||||||
|
|
||||||
void Clay_Win32_Render(HWND hwnd, Clay_RenderCommandArray renderCommands)
|
#ifndef RECTWIDTH
|
||||||
|
#define RECTWIDTH(rc) ((rc).right - (rc).left)
|
||||||
|
#endif
|
||||||
|
#ifndef RECTHEIGHT
|
||||||
|
#define RECTHEIGHT(rc) ((rc).bottom - (rc).top)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Renderer options bit flags
|
||||||
|
// RF clearly stated in the name to avoid confusion with possible macro definitions for other purposes
|
||||||
|
#define CLAYGDI_RF_ALPHABLEND 0x00000001
|
||||||
|
#define CLAYGDI_RF_SMOOTHCORNERS 0x00000002
|
||||||
|
// These are bitflags, not indexes. Next would be 0x00000004
|
||||||
|
|
||||||
|
inline DWORD Clay_Win32_GetRendererFlags() { return g_dwGdiRenderFlags; }
|
||||||
|
|
||||||
|
// Replaces the rendering flags with new ones provided
|
||||||
|
inline void Clay_Win32_SetRendererFlags(DWORD dwFlags) { g_dwGdiRenderFlags = dwFlags; }
|
||||||
|
|
||||||
|
// Returns `true` if flags were modified
|
||||||
|
inline bool Clay_Win32_ModifyRendererFlags(DWORD dwRemove, DWORD dwAdd)
|
||||||
|
{
|
||||||
|
DWORD dwSavedFlags = g_dwGdiRenderFlags;
|
||||||
|
DWORD dwNewFlags = (dwSavedFlags & ~dwRemove) | dwAdd;
|
||||||
|
|
||||||
|
if (dwSavedFlags == dwNewFlags)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
Clay_Win32_SetRendererFlags(dwNewFlags);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------------------+
|
||||||
|
| Math stuff start |
|
||||||
|
+----------------------------------------------------------------------------*/
|
||||||
|
// Intrinsincs wrappers
|
||||||
|
#if !defined(CLAY_DISABLE_SIMD) && (defined(__x86_64__) || defined(_M_X64) || defined(_M_AMD64))
|
||||||
|
inline float intrin_sqrtf(const float f)
|
||||||
|
{
|
||||||
|
__m128 temp = _mm_set_ss(f);
|
||||||
|
temp = _mm_sqrt_ss(temp);
|
||||||
|
return _mm_cvtss_f32(temp);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Use fast inverse square root
|
||||||
|
#if defined(USE_FAST_SQRT)
|
||||||
|
float fast_inv_sqrtf(float number)
|
||||||
|
{
|
||||||
|
const float threehalfs = 1.5f;
|
||||||
|
|
||||||
|
float x2 = number * 0.5f;
|
||||||
|
float y = number;
|
||||||
|
|
||||||
|
// Evil bit-level hacking
|
||||||
|
uint32_t i = *(uint32_t*)&y;
|
||||||
|
i = 0x5f3759df - (i >> 1); // Initial guess for Newton's method
|
||||||
|
y = *(float*)&i;
|
||||||
|
|
||||||
|
// One iteration of Newton's method
|
||||||
|
y = y * (threehalfs - (x2 * y * y)); // y = y * (1.5 - 0.5 * x * y^2)
|
||||||
|
|
||||||
|
return y;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fast square root approximation using the inverse square root
|
||||||
|
float fast_sqrtf(float number)
|
||||||
|
{
|
||||||
|
if (number < 0.0f) return 0.0f; // Handle negative input
|
||||||
|
return number * fast_inv_sqrtf(number);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// sqrtf_impl implementation chooser
|
||||||
|
#if !defined(CLAY_DISABLE_SIMD) && (defined(__x86_64__) || defined(_M_X64) || defined(_M_AMD64))
|
||||||
|
#define sqrtf_impl(x) intrin_sqrtf(x)
|
||||||
|
#elif defined(USE_FAST_SQRT)
|
||||||
|
#define sqrtf_impl(x) fast_sqrtf(x)
|
||||||
|
#else
|
||||||
|
#define sqrtf_impl(x) sqrtf(x) // Fallback to std sqrtf
|
||||||
|
#endif
|
||||||
|
/*----------------------------------------------------------------------------+
|
||||||
|
| Math stuff end |
|
||||||
|
+----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
static inline Clay_Color ColorBlend(Clay_Color base, Clay_Color overlay, float factor)
|
||||||
|
{
|
||||||
|
Clay_Color blended;
|
||||||
|
|
||||||
|
// Normalize alpha values for multiplications
|
||||||
|
float base_a = base.a / 255.0f;
|
||||||
|
float overlay_a = overlay.a / 255.0f;
|
||||||
|
|
||||||
|
overlay_a *= factor;
|
||||||
|
|
||||||
|
float out_a = overlay_a + base_a * (1.0f - overlay_a);
|
||||||
|
|
||||||
|
// Avoid division by zero and fully transparent cases
|
||||||
|
if (out_a <= 0.0f)
|
||||||
|
{
|
||||||
|
return (Clay_Color) { .a = 0, .r = 0, .g = 0, .b = 0 };
|
||||||
|
}
|
||||||
|
|
||||||
|
blended.r = (overlay.r * overlay_a + base.r * base_a * (1.0f - overlay_a)) / out_a;
|
||||||
|
blended.g = (overlay.g * overlay_a + base.g * base_a * (1.0f - overlay_a)) / out_a;
|
||||||
|
blended.b = (overlay.b * overlay_a + base.b * base_a * (1.0f - overlay_a)) / out_a;
|
||||||
|
blended.a = out_a * 255.0f; // Denormalize alpha back
|
||||||
|
|
||||||
|
return blended;
|
||||||
|
}
|
||||||
|
|
||||||
|
static float RoundedRectPixelCoverage(int x, int y, const Clay_CornerRadius radius, int width, int height) {
|
||||||
|
// Check if the pixel is in one of the four rounded corners
|
||||||
|
if (x < radius.topLeft && y < radius.topLeft) {
|
||||||
|
// Top-left corner
|
||||||
|
float dx = radius.topLeft - x - 1;
|
||||||
|
float dy = radius.topLeft - y - 1;
|
||||||
|
float distance = sqrtf_impl(dx * dx + dy * dy);
|
||||||
|
if (distance > radius.topLeft)
|
||||||
|
return 0.0f;
|
||||||
|
if (distance <= radius.topLeft - 1)
|
||||||
|
return 1.0f;
|
||||||
|
return radius.topLeft - distance;
|
||||||
|
}
|
||||||
|
else if (x >= width - radius.topRight && y < radius.topRight) {
|
||||||
|
// Top-right corner
|
||||||
|
float dx = x - (width - radius.topRight);
|
||||||
|
float dy = radius.topRight - y - 1;
|
||||||
|
float distance = sqrtf_impl(dx * dx + dy * dy);
|
||||||
|
if (distance > radius.topRight)
|
||||||
|
return 0.0f;
|
||||||
|
if (distance <= radius.topRight - 1)
|
||||||
|
return 1.0f;
|
||||||
|
return radius.topRight - distance;
|
||||||
|
}
|
||||||
|
else if (x < radius.bottomLeft && y >= height - radius.bottomLeft) {
|
||||||
|
// Bottom-left corner
|
||||||
|
float dx = radius.bottomLeft - x - 1;
|
||||||
|
float dy = y - (height - radius.bottomLeft);
|
||||||
|
float distance = sqrtf_impl(dx * dx + dy * dy);
|
||||||
|
if (distance > radius.bottomLeft)
|
||||||
|
return 0.0f;
|
||||||
|
if (distance <= radius.bottomLeft - 1)
|
||||||
|
return 1.0f;
|
||||||
|
return radius.bottomLeft - distance;
|
||||||
|
}
|
||||||
|
else if (x >= width - radius.bottomRight && y >= height - radius.bottomRight) {
|
||||||
|
// Bottom-right corner
|
||||||
|
float dx = x - (width - radius.bottomRight);
|
||||||
|
float dy = y - (height - radius.bottomRight);
|
||||||
|
float distance = sqrtf_impl(dx * dx + dy * dy);
|
||||||
|
if (distance > radius.bottomRight)
|
||||||
|
return 0.0f;
|
||||||
|
if (distance <= radius.bottomRight - 1)
|
||||||
|
return 1.0f;
|
||||||
|
return radius.bottomRight - distance;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Not in a corner, full coverage
|
||||||
|
return 1.0f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
HDC hdcMem;
|
||||||
|
HBITMAP hbmMem;
|
||||||
|
HBITMAP hbmMemPrev;
|
||||||
|
void* pBits;
|
||||||
|
SIZE size;
|
||||||
|
} HDCSubstitute;
|
||||||
|
|
||||||
|
static void CreateHDCSubstitute(HDCSubstitute* phdcs, HDC hdcSrc, PRECT prc)
|
||||||
|
{
|
||||||
|
if (prc == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
phdcs->size = (SIZE){ RECTWIDTH(*prc), RECTHEIGHT(*prc) };
|
||||||
|
if (phdcs->size.cx <= 0 || phdcs->size.cy <= 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
phdcs->hdcMem = CreateCompatibleDC(hdcSrc);
|
||||||
|
if (phdcs->hdcMem == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Create a 32-bit DIB section for the memory DC
|
||||||
|
BITMAPINFO bmi = { 0 };
|
||||||
|
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
|
||||||
|
bmi.bmiHeader.biWidth = phdcs->size.cx;
|
||||||
|
bmi.bmiHeader.biHeight = -phdcs->size.cy; // I think it's faster? Probably
|
||||||
|
bmi.bmiHeader.biPlanes = 1;
|
||||||
|
bmi.bmiHeader.biBitCount = 32;
|
||||||
|
bmi.bmiHeader.biCompression = BI_RGB;
|
||||||
|
|
||||||
|
phdcs->pBits = NULL;
|
||||||
|
|
||||||
|
phdcs->hbmMem = CreateDIBSection(phdcs->hdcMem, &bmi, DIB_RGB_COLORS, &phdcs->pBits, NULL, 0);
|
||||||
|
if (phdcs->hbmMem == NULL)
|
||||||
|
{
|
||||||
|
DeleteDC(phdcs->hdcMem);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Select the DIB section into the memory DC
|
||||||
|
phdcs->hbmMemPrev = SelectObject(phdcs->hdcMem, phdcs->hbmMem);
|
||||||
|
|
||||||
|
// Copy the content of the target DC to the memory DC
|
||||||
|
BitBlt(phdcs->hdcMem, 0, 0, phdcs->size.cx, phdcs->size.cy, hdcSrc, prc->left, prc->top, SRCCOPY);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void DestroyHDCSubstitute(HDCSubstitute* phdcs)
|
||||||
|
{
|
||||||
|
if (phdcs == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Clean up
|
||||||
|
SelectObject(phdcs->hdcMem, phdcs->hbmMemPrev);
|
||||||
|
DeleteObject(phdcs->hbmMem);
|
||||||
|
DeleteDC(phdcs->hdcMem);
|
||||||
|
|
||||||
|
ZeroMemory(phdcs, sizeof(HDCSubstitute));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void __Clay_Win32_FillRoundRect(HDC hdc, PRECT prc, Clay_Color color, Clay_CornerRadius radius)
|
||||||
|
{
|
||||||
|
HDCSubstitute substitute = { 0 };
|
||||||
|
CreateHDCSubstitute(&substitute, hdc, prc);
|
||||||
|
|
||||||
|
bool has_corner_radius = radius.topLeft || radius.topRight || radius.bottomLeft || radius.bottomRight;
|
||||||
|
|
||||||
|
if (has_corner_radius)
|
||||||
|
{
|
||||||
|
// Limit the corner radius to the minimum of half the width and half the height
|
||||||
|
float max_radius = (float)fmin(substitute.size.cx / 2.0f, substitute.size.cy / 2.0f);
|
||||||
|
if (radius.topLeft > max_radius) radius.topLeft = max_radius;
|
||||||
|
if (radius.topRight > max_radius) radius.topRight = max_radius;
|
||||||
|
if (radius.bottomLeft > max_radius) radius.bottomLeft = max_radius;
|
||||||
|
if (radius.bottomRight > max_radius) radius.bottomRight = max_radius;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Iterate over each pixel in the DIB section
|
||||||
|
uint32_t* pixels = (uint32_t*)substitute.pBits;
|
||||||
|
for (int y = 0; y < substitute.size.cy; ++y)
|
||||||
|
{
|
||||||
|
for (int x = 0; x < substitute.size.cx; ++x)
|
||||||
|
{
|
||||||
|
float coverage = 1.0f;
|
||||||
|
if (has_corner_radius)
|
||||||
|
coverage = RoundedRectPixelCoverage(x, y, radius, substitute.size.cx, substitute.size.cy);
|
||||||
|
|
||||||
|
if (coverage > 0.0f)
|
||||||
|
{
|
||||||
|
uint32_t pixel = pixels[y * substitute.size.cx + x];
|
||||||
|
Clay_Color dst_color = {
|
||||||
|
.r = (float)((pixel >> 16) & 0xFF), // Red
|
||||||
|
.g = (float)((pixel >> 8) & 0xFF), // Green
|
||||||
|
.b = (float)(pixel & 0xFF), // Blue
|
||||||
|
.a = 255.0f // Fully opaque
|
||||||
|
};
|
||||||
|
Clay_Color blended = ColorBlend(dst_color, color, coverage);
|
||||||
|
|
||||||
|
pixels[y * substitute.size.cx + x] =
|
||||||
|
((uint32_t)(blended.b) << 0) |
|
||||||
|
((uint32_t)(blended.g) << 8) |
|
||||||
|
((uint32_t)(blended.r) << 16);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copy the blended content back to the target DC
|
||||||
|
BitBlt(hdc, prc->left, prc->top, substitute.size.cx, substitute.size.cy, substitute.hdcMem, 0, 0, SRCCOPY);
|
||||||
|
DestroyHDCSubstitute(&substitute);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Clay_Win32_Render(HWND hwnd, Clay_RenderCommandArray renderCommands, HFONT* fonts)
|
||||||
{
|
{
|
||||||
bool is_clipping = false;
|
bool is_clipping = false;
|
||||||
HRGN clipping_region = {0};
|
HRGN clipping_region = {0};
|
||||||
@ -48,14 +327,22 @@ void Clay_Win32_Render(HWND hwnd, Clay_RenderCommandArray renderCommands)
|
|||||||
r.right = boundingBox.x + boundingBox.width + r.right;
|
r.right = boundingBox.x + boundingBox.width + r.right;
|
||||||
r.bottom = boundingBox.y + boundingBox.height + r.bottom;
|
r.bottom = boundingBox.y + boundingBox.height + r.bottom;
|
||||||
|
|
||||||
|
uint16_t font_id = renderCommand->renderData.text.fontId;
|
||||||
|
HFONT hFont = fonts[font_id];
|
||||||
|
HFONT hPrevFont = SelectObject(renderer_hdcMem, hFont);
|
||||||
|
|
||||||
|
// Actually draw text
|
||||||
DrawTextA(renderer_hdcMem, renderCommand->renderData.text.stringContents.chars,
|
DrawTextA(renderer_hdcMem, renderCommand->renderData.text.stringContents.chars,
|
||||||
renderCommand->renderData.text.stringContents.length,
|
renderCommand->renderData.text.stringContents.length,
|
||||||
&r, DT_TOP | DT_LEFT);
|
&r, DT_TOP | DT_LEFT);
|
||||||
|
|
||||||
|
SelectObject(renderer_hdcMem, hPrevFont);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CLAY_RENDER_COMMAND_TYPE_RECTANGLE:
|
case CLAY_RENDER_COMMAND_TYPE_RECTANGLE:
|
||||||
{
|
{
|
||||||
|
DWORD dwFlags = Clay_Win32_GetRendererFlags();
|
||||||
Clay_RectangleRenderData rrd = renderCommand->renderData.rectangle;
|
Clay_RectangleRenderData rrd = renderCommand->renderData.rectangle;
|
||||||
RECT r = rc;
|
RECT r = rc;
|
||||||
|
|
||||||
@ -64,9 +351,28 @@ void Clay_Win32_Render(HWND hwnd, Clay_RenderCommandArray renderCommands)
|
|||||||
r.right = boundingBox.x + boundingBox.width;
|
r.right = boundingBox.x + boundingBox.width;
|
||||||
r.bottom = boundingBox.y + boundingBox.height;
|
r.bottom = boundingBox.y + boundingBox.height;
|
||||||
|
|
||||||
|
bool translucid = false;
|
||||||
|
// There is need to check that only if alphablending is enabled.
|
||||||
|
// In other case the blending will be always opaque and we can jump to simpler FillRgn/Rect
|
||||||
|
if (dwFlags & CLAYGDI_RF_ALPHABLEND)
|
||||||
|
translucid = rrd.backgroundColor.a > 0.0f && rrd.backgroundColor.a < 255.0f;
|
||||||
|
|
||||||
|
bool has_rounded_corners = rrd.cornerRadius.topLeft > 0.0f
|
||||||
|
|| rrd.cornerRadius.topRight > 0.0f
|
||||||
|
|| rrd.cornerRadius.bottomLeft > 0.0f
|
||||||
|
|| rrd.cornerRadius.bottomRight > 0.0f;
|
||||||
|
|
||||||
|
// We go here if CLAYGDI_RF_SMOOTHCORNERS flag is set and one of the corners is rounded
|
||||||
|
// Also we go here if GLAYGDI_RF_ALPHABLEND flag is set and the fill color is translucid
|
||||||
|
if ((dwFlags & CLAYGDI_RF_ALPHABLEND) && translucid || (dwFlags & CLAYGDI_RF_SMOOTHCORNERS) && has_rounded_corners)
|
||||||
|
{
|
||||||
|
__Clay_Win32_FillRoundRect(renderer_hdcMem, &r, rrd.backgroundColor, rrd.cornerRadius);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
HBRUSH recColor = CreateSolidBrush(RGB(rrd.backgroundColor.r, rrd.backgroundColor.g, rrd.backgroundColor.b));
|
HBRUSH recColor = CreateSolidBrush(RGB(rrd.backgroundColor.r, rrd.backgroundColor.g, rrd.backgroundColor.b));
|
||||||
|
|
||||||
if (rrd.cornerRadius.topLeft > 0)
|
if (has_rounded_corners)
|
||||||
{
|
{
|
||||||
HRGN roundedRectRgn = CreateRoundRectRgn(
|
HRGN roundedRectRgn = CreateRoundRectRgn(
|
||||||
r.left, r.top, r.right + 1, r.bottom + 1,
|
r.left, r.top, r.right + 1, r.bottom + 1,
|
||||||
@ -81,6 +387,8 @@ void Clay_Win32_Render(HWND hwnd, Clay_RenderCommandArray renderCommands)
|
|||||||
}
|
}
|
||||||
|
|
||||||
DeleteObject(recColor);
|
DeleteObject(recColor);
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -216,6 +524,37 @@ static inline Clay_Dimensions Clay_Win32_MeasureText(Clay_StringSlice text, Clay
|
|||||||
{
|
{
|
||||||
Clay_Dimensions textSize = {0};
|
Clay_Dimensions textSize = {0};
|
||||||
|
|
||||||
|
if (userData != NULL)
|
||||||
|
{
|
||||||
|
HFONT* fonts = (HFONT*)userData;
|
||||||
|
HFONT hFont = fonts[config->fontId];
|
||||||
|
|
||||||
|
if (hFont != NULL)
|
||||||
|
{
|
||||||
|
HDC hScreenDC = GetDC(NULL);
|
||||||
|
HDC hTempDC = CreateCompatibleDC(hScreenDC);
|
||||||
|
|
||||||
|
if (hTempDC != NULL)
|
||||||
|
{
|
||||||
|
HFONT hPrevFont = SelectObject(hTempDC, hFont);
|
||||||
|
|
||||||
|
SIZE size;
|
||||||
|
GetTextExtentPoint32(hTempDC, text.chars, text.length, &size);
|
||||||
|
|
||||||
|
textSize.width = size.cx;
|
||||||
|
textSize.height = size.cy;
|
||||||
|
|
||||||
|
SelectObject(hScreenDC, hPrevFont);
|
||||||
|
DeleteDC(hTempDC);
|
||||||
|
|
||||||
|
return textSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
ReleaseDC(HWND_DESKTOP, hScreenDC);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallback for system bitmap font
|
||||||
float maxTextWidth = 0.0f;
|
float maxTextWidth = 0.0f;
|
||||||
float lineTextWidth = 0;
|
float lineTextWidth = 0;
|
||||||
float textHeight = WIN32_FONT_HEIGHT;
|
float textHeight = WIN32_FONT_HEIGHT;
|
||||||
@ -239,3 +578,32 @@ static inline Clay_Dimensions Clay_Win32_MeasureText(Clay_StringSlice text, Clay
|
|||||||
|
|
||||||
return textSize;
|
return textSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HFONT Clay_Win32_SimpleCreateFont(const char* filePath, const char* family, int height, int weight)
|
||||||
|
{
|
||||||
|
// Add the font resource to the application instance
|
||||||
|
int fontAdded = AddFontResourceEx(filePath, FR_PRIVATE, NULL);
|
||||||
|
if (fontAdded == 0) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
int fontHeight = height;
|
||||||
|
|
||||||
|
// If negative, treat height as Pt rather than pixels
|
||||||
|
if (height < 0) {
|
||||||
|
// Get the screen DPI
|
||||||
|
HDC hScreenDC = GetDC(NULL);
|
||||||
|
int iScreenDPI = GetDeviceCaps(hScreenDC, LOGPIXELSY);
|
||||||
|
ReleaseDC(HWND_DESKTOP, hScreenDC);
|
||||||
|
|
||||||
|
// Convert font height from points to pixels
|
||||||
|
fontHeight = MulDiv(height, iScreenDPI, 72);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create the font using the calculated height and the font name
|
||||||
|
HFONT hFont = CreateFont(fontHeight, 0, 0, 0, weight, FALSE, FALSE, FALSE,
|
||||||
|
ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
|
||||||
|
DEFAULT_PITCH, family);
|
||||||
|
|
||||||
|
return hFont;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user