Update clay & odin, remove custom sdl3_ttf bindings, fix example, small changes to borders

This commit is contained in:
shan
2025-07-04 13:22:36 -07:00
parent 1691845199
commit 13cf8df027
11 changed files with 80 additions and 232 deletions

View File

@@ -103,7 +103,7 @@ TextAlignment :: enum EnumBackingType {
}
TextElementConfig :: struct {
userData: rawptr,
userData: rawptr,
textColor: Color,
fontId: u16,
fontSize: u16,
@@ -113,9 +113,12 @@ TextElementConfig :: struct {
textAlignment: TextAlignment,
}
AspectRatioElementConfig :: struct {
aspectRatio: f32,
}
ImageElementConfig :: struct {
imageData: rawptr,
sourceDimensions: Dimensions,
}
CustomElementConfig :: struct {
@@ -135,9 +138,10 @@ BorderElementConfig :: struct {
width: BorderWidth,
}
ScrollElementConfig :: struct {
horizontal: bool,
vertical: bool,
ClipElementConfig :: struct {
horizontal: bool, // clip overflowing elements on the "X" axis
vertical: bool, // clip overflowing elements on the "Y" axis
childOffset: Vector2, // offsets the [X,Y] positions of all child elements, primarily for scrolling containers
}
FloatingAttachPointType :: enum EnumBackingType {
@@ -169,6 +173,11 @@ FloatingAttachToElement :: enum EnumBackingType {
Root,
}
FloatingClipToElement :: enum EnumBackingType {
None,
AttachedParent,
}
FloatingElementConfig :: struct {
offset: Vector2,
expand: Dimensions,
@@ -177,6 +186,7 @@ FloatingElementConfig :: struct {
attachment: FloatingAttachPoints,
pointerCaptureMode: PointerCaptureMode,
attachTo: FloatingAttachToElement,
clipTo: FloatingClipToElement,
}
TextRenderData :: struct {
@@ -196,7 +206,6 @@ RectangleRenderData :: struct {
ImageRenderData :: struct {
backgroundColor: Color,
cornerRadius: CornerRadius,
sourceDimensions: Dimensions,
imageData: rawptr,
}
@@ -235,7 +244,7 @@ ScrollContainerData :: struct {
scrollPosition: ^Vector2,
scrollContainerDimensions: Dimensions,
contentDimensions: Dimensions,
config: ScrollElementConfig,
config: ClipElementConfig,
// Indicates whether an actual scroll container matched the provided ID or if the default struct was returned.
found: bool,
}
@@ -329,16 +338,17 @@ ClayArray :: struct($type: typeid) {
}
ElementDeclaration :: struct {
id: ElementId,
layout: LayoutConfig,
id: ElementId,
layout: LayoutConfig,
backgroundColor: Color,
cornerRadius: CornerRadius,
image: ImageElementConfig,
floating: FloatingElementConfig,
custom: CustomElementConfig,
scroll: ScrollElementConfig,
border: BorderElementConfig,
userData: rawptr,
cornerRadius: CornerRadius,
aspectRatio: AspectRatioElementConfig,
image: ImageElementConfig,
floating: FloatingElementConfig,
custom: CustomElementConfig,
clip: ClipElementConfig,
border: BorderElementConfig,
userData: rawptr,
}
ErrorType :: enum EnumBackingType {
@@ -385,6 +395,7 @@ foreign Clay {
Hovered :: proc() -> bool ---
OnHover :: proc(onHoverFunction: proc "c" (id: ElementId, pointerData: PointerData, userData: rawptr), userData: rawptr) ---
PointerOver :: proc(id: ElementId) -> bool ---
GetScrollOffset :: proc() -> Vector2 ---
GetScrollContainerData :: proc(id: ElementId) -> ScrollContainerData ---
SetMeasureTextFunction :: proc(measureTextFunction: proc "c" (text: StringSlice, config: ^TextElementConfig, userData: rawptr) -> Dimensions, userData: rawptr) ---
SetQueryScrollOffsetFunction :: proc(queryScrollOffsetFunction: proc "c" (elementId: u32, userData: rawptr) -> Vector2, userData: rawptr) ---
@@ -437,6 +448,14 @@ PaddingAll :: proc(allPadding: u16) -> Padding {
return { left = allPadding, right = allPadding, top = allPadding, bottom = allPadding }
}
BorderOutside :: proc(width: u16) -> BorderWidth {
return {width, width, width, width, 0}
}
BorderAll :: proc(width: u16) -> BorderWidth {
return {width, width, width, width, width}
}
CornerRadiusAll :: proc(radius: f32) -> CornerRadius {
return CornerRadius{radius, radius, radius, radius}
}
@@ -467,4 +486,4 @@ ID :: proc(label: string, index: u32 = 0) -> ElementId {
ID_LOCAL :: proc(label: string, index: u32 = 0) -> ElementId {
return _HashString(MakeString(label), index, _GetParentElementId())
}
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -1,184 +0,0 @@
package sdl3_ttf
import sdl "vendor:sdl3"
import "core:c"
foreign import lib "system:SDL3_ttf"
Font :: struct {}
Text :: struct {
text: cstring,
num_lines: c.int,
refcount: c.int,
internal: rawptr,
}
TextEngine :: struct {}
Direction :: enum c.int {
LTR = 0,
RTL,
TTB,
BTT,
}
// Normal == empty
FontStyleFlag :: enum u32 {
BOLD = 0,
ITALIC = 1,
UNDERLINE = 2,
STRIKETHROUGH = 3,
}
FontStyleFlags :: bit_set[FontStyleFlag;u32]
FONT_STYLE_NORMAL :: FontStyleFlags{}
FONT_STYLE_BOLD :: FontStyleFlags{.BOLD}
FONT_STYLE_ITALIC :: FontStyleFlags{.ITALIC}
FONT_STYLE_UNDERLINE :: FontStyleFlags{.UNDERLINE}
FONT_STYLE_STRIKETHROUGH :: FontStyleFlags{.STRIKETHROUGH}
HintingFlags :: enum c.int {
NORMAL = 0,
LIGHT,
MONO,
NONE,
LIGHT_SUBPIXEL,
}
TTF_PROP_FONT_OUTLINE_LINE_CAP_NUMBER :: "SDL_ttf.font.outline.line_cap"
TTF_PROP_FONT_OUTLINE_LINE_JOIN_NUMBER :: "SDL_ttf.font.outline.line_join"
TTF_PROP_FONT_OUTLINE_MITER_LIMIT_NUMBER :: "SDL_ttf.font.outline.miter_limit"
HorizontalAlignment :: enum c.int {
INVALID = -1,
LEFT,
CENTER,
RIGHT,
}
GPUAtlasDrawSequence :: struct {
atlas_texture: ^sdl.GPUTexture,
vertex_positions: [^]sdl.FPoint,
uvs: [^]sdl.FPoint, // Normalized
num_verticies: c.int,
indices: [^]c.int,
num_indices: c.int,
next: ^GPUAtlasDrawSequence, // If nil, this is the last text in the sequence
}
GPUTextEngineWinding :: enum c.int {
INVALID = -1,
CLOCKWISE,
COUNTERCLOCKWISE,
}
SubStringFlag :: enum u32 {
TEXT_START,
LINE_START,
LINE_END,
TEXT_END,
}
SubString :: struct {
flags: SubStringFlag,
offset: c.int,
length: c.int,
line_index: c.int,
cluster_index: c.int,
rect: sdl.Rect,
}
/// General
@(default_calling_convention = "c", link_prefix = "TTF_")
foreign lib {
Init :: proc() -> bool ---
CreateGPUTextEngine :: proc(device: ^sdl.GPUDevice) -> ^TextEngine ---
DestroyGPUTextEngine :: proc(engine: ^TextEngine) ---
Quit :: proc() ---
}
/// Fonts
@(default_calling_convention = "c", link_prefix = "TTF_")
foreign lib {
CloseFont :: proc(font: ^Font) ---
FontHasGlyph :: proc(font: ^Font, glyph: u32) -> bool ---
FontIsFixedWidth :: proc(font: ^Font) -> bool ---
GetFontAscent :: proc(font: ^Font) -> c.int ---
GetFontDescent :: proc(font: ^Font) -> c.int ---
GetFontDirection :: proc(font: ^Font) -> Direction ---
GetFontDPI :: proc(font: ^Font, hdpi: ^c.int, vdpi: ^c.int) -> bool ---
GetFontFamilyName :: proc(font: ^Font) -> cstring ---
GetFontGeneration :: proc(font: ^Font) -> u32 ---
GetFontHeight :: proc(font: ^Font) -> c.int ---
GetFontHinting :: proc(font: ^Font) -> HintingFlags ---
GetFontKerning :: proc(font: ^Font) -> bool ---
/// Returns the font's recommended spacing
GetFontLineSkip :: proc(font: ^Font) -> c.int ---
GetFontOutline :: proc(font: ^Font) -> c.int ---
GetFontProperties :: proc(font: ^Font) -> sdl.PropertiesID ---
GetFontSize :: proc(font: ^Font) -> f32 ---
GetFontStyle :: proc(font: ^Font) -> FontStyleFlags ---
GetFontStyleName :: proc(font: ^Font) -> cstring ---
GetFontWrapAlignment :: proc(font: ^Font) -> HorizontalAlignment ---
GetFreeTypeVersion :: proc(major: ^c.int, minor: ^c.int, patch: ^c.int) ---
GetGlyphMetrics :: proc(font: ^Font, glyph: u32, min_x: ^c.int, max_x: ^c.int, min_y: ^c.int, max_y: ^c.int, advance: ^c.int) -> bool ---
GetGlyphScript :: proc(glyph: u32, script: ^c.char, script_size: c.size_t) -> bool ---
/// `stream`: A `sdl.IOStream` to provide a font's file data
/// `close_io`: Close src when the font is closed, false to leave it open
/// `point_size`: Font point size to use for the newly-opened font
OpenFontIO :: proc(stream: ^sdl.IOStream, close_io: bool, point_size: f32) -> ^Font ---
OpenFont :: proc(file: cstring, point_size: f32) -> ^Font ---
SetFontDirection :: proc(font: ^Font, direction: Direction) -> bool ---
SetFontHinting :: proc(font: ^Font, hinting_flags: HintingFlags) ---
SetFontKerning :: proc(font: ^Font, enabled: bool) ---
SetFontLineSkip :: proc(font: ^Font, lineskip: c.int) ---
SetFontOutline :: proc(font: ^Font, outline: c.int) -> bool ---
SetFontScript :: proc(font: ^Font, script: cstring) -> bool ---
SetFontSize :: proc(font: ^Font, pt_size: f32) -> bool ---
SetFontSizeDPI :: proc(font: ^Font, pt_size: f32, hdpi: c.int, vdpi: c.int) -> bool ---
SetFontStyle :: proc(font: ^Font, style: FontStyleFlags) ---
SetFontWrapAlignment :: proc(font: ^Font, horizontal_alignment: HorizontalAlignment) ---
SetGPUTextEngineWinding :: proc(engine: ^TextEngine, winding: GPUTextEngineWinding) ---
}
/// Text
@(default_calling_convention = "c", link_prefix = "TTF_")
foreign lib {
AppendTextString :: proc(text: ^Text, str: cstring, length: c.size_t) -> bool ---
CreateText :: proc(engine: ^TextEngine, font: ^Font, text: cstring, length: c.size_t) -> ^Text ---
DeleteTextString :: proc(text: ^Text, offset: c.int, length: c.int) -> bool ---
DestroyText :: proc(text: ^Text) ---
GetGPUTextDrawData :: proc(text: ^Text) -> ^GPUAtlasDrawSequence ---
GetGPUTextEngineWinding :: proc(engine: ^TextEngine) -> GPUTextEngineWinding ---
GetNextTextSubString :: proc(text: ^Text, substring: ^SubString, next: ^SubString) -> bool ---
GetPreviousTextSubString :: proc(text: ^Text, substring: ^SubString, previous: ^SubString) -> bool ---
/// Calculate the dimensions of a rendered string of UTF-8 text.
GetStringSize :: proc(font: ^Font, text: cstring, length: c.size_t, w: ^c.int, h: ^c.int) -> bool ---
GetStringSizeWrapped :: proc(font: ^Font, text: cstring, length: c.size_t, wrap_width: c.int, w: ^c.int, h: ^c.int) -> bool ---
GetTextColor :: proc(text: ^Text, r: ^u8, g: ^u8, b: ^u8, a: ^u8) -> bool ---
GetTextColorFloat :: proc(text: ^Text, r: ^f32, g: ^f32, b: ^f32, a: ^f32) -> bool ---
GetTextEngine :: proc(text: ^Text) -> ^TextEngine ---
GetTextFont :: proc(text: ^Text) -> ^Font ---
GetTextPosition :: proc(text: ^Text, x: ^c.int, y: ^c.int) -> bool ---
GetTextProperties :: proc(text: ^Text) -> sdl.PropertiesID ---
GetTextSize :: proc(text: ^Text, width: ^c.int, height: ^c.int) -> bool ---
GetTextSubString :: proc(text: ^Text, offset: c.int, substring: ^SubString) -> bool ---
GetTextSubStringForLine :: proc(text: ^Text, line: c.int, substring: ^SubString) -> bool ---
GetTextSubStringForPoint :: proc(text: ^Text, x: c.int, y: c.int, substring: ^SubString) -> bool ---
GetTextSubStringsForRange :: proc(text: ^Text, offset: c.int, length: c.int, count: ^c.int) -> [^]^SubString ---
GetTextWrapping :: proc(text: ^Text, wrap_length: ^c.int) -> bool ---
GetTextWrapWidth :: proc(text: ^Text, wrap_width: ^c.int) -> bool ---
InsertTextString :: proc(text: ^Text, offset: c.int, str: cstring, length: c.size_t) -> bool ---
// Calculate how much of a UTF-8 string will fit in a given width.
MeasureString :: proc(font: ^Font, text: cstring, length: c.size_t, max_width: c.int, measured_width: ^c.int, measured_length: ^c.size_t) -> bool ---
SetTextColor :: proc(text: ^Text, r: u8, g: u8, b: u8, a: u8) -> bool ---
SetTextColorFloat :: proc(text: ^Text, r: f32, g: f32, b: f32, a: f32) -> bool ---
SetTextEngine :: proc(text: ^Text, engine: ^TextEngine) -> bool ---
SetTextFont :: proc(text: ^Text, font: ^Font) -> bool ---
SetTextPosition :: proc(text: ^Text, x: c.int, y: c.int) -> bool ---
SetTextString :: proc(text: ^Text, str: cstring, length: c.size_t) -> bool ---
SetTextWrapping :: proc(text: ^Text, wrap_length: c.int) -> bool ---
SetTextWrapWhitespaceVisible :: proc(text: ^Text, visible: bool) -> bool ---
SetTextWrapWidth :: proc(text: ^Text, wrap_width: c.int) -> bool ---
}