From 8ac0c4c00bcb33a261cfc64b3c1eeffeffb40099 Mon Sep 17 00:00:00 2001 From: squid233 <60126026+squid233@users.noreply.github.com> Date: Mon, 31 Jul 2023 22:57:21 +0800 Subject: [PATCH] [STB] Add static sizeof method to struct --- .../src/main/java/overrungl/stb/STBTTAlignedQuad.java | 7 +++++++ .../src/main/java/overrungl/stb/STBTTBakedChar.java | 9 ++++++++- .../src/main/java/overrungl/stb/STBTTKerningEntry.java | 9 ++++++++- .../src/main/java/overrungl/stb/STBTTPackRange.java | 9 ++++++++- .../src/main/java/overrungl/stb/STBTTPackedChar.java | 9 ++++++++- .../src/main/java/overrungl/stb/STBTTVertex.java | 7 +++++++ 6 files changed, 46 insertions(+), 4 deletions(-) diff --git a/modules/overrungl.stb/src/main/java/overrungl/stb/STBTTAlignedQuad.java b/modules/overrungl.stb/src/main/java/overrungl/stb/STBTTAlignedQuad.java index 681197c2..0cd1257b 100644 --- a/modules/overrungl.stb/src/main/java/overrungl/stb/STBTTAlignedQuad.java +++ b/modules/overrungl.stb/src/main/java/overrungl/stb/STBTTAlignedQuad.java @@ -67,6 +67,13 @@ public STBTTAlignedQuad(MemorySegment address) { super(address, LAYOUT); } + /** + * {@return the elements size of this struct in bytes} + */ + public static long sizeof() { + return LAYOUT.byteSize(); + } + public static STBTTAlignedQuad create(SegmentAllocator allocator) { return new STBTTAlignedQuad(allocator.allocate(LAYOUT)); } diff --git a/modules/overrungl.stb/src/main/java/overrungl/stb/STBTTBakedChar.java b/modules/overrungl.stb/src/main/java/overrungl/stb/STBTTBakedChar.java index 50d66c57..cdd44e92 100644 --- a/modules/overrungl.stb/src/main/java/overrungl/stb/STBTTBakedChar.java +++ b/modules/overrungl.stb/src/main/java/overrungl/stb/STBTTBakedChar.java @@ -62,7 +62,7 @@ public sealed class STBTTBakedChar extends Struct { yoff = LAYOUT.varHandle(PathElement.groupElement("yoff")), xadvance = LAYOUT.varHandle(PathElement.groupElement("xadvance")); - public STBTTBakedChar(MemorySegment address, MemoryLayout layout) { + protected STBTTBakedChar(MemorySegment address, MemoryLayout layout) { super(address, layout); } @@ -70,6 +70,13 @@ public STBTTBakedChar(MemorySegment address) { super(address, LAYOUT); } + /** + * {@return the elements size of this struct in bytes} + */ + public static long sizeof() { + return LAYOUT.byteSize(); + } + public static Buffer create(SegmentAllocator allocator, long count) { return new Buffer(allocator.allocateArray(LAYOUT, count), count); } diff --git a/modules/overrungl.stb/src/main/java/overrungl/stb/STBTTKerningEntry.java b/modules/overrungl.stb/src/main/java/overrungl/stb/STBTTKerningEntry.java index 8d2d94d4..5620f22e 100644 --- a/modules/overrungl.stb/src/main/java/overrungl/stb/STBTTKerningEntry.java +++ b/modules/overrungl.stb/src/main/java/overrungl/stb/STBTTKerningEntry.java @@ -54,7 +54,7 @@ public sealed class STBTTKerningEntry extends Struct { glyph2 = LAYOUT.varHandle(PathElement.groupElement("glyph2")), advance = LAYOUT.varHandle(PathElement.groupElement("advance")); - public STBTTKerningEntry(MemorySegment address, MemoryLayout layout) { + protected STBTTKerningEntry(MemorySegment address, MemoryLayout layout) { super(address, layout); } @@ -62,6 +62,13 @@ public STBTTKerningEntry(MemorySegment address) { super(address, LAYOUT); } + /** + * {@return the elements size of this struct in bytes} + */ + public static long sizeof() { + return LAYOUT.byteSize(); + } + public int glyph1() { return (int) glyph1.get(segment()); } diff --git a/modules/overrungl.stb/src/main/java/overrungl/stb/STBTTPackRange.java b/modules/overrungl.stb/src/main/java/overrungl/stb/STBTTPackRange.java index 01ed1c2a..6b150060 100644 --- a/modules/overrungl.stb/src/main/java/overrungl/stb/STBTTPackRange.java +++ b/modules/overrungl.stb/src/main/java/overrungl/stb/STBTTPackRange.java @@ -65,7 +65,7 @@ public sealed class STBTTPackRange extends Struct { num_chars = LAYOUT.varHandle(PathElement.groupElement("num_chars")), chardata_for_range = LAYOUT.varHandle(PathElement.groupElement("chardata_for_range")); - public STBTTPackRange(MemorySegment address, MemoryLayout layout) { + protected STBTTPackRange(MemorySegment address, MemoryLayout layout) { super(address, layout); } @@ -73,6 +73,13 @@ public STBTTPackRange(MemorySegment address) { super(address, LAYOUT); } + /** + * {@return the elements size of this struct in bytes} + */ + public static long sizeof() { + return LAYOUT.byteSize(); + } + public static STBTTPackRange create(SegmentAllocator allocator) { return new STBTTPackRange(allocator.allocate(LAYOUT)); } diff --git a/modules/overrungl.stb/src/main/java/overrungl/stb/STBTTPackedChar.java b/modules/overrungl.stb/src/main/java/overrungl/stb/STBTTPackedChar.java index ee2a5e04..cfc8a96d 100644 --- a/modules/overrungl.stb/src/main/java/overrungl/stb/STBTTPackedChar.java +++ b/modules/overrungl.stb/src/main/java/overrungl/stb/STBTTPackedChar.java @@ -67,7 +67,7 @@ public sealed class STBTTPackedChar extends Struct { xoff2 = LAYOUT.varHandle(PathElement.groupElement("xoff2")), yoff2 = LAYOUT.varHandle(PathElement.groupElement("yoff2")); - public STBTTPackedChar(MemorySegment address, MemoryLayout layout) { + protected STBTTPackedChar(MemorySegment address, MemoryLayout layout) { super(address, layout); } @@ -75,6 +75,13 @@ public STBTTPackedChar(MemorySegment address) { super(address, LAYOUT); } + /** + * {@return the elements size of this struct in bytes} + */ + public static long sizeof() { + return LAYOUT.byteSize(); + } + public static Buffer create(SegmentAllocator allocator, long count) { return new Buffer(allocator.allocateArray(LAYOUT, count), count); } diff --git a/modules/overrungl.stb/src/main/java/overrungl/stb/STBTTVertex.java b/modules/overrungl.stb/src/main/java/overrungl/stb/STBTTVertex.java index b16bd20f..1a951946 100644 --- a/modules/overrungl.stb/src/main/java/overrungl/stb/STBTTVertex.java +++ b/modules/overrungl.stb/src/main/java/overrungl/stb/STBTTVertex.java @@ -66,6 +66,13 @@ public STBTTVertex(MemorySegment address) { super(address, LAYOUT); } + /** + * {@return the elements size of this struct in bytes} + */ + public static long sizeof() { + return LAYOUT.byteSize(); + } + public short x() { return (short) x.get(segment()); }