Skip to content

Commit

Permalink
[STB] Add static sizeof method to struct
Browse files Browse the repository at this point in the history
  • Loading branch information
squid233 committed Jul 31, 2023
1 parent ba10040 commit 8ac0c4c
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,21 @@ 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);
}

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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,21 @@ 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);
}

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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,21 @@ 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);
}

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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,21 @@ 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);
}

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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down

0 comments on commit 8ac0c4c

Please sign in to comment.