Change c types to odin types when size is always known

This commit is contained in:
FourteenBrush 2024-08-31 20:59:00 +02:00
parent bdbe005ffc
commit 732ae76ef7
No known key found for this signature in database
GPG Key ID: DF8312C105596025

View File

@ -31,8 +31,8 @@ Dimensions :: struct {
Arena :: struct { Arena :: struct {
label: String, label: String,
nextAllocation: c.uint64_t, nextAllocation: u64,
capacity: c.uint64_t, capacity: u16,
memory: [^]c.char, memory: [^]c.char,
} }
@ -53,7 +53,7 @@ CornerRadius :: struct {
} }
BorderData :: struct { BorderData :: struct {
width: c.uint32_t, width: u32,
color: Color, color: Color,
} }
@ -75,10 +75,10 @@ RectangleElementConfig :: struct {
TextElementConfig :: struct { TextElementConfig :: struct {
textColor: Color, textColor: Color,
fontId: c.uint16_t, fontId: u16,
fontSize: c.uint16_t, fontSize: u16,
letterSpacing: c.uint16_t, letterSpacing: u16,
lineSpacing: c.uint16_t, lineSpacing: u16,
} }
ImageElementConfig :: struct { ImageElementConfig :: struct {
@ -100,8 +100,8 @@ BorderElementConfig :: struct {
} }
ScrollElementConfig :: struct { ScrollElementConfig :: struct {
horizontal: c.bool, horizontal: bool,
vertical: c.bool, vertical: bool,
} }
FloatingAttachPointType :: enum u8 { FloatingAttachPointType :: enum u8 {
@ -124,8 +124,8 @@ FloatingAttachPoints :: struct {
FloatingElementConfig :: struct { FloatingElementConfig :: struct {
offset: Vector2, offset: Vector2,
expand: Dimensions, expand: Dimensions,
zIndex: c.uint16_t, zIndex: u16,
parentId: c.uint32_t, parentId: u32,
attachment: FloatingAttachPoints, attachment: FloatingAttachPoints,
} }
@ -141,7 +141,7 @@ RenderCommand :: struct {
boundingBox: BoundingBox, boundingBox: BoundingBox,
config: ElementConfigUnion, config: ElementConfigUnion,
text: String, text: String,
id: c.uint32_t, id: u32,
commandType: RenderCommandType, commandType: RenderCommandType,
} }
@ -153,7 +153,7 @@ ScrollContainerData :: struct {
contentDimensions: Dimensions, contentDimensions: Dimensions,
config: ScrollElementConfig, config: ScrollElementConfig,
// Indicates whether an actual scroll container matched the provided ID or if the default struct was returned. // Indicates whether an actual scroll container matched the provided ID or if the default struct was returned.
found: c.bool, found: bool,
} }
SizingType :: enum u8 { SizingType :: enum u8 {
@ -184,8 +184,8 @@ Sizing :: struct {
} }
Padding :: struct { Padding :: struct {
x: c.uint16_t, x: u16,
y: c.uint16_t, y: u16,
} }
LayoutDirection :: enum u8 { LayoutDirection :: enum u8 {
@ -213,30 +213,30 @@ ChildAlignment :: struct {
LayoutConfig :: struct { LayoutConfig :: struct {
sizing: Sizing, sizing: Sizing,
padding: Padding, padding: Padding,
childGap: c.uint16_t, childGap: u16,
layoutDirection: LayoutDirection, layoutDirection: LayoutDirection,
childAlignment: ChildAlignment, childAlignment: ChildAlignment,
} }
ClayArray :: struct($type: typeid) { ClayArray :: struct($type: typeid) {
capacity: c.uint32_t, capacity: u32,
length: c.uint32_t, length: u32,
internalArray: [^]type, internalArray: [^]type,
} }
@(link_prefix = "Clay_", default_calling_convention = "c") @(link_prefix = "Clay_", default_calling_convention = "c")
foreign Clay { foreign Clay {
MinMemorySize :: proc() -> c.uint32_t --- MinMemorySize :: proc() -> u32 ---
CreateArenaWithCapacityAndMemory :: proc(capacity: c.uint32_t, offset: [^]u8) -> Arena --- CreateArenaWithCapacityAndMemory :: proc(capacity: u32, offset: [^]u8) -> Arena ---
SetPointerPosition :: proc(position: Vector2) --- SetPointerPosition :: proc(position: Vector2) ---
Initialize :: proc(arena: Arena) --- Initialize :: proc(arena: Arena) ---
UpdateScrollContainers :: proc(isPointerActive: c.bool, scrollDelta: Vector2, deltaTime: c.float) --- UpdateScrollContainers :: proc(isPointerActive: bool, scrollDelta: Vector2, deltaTime: c.float) ---
BeginLayout :: proc(screenWidth: c.int, screenHeight: c.int) --- BeginLayout :: proc(screenWidth: c.int, screenHeight: c.int) ---
EndLayout :: proc(screenWidth: c.int, screenHeight: c.int) -> ClayArray(RenderCommand) --- EndLayout :: proc(screenWidth: c.int, screenHeight: c.int) -> ClayArray(RenderCommand) ---
PointerOver :: proc(id: c.uint32_t) -> c.bool --- PointerOver :: proc(id: u32) -> bool ---
GetScrollContainerData :: proc(id: c.uint32_t) -> ScrollContainerData --- GetScrollContainerData :: proc(id: u32) -> ScrollContainerData ---
SetMeasureTextFunction :: proc(measureTextFunction: proc(text: ^String, config: ^TextElementConfig) -> Dimensions) --- SetMeasureTextFunction :: proc(measureTextFunction: proc(text: ^String, config: ^TextElementConfig) -> Dimensions) ---
RenderCommandArray_Get :: proc(array: ^ClayArray(RenderCommand), index: c.int32_t) -> ^RenderCommand --- RenderCommandArray_Get :: proc(array: ^ClayArray(RenderCommand), index: i32) -> ^RenderCommand ---
} }
@(private, link_prefix = "Clay_", default_calling_convention = "c") @(private, link_prefix = "Clay_", default_calling_convention = "c")
@ -253,14 +253,14 @@ foreign {
@(link_prefix = "Clay_", default_calling_convention = "c", private) @(link_prefix = "Clay_", default_calling_convention = "c", private)
foreign Clay { foreign Clay {
_OpenContainerElement :: proc(id: c.uint32_t, layoutConfig: ^LayoutConfig) --- _OpenContainerElement :: proc(id: u32, layoutConfig: ^LayoutConfig) ---
_OpenRectangleElement :: proc(id: c.uint32_t, layoutConfig: ^LayoutConfig, rectangleConfig: ^RectangleElementConfig) --- _OpenRectangleElement :: proc(id: u32, layoutConfig: ^LayoutConfig, rectangleConfig: ^RectangleElementConfig) ---
_OpenTextElement :: proc(id: c.uint32_t, text: String, textConfig: ^TextElementConfig) --- _OpenTextElement :: proc(id: u32, text: String, textConfig: ^TextElementConfig) ---
_OpenImageElement :: proc(id: c.uint32_t, layoutConfig: ^LayoutConfig, imageConfig: ^ImageElementConfig) --- _OpenImageElement :: proc(id: u32, layoutConfig: ^LayoutConfig, imageConfig: ^ImageElementConfig) ---
_OpenScrollElement :: proc(id: c.uint32_t, layoutConfig: ^LayoutConfig, imageConfig: ^ScrollElementConfig) --- _OpenScrollElement :: proc(id: u32, layoutConfig: ^LayoutConfig, imageConfig: ^ScrollElementConfig) ---
_OpenFloatingElement :: proc(id: c.uint32_t, layoutConfig: ^LayoutConfig, imageConfig: ^FloatingElementConfig) --- _OpenFloatingElement :: proc(id: u32, layoutConfig: ^LayoutConfig, imageConfig: ^FloatingElementConfig) ---
_OpenBorderElement :: proc(id: c.uint32_t, layoutConfig: ^LayoutConfig, imageConfig: ^BorderElementConfig) --- _OpenBorderElement :: proc(id: u32, layoutConfig: ^LayoutConfig, imageConfig: ^BorderElementConfig) ---
_OpenCustomElement :: proc(id: c.uint32_t, layoutConfig: ^LayoutConfig, imageConfig: ^CustomElementConfig) --- _OpenCustomElement :: proc(id: u32, layoutConfig: ^LayoutConfig, imageConfig: ^CustomElementConfig) ---
_CloseElementWithChildren :: proc() --- _CloseElementWithChildren :: proc() ---
_CloseScrollElement :: proc() --- _CloseScrollElement :: proc() ---
_CloseFloatingElement :: proc() --- _CloseFloatingElement :: proc() ---
@ -272,17 +272,17 @@ foreign Clay {
_CustomElementConfigArray_Add :: proc(array: ^ClayArray(CustomElementConfig), config: CustomElementConfig) -> ^CustomElementConfig --- _CustomElementConfigArray_Add :: proc(array: ^ClayArray(CustomElementConfig), config: CustomElementConfig) -> ^CustomElementConfig ---
_ScrollElementConfigArray_Add :: proc(array: ^ClayArray(ScrollElementConfig), config: ScrollElementConfig) -> ^ScrollElementConfig --- _ScrollElementConfigArray_Add :: proc(array: ^ClayArray(ScrollElementConfig), config: ScrollElementConfig) -> ^ScrollElementConfig ---
_BorderElementConfigArray_Add :: proc(array: ^ClayArray(BorderElementConfig), config: BorderElementConfig) -> ^BorderElementConfig --- _BorderElementConfigArray_Add :: proc(array: ^ClayArray(BorderElementConfig), config: BorderElementConfig) -> ^BorderElementConfig ---
_HashString :: proc(toHash: String, index: c.uint32_t) -> c.uint32_t --- _HashString :: proc(toHash: String, index: u32) -> u32 ---
} }
@(require_results, deferred_none = _CloseElementWithChildren) @(require_results, deferred_none = _CloseElementWithChildren)
Container :: proc(id: c.uint32_t, layoutConfig: ^LayoutConfig) -> bool { Container :: proc(id: u32, layoutConfig: ^LayoutConfig) -> bool {
_OpenContainerElement(id, layoutConfig) _OpenContainerElement(id, layoutConfig)
return true return true
} }
@(require_results, deferred_none = _CloseElementWithChildren) @(require_results, deferred_none = _CloseElementWithChildren)
Rectangle :: proc(id: c.uint32_t, layoutConfig: ^LayoutConfig, rectangleConfig: ^RectangleElementConfig) -> bool { Rectangle :: proc(id: u32, layoutConfig: ^LayoutConfig, rectangleConfig: ^RectangleElementConfig) -> bool {
_OpenRectangleElement(id, layoutConfig, rectangleConfig) _OpenRectangleElement(id, layoutConfig, rectangleConfig)
return true return true
} }
@ -293,31 +293,31 @@ Text :: proc(id: u32, text: string, textConfig: ^TextElementConfig) -> bool {
} }
@(require_results, deferred_none = _CloseElementWithChildren) @(require_results, deferred_none = _CloseElementWithChildren)
Image :: proc(id: c.uint32_t, layoutConfig: ^LayoutConfig, imageConfig: ^ImageElementConfig) -> bool { Image :: proc(id: u32, layoutConfig: ^LayoutConfig, imageConfig: ^ImageElementConfig) -> bool {
_OpenImageElement(id, layoutConfig, imageConfig) _OpenImageElement(id, layoutConfig, imageConfig)
return true return true
} }
@(require_results, deferred_none = _CloseScrollElement) @(require_results, deferred_none = _CloseScrollElement)
Scroll :: proc(id: c.uint32_t, layoutConfig: ^LayoutConfig, scrollConfig: ^ScrollElementConfig) -> bool { Scroll :: proc(id: u32, layoutConfig: ^LayoutConfig, scrollConfig: ^ScrollElementConfig) -> bool {
_OpenScrollElement(id, layoutConfig, scrollConfig) _OpenScrollElement(id, layoutConfig, scrollConfig)
return true return true
} }
@(require_results, deferred_none = _CloseFloatingElement) @(require_results, deferred_none = _CloseFloatingElement)
Floating :: proc(id: c.uint32_t, layoutConfig: ^LayoutConfig, floatingConfig: ^FloatingElementConfig) -> bool { Floating :: proc(id: u32, layoutConfig: ^LayoutConfig, floatingConfig: ^FloatingElementConfig) -> bool {
_OpenFloatingElement(id, layoutConfig, floatingConfig) _OpenFloatingElement(id, layoutConfig, floatingConfig)
return true return true
} }
@(require_results, deferred_none = _CloseElementWithChildren) @(require_results, deferred_none = _CloseElementWithChildren)
Border :: proc(id: c.uint32_t, layoutConfig: ^LayoutConfig, borderConfig: ^BorderElementConfig) -> bool { Border :: proc(id: u32, layoutConfig: ^LayoutConfig, borderConfig: ^BorderElementConfig) -> bool {
_OpenBorderElement(id, layoutConfig, borderConfig) _OpenBorderElement(id, layoutConfig, borderConfig)
return true return true
} }
@(require_results, deferred_none = _CloseElementWithChildren) @(require_results, deferred_none = _CloseElementWithChildren)
Custom :: proc(id: c.uint32_t, layoutConfig: ^LayoutConfig, customConfig: ^CustomElementConfig) -> bool { Custom :: proc(id: u32, layoutConfig: ^LayoutConfig, customConfig: ^CustomElementConfig) -> bool {
_OpenCustomElement(id, layoutConfig, customConfig) _OpenCustomElement(id, layoutConfig, customConfig)
return true return true
} }