mirror of
https://github.com/nicbarker/clay.git
synced 2025-04-15 10:48:04 +00:00
Changed the UI proc to be like the one in the Odin bindings
This commit is contained in:
parent
409bf1c3bf
commit
e9522005db
Binary file not shown.
@ -80,10 +80,7 @@ main :: () {
|
||||
Clay.ID("OuterContainer"),
|
||||
Clay.Layout(.{
|
||||
layoutDirection = .TOP_TO_BOTTOM,
|
||||
sizing = Clay.Sizing.{
|
||||
Clay.SizingGrow(),
|
||||
Clay.SizingGrow(),
|
||||
},
|
||||
sizing = layout_expand,
|
||||
padding = .{16, 16},
|
||||
childGap = 16,
|
||||
}),
|
||||
|
@ -5,6 +5,8 @@ SOURCE_PATH :: "source";
|
||||
// These have custom declaration in module.jai
|
||||
DECLARATIONS_TO_OMIT :: string.[
|
||||
"Clay_Vector2",
|
||||
"Clay__ElementConfigType",
|
||||
"Clay__AlignClay__ElementConfigType",
|
||||
];
|
||||
|
||||
#if AT_COMPILE_TIME {
|
||||
|
@ -1,38 +1,80 @@
|
||||
|
||||
Vector2 :: Math.Vector2;
|
||||
|
||||
ElementConfigType :: enum s32 {
|
||||
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 :: 256;
|
||||
LAYOUT :: 257;
|
||||
}
|
||||
|
||||
// This is passed to UI so that we can omit layout
|
||||
TypedConfig :: struct {
|
||||
type: ElementConfigType;
|
||||
config: *void;
|
||||
id: ElementId;
|
||||
}
|
||||
|
||||
make_string :: (str: string) -> String {
|
||||
return .{cast(u64, str.count), str.data};
|
||||
}
|
||||
|
||||
UI :: (id: ElementId, layout: LayoutConfig, configs: ..ElementConfig, $call := #caller_code) -> bool #must #expand {
|
||||
// The way of handling this is inspired by the odin bindings
|
||||
UI :: (configs: ..TypedConfig, $call := #caller_code) -> bool #must #expand {
|
||||
_OpenElement();
|
||||
_AttachId(id);
|
||||
_AttachLayoutConfig(_StoreLayoutConfig(layout));
|
||||
for configs _AttachElementConfig(it.config, it.type);
|
||||
for config : 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();
|
||||
|
||||
// !IMPORTANT
|
||||
// TODO Fix the need to have to add the namespace here
|
||||
#insert,scope(call) #code defer Clay._CloseElement();;
|
||||
|
||||
return true;
|
||||
|
||||
// `defer _CloseElement();
|
||||
}
|
||||
|
||||
ID :: (label: string, index: u32 = 0) -> ElementId {
|
||||
return _HashString(make_string(label), index, 0);
|
||||
ID :: (label: string, index: u32 = 0) -> TypedConfig {
|
||||
return .{type = .ID, id = _HashString(make_string(label), index, 0)};
|
||||
}
|
||||
|
||||
Layout :: (config: LayoutConfig) -> LayoutConfig {
|
||||
// We can just return the config because the layout is attached and stored in the UI function
|
||||
return config;
|
||||
Layout :: (config: LayoutConfig) -> TypedConfig {
|
||||
return .{type = .LAYOUT, config = _StoreLayoutConfig(config)};
|
||||
}
|
||||
|
||||
Rectangle :: (config: RectangleElementConfig) -> ElementConfig {
|
||||
Rectangle :: (config: RectangleElementConfig) -> TypedConfig {
|
||||
return .{
|
||||
type = .RECTANGLE,
|
||||
config.rectangleElementConfig = _StoreRectangleElementConfig(config)
|
||||
config = _StoreRectangleElementConfig(config)
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
//
|
||||
// This file was auto-generated using the following command:
|
||||
//
|
||||
// jai generate.jai - -compile -debug
|
||||
// jai generate.jai - -compile
|
||||
//
|
||||
|
||||
|
||||
@ -119,29 +119,6 @@ _AlignClay_CornerRadius :: struct {
|
||||
x: CornerRadius;
|
||||
}
|
||||
|
||||
_ElementConfigType :: enum s32 {
|
||||
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;
|
||||
}
|
||||
_AlignClay__ElementConfigType :: struct {
|
||||
c: u8;
|
||||
x: _ElementConfigType;
|
||||
}
|
||||
|
||||
LayoutDirection :: enum s32 {
|
||||
LEFT_TO_RIGHT :: 0;
|
||||
TOP_TO_BOTTOM :: 1;
|
||||
@ -429,7 +406,7 @@ _AlignClay_ElementConfigUnion :: struct {
|
||||
}
|
||||
|
||||
ElementConfig :: struct {
|
||||
type: _ElementConfigType;
|
||||
type: ElementConfigType;
|
||||
config: ElementConfigUnion;
|
||||
}
|
||||
_AlignClay_ElementConfig :: struct {
|
||||
@ -594,7 +571,7 @@ _StoreLayoutConfig :: (config: LayoutConfig) -> *LayoutConfig #foreign clay "Cla
|
||||
_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";
|
||||
_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";
|
||||
@ -825,15 +802,6 @@ clay :: #library,no_dll "clay-jai/windows/clay";
|
||||
assert(size_of(_AlignClay_CornerRadius) == 20, "_AlignClay_CornerRadius has size % instead of 20", size_of(_AlignClay_CornerRadius));
|
||||
}
|
||||
|
||||
{
|
||||
instance: _AlignClay__ElementConfigType;
|
||||
assert(((cast(*void)(*instance.c)) - cast(*void)(*instance)) == 0, "_AlignClay__ElementConfigType.c has unexpected offset % instead of 0", ((cast(*void)(*instance.c)) - cast(*void)(*instance)));
|
||||
assert(size_of(type_of(_AlignClay__ElementConfigType.c)) == 1, "_AlignClay__ElementConfigType.c has unexpected size % instead of 1", size_of(type_of(_AlignClay__ElementConfigType.c)));
|
||||
assert(((cast(*void)(*instance.x)) - cast(*void)(*instance)) == 4, "_AlignClay__ElementConfigType.x has unexpected offset % instead of 4", ((cast(*void)(*instance.x)) - cast(*void)(*instance)));
|
||||
assert(size_of(type_of(_AlignClay__ElementConfigType.x)) == 4, "_AlignClay__ElementConfigType.x has unexpected size % instead of 4", size_of(type_of(_AlignClay__ElementConfigType.x)));
|
||||
assert(size_of(_AlignClay__ElementConfigType) == 8, "_AlignClay__ElementConfigType has size % instead of 8", size_of(_AlignClay__ElementConfigType));
|
||||
}
|
||||
|
||||
{
|
||||
instance: _AlignClay_LayoutDirection;
|
||||
assert(((cast(*void)(*instance.c)) - cast(*void)(*instance)) == 0, "_AlignClay_LayoutDirection.c has unexpected offset % instead of 0", ((cast(*void)(*instance.c)) - cast(*void)(*instance)));
|
||||
|
Loading…
Reference in New Issue
Block a user