Skip to content

Commit cd4f936

Browse files
committed
- layout
- moved `Text Filter()` after `"Disable block"` - switched `packedChars` to Array<> - fixed bug in `buildWithStbTrueType`, forgot to slice properly (didn't drop the tail)
1 parent 6e3f1d7 commit cd4f936

File tree

5 files changed

+51
-54
lines changed

5 files changed

+51
-54
lines changed

core/src/main/kotlin/imgui/demo/ShowDemoWindowLayout.kt

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
@file:OptIn(ExperimentalStdlibApi::class)
2+
13
package imgui.demo
24

3-
import glm_.has
45
import glm_.L
56
import glm_.f
7+
import glm_.has
68
import glm_.i
79
import glm_.vec2.Vec2
810
import glm_.vec4.Vec4
@@ -44,7 +46,6 @@ import imgui.ImGui.invisibleButton
4446
import imgui.ImGui.io
4547
import imgui.ImGui.isDragging
4648
import imgui.ImGui.isItemActive
47-
import imgui.ImGui.isItemHovered
4849
import imgui.ImGui.itemRectMax
4950
import imgui.ImGui.itemRectSize
5051
import imgui.ImGui.listBox
@@ -73,7 +74,6 @@ import imgui.ImGui.setScrollFromPosX
7374
import imgui.ImGui.setScrollFromPosY
7475
import imgui.ImGui.setScrollHereX
7576
import imgui.ImGui.setScrollHereY
76-
import imgui.ImGui.setTooltip
7777
import imgui.ImGui.smallButton
7878
import imgui.ImGui.spacing
7979
import imgui.ImGui.style
@@ -122,8 +122,8 @@ object ShowDemoWindowLayout {
122122
treeNode("Groups") {
123123

124124
helpMarker("BeginGroup() basically locks the horizontal position for new line. " +
125-
"EndGroup() bundles the whole group so that you can use \"item\" functions such as " +
126-
"IsItemHovered()/IsItemActive() or SameLine() etc. on the whole group.")
125+
"EndGroup() bundles the whole group so that you can use \"item\" functions such as " +
126+
"IsItemHovered()/IsItemActive() or SameLine() etc. on the whole group.")
127127
beginGroup()
128128
group {
129129
button("AAA")
@@ -164,9 +164,8 @@ object ShowDemoWindowLayout {
164164

165165
run {
166166
bulletText("Text baseline:")
167-
sameLine(); helpMarker(
168-
"This is testing the vertical alignment that gets applied on text to keep it aligned with widgets. " +
169-
"Lines only composed of text or \"small\" widgets use less vertical space than lines with framed widgets.")
167+
sameLine(); helpMarker("This is testing the vertical alignment that gets applied on text to keep it aligned with widgets. " +
168+
"Lines only composed of text or \"small\" widgets use less vertical space than lines with framed widgets.")
170169
indent {
171170

172171
text("KO Blahblah"); sameLine()
@@ -607,11 +606,10 @@ object ShowDemoWindowLayout {
607606

608607
// Horizontal scroll functions
609608
spacing()
610-
helpMarker(
611-
"Use SetScrollHereX() or SetScrollFromPosX() to scroll to a given horizontal position.\n\n" +
612-
"Because the clipping rectangle of most window hides half worth of WindowPadding on the " +
613-
"left/right, using SetScrollFromPosX(+1) will usually result in clipped text whereas the " +
614-
"equivalent SetScrollFromPosY(+1) wouldn't.")
609+
helpMarker("Use SetScrollHereX() or SetScrollFromPosX() to scroll to a given horizontal position.\n\n" +
610+
"Because the clipping rectangle of most window hides half worth of WindowPadding on the " +
611+
"left/right, using SetScrollFromPosX(+1) will usually result in clipped text whereas the " +
612+
"equivalent SetScrollFromPosY(+1) wouldn't.")
615613
pushID("##HorizontalScrolling")
616614
for (i in 0..4) {
617615
val childHeight = textLineHeight + style.scrollbarSize + style.windowPadding.y * 2f
@@ -641,9 +639,8 @@ object ShowDemoWindowLayout {
641639

642640
// Miscellaneous Horizontal Scrolling Demo
643641

644-
helpMarker(
645-
"Horizontal scrolling for a window is enabled via the ImGuiWindowFlags_HorizontalScrollbar flag.\n\n" +
646-
"You may want to also explicitly specify content width by using SetNextWindowContentWidth() before Begin().")
642+
helpMarker("Horizontal scrolling for a window is enabled via the ImGuiWindowFlags_HorizontalScrollbar flag.\n\n" +
643+
"You may want to also explicitly specify content width by using SetNextWindowContentWidth() before Begin().")
647644
slider("Lines", ::lines, 1, 15)
648645
pushStyleVar(StyleVar.FrameRounding, 3f)
649646
pushStyleVar(StyleVar.FramePadding, Vec2(2f, 1f))
@@ -655,7 +652,7 @@ object ShowDemoWindowLayout {
655652
// the cursor position yourself, aka using SetCursorPos/SetCursorScreenPos to position the widgets
656653
// yourself. You may also want to use the lower-level ImDrawList API.
657654
val numButtons = 10 + (line * if (line has 1) 9 else 3)
658-
for (n in 0 until numButtons) {
655+
for (n in 0..<numButtons) {
659656
if (n > 0) sameLine()
660657
pushID(n + line * 1000)
661658
val label = if (n % 15 == 0) "FizzBuzz" else if (n % 3 == 0) "Fizz" else if (n % 5 == 0) "Buzz" else "$n"
@@ -780,16 +777,15 @@ object ShowDemoWindowLayout {
780777
drag2("size", size, 0.5f, 1f, 200f, "%.0f")
781778
textWrapped("(Click and drag to scroll)")
782779

783-
helpMarker(
784-
"(Left) Using ImGui::PushClipRect():\n" +
785-
"Will alter ImGui hit-testing logic + ImDrawList rendering.\n" +
786-
"(use this if you want your clipping rectangle to affect interactions)\n\n" +
787-
"(Center) Using ImDrawList::PushClipRect():\n" +
788-
"Will alter ImDrawList rendering only.\n" +
789-
"(use this as a shortcut if you are only using ImDrawList calls)\n\n" +
790-
"(Right) Using ImDrawList::AddText() with a fine ClipRect:\n" +
791-
"Will alter only this specific ImDrawList::AddText() rendering.\n" +
792-
"This is often used internally to avoid altering the clipping rectangle and minimize draw calls.")
780+
helpMarker("(Left) Using ImGui::PushClipRect():\n" +
781+
"Will alter ImGui hit-testing logic + ImDrawList rendering.\n" +
782+
"(use this if you want your clipping rectangle to affect interactions)\n\n" +
783+
"(Center) Using ImDrawList::PushClipRect():\n" +
784+
"Will alter ImDrawList rendering only.\n" +
785+
"(use this as a shortcut if you are only using ImDrawList calls)\n\n" +
786+
"(Right) Using ImDrawList::AddText() with a fine ClipRect:\n" +
787+
"Will alter only this specific ImDrawList::AddText() rendering.\n" +
788+
"This is often used internally to avoid altering the clipping rectangle and minimize draw calls.")
793789

794790
for (n in 0..2) {
795791
if (n > 0)

core/src/main/kotlin/imgui/demo/ShowDemoWindowWidgets.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,6 @@ object ShowDemoWindowWidgets {
239239
`Drag and Drop`()
240240
`Querying Item Status (Edited,Active,Hovered etc)`()
241241
`Querying Window Status (Focused-Hovered etc,)`()
242-
`Text Filter`()
243242

244243
// Demonstrate BeginDisabled/EndDisabled using a checkbox located at the bottom of the section (which is a bit odd:
245244
// logically we'd have this checkbox at the top of the section, but we don't want this feature to steal that space)
@@ -250,6 +249,8 @@ object ShowDemoWindowWidgets {
250249
checkbox("Disable entire section above", ::disableAll)
251250
sameLine(); helpMarker("Demonstrate using BeginDisabled()/EndDisabled() across this section.")
252251
}
252+
253+
`Text Filter`()
253254
}
254255

255256
object Basic {
@@ -700,6 +701,7 @@ object ShowDemoWindowWidgets {
700701
"Below we are displaying the font texture (which is the only texture we have access to in this demo). " +
701702
"Use the 'ImTextureID' type as storage to pass pointers or identifier to your own texture data. " +
702703
"Hover the texture for a zoomed view!")
704+
703705
// Below we are displaying the font texture because it is the only texture we have access to inside the demo!
704706
// Remember that ImTextureID is just storage for whatever you want it to be. It is essentially a value that
705707
// will be passed to the rendering backend via the ImDrawCmd structure.

core/src/main/kotlin/imgui/font/FontAtlas.kt

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ class FontAtlas {
119119
}
120120

121121
fun addFontFromMemoryTTF(fontData: CharArray, sizePixels: Float, fontCfg: FontConfig = FontConfig(), glyphRanges: Array<IntRange> = emptyArray()): Font =
122-
addFontFromMemoryTTF(ByteArray(fontData.size) { fontData[it].b }, sizePixels, fontCfg, glyphRanges)
122+
addFontFromMemoryTTF(ByteArray(fontData.size) { fontData[it].b }, sizePixels, fontCfg, glyphRanges)
123123

124124
/** @param compressedFontData still owned by caller. Compress with binary_to_compressed_c.cpp. */
125125
fun addFontFromMemoryCompressedTTF(compressedFontData: CharArray, sizePixels: Float, fontCfg: FontConfig = FontConfig(), glyphRanges: Array<IntRange> = emptyArray()): Font {
@@ -205,10 +205,10 @@ class FontAtlas {
205205
// using a hot-reloading scheme that messes up static data, store your own instance of ImFontBuilderIO somewhere
206206
// and point to it instead of pointing directly to return value of the GetBuilderXXX functions.
207207
val builderIo = fontBuilderIO ?:
208-
// #ifdef IMGUI_ENABLE_FREETYPE
209-
// TODO builderIo = ImGuiFreeType::GetBuilderForFreeType()
210-
// #elif defined(IMGUI_ENABLE_STB_TRUETYPE)
211-
getBuilderForStbTruetype()
208+
// #ifdef IMGUI_ENABLE_FREETYPE
209+
// TODO builderIo = ImGuiFreeType::GetBuilderForFreeType()
210+
// #elif defined(IMGUI_ENABLE_STB_TRUETYPE)
211+
getBuilderForStbTruetype()
212212
// #else
213213
// IM_ASSERT(0) // Invalid Build function
214214

@@ -538,7 +538,7 @@ class FontAtlas {
538538
var rects: Array<rectpack.Rect> = emptyArray()
539539

540540
/** Output glyphs */
541-
var packedChars: List<PackedChar> = emptyList()
541+
var packedChars: Array<PackedChar> = emptyArray()
542542

543543
/** Ranges as requested by user (user is allowed to request too much, e.g. 0x0020..0xFFFF) */
544544
lateinit var srcRanges: Array<IntRange>
@@ -694,8 +694,8 @@ class FontAtlas {
694694
if (srcTmp.glyphsCount == 0)
695695
continue
696696

697-
srcTmp.rects = bufRects.drop(bufRectsOutN).toTypedArray()
698-
srcTmp.packedChars = bufPackedchars.drop(bufPackedcharsOutN)
697+
srcTmp.rects = bufRects.copyOfRange(bufRectsOutN, bufRectsOutN + srcTmp.glyphsCount)
698+
srcTmp.packedChars = bufPackedchars.copyOfRange(bufPackedcharsOutN, bufPackedcharsOutN + srcTmp.glyphsCount)
699699
bufRectsOutN += srcTmp.glyphsCount
700700
bufPackedcharsOutN += srcTmp.glyphsCount
701701

@@ -706,7 +706,7 @@ class FontAtlas {
706706
firstUnicodeCodepointInRange = 0
707707
arrayOfUnicodeCodepoints = srcTmp.glyphsList.toIntArray()
708708
numChars = srcTmp.glyphsList.size
709-
chardataForRange = ArrayList(srcTmp.packedChars)
709+
chardataForRange = srcTmp.packedChars
710710
hOversample = cfg.oversample.x.ui
711711
vOversample = cfg.oversample.y.ui
712712
}
@@ -763,7 +763,7 @@ class FontAtlas {
763763

764764
// Extend texture height and mark missing glyphs as non-packed so we won't render them.
765765
// FIXME: We are not handling packing failure here (would happen if we got off TEX_HEIGHT_MAX or if a single if larger than TexWidth?)
766-
for (glyphIdx in 0 until srcTmp.glyphsCount)
766+
for (glyphIdx in 0..<srcTmp.glyphsCount)
767767
if (srcTmp.rects[glyphIdx].wasPacked != 0)
768768
texSize.y = texSize.y max (srcTmp.rects[glyphIdx].y + srcTmp.rects[glyphIdx].h)
769769
}
@@ -832,7 +832,7 @@ class FontAtlas {
832832
val q = AlignedQuad()
833833
getPackedQuad(srcTmp.packedChars, texSize.x, texSize.y, glyphIdx, q = q)
834834
dstFont.addGlyph(cfg, codepoint, q.x0 + fontOff.x, q.y0 + fontOff.y,
835-
q.x1 + fontOff.x, q.y1 + fontOff.y, q.s0, q.t0, q.s1, q.t1, pc.xAdvance)
835+
q.x1 + fontOff.x, q.y1 + fontOff.y, q.s0, q.t0, q.s1, q.t1, pc.xAdvance)
836836
}
837837
}
838838
// bufPackedchars.free()
@@ -928,7 +928,7 @@ class FontAtlas {
928928
val uv1 = Vec2()
929929
calcCustomRectUV(r, uv0, uv1)
930930
font.addGlyph(null, r.glyphID, r.glyphOffset.x, r.glyphOffset.y, r.glyphOffset.x + r.width, r.glyphOffset.y + r.height,
931-
uv0.x, uv0.y, uv1.x, uv1.y, r.glyphAdvanceX)
931+
uv0.x, uv0.y, uv1.x, uv1.y, r.glyphAdvanceX)
932932
}
933933
// Build all fonts lookup tables
934934
fonts.filter { it.dirtyLookupTables }.forEach { it.buildLookupTable() }
@@ -1113,15 +1113,15 @@ class FontAtlas {
11131113
}
11141114

11151115
val cursorDatas = arrayOf(
1116-
// Pos ........ Size ......... Offset ......
1117-
arrayOf(Vec2(0, 3), Vec2(12, 19), Vec2(0)), // MouseCursor.Arrow
1118-
arrayOf(Vec2(13, 0), Vec2(7, 16), Vec2(1, 8)), // MouseCursor.TextInput
1119-
arrayOf(Vec2(31, 0), Vec2(23), Vec2(11)), // MouseCursor.Move
1120-
arrayOf(Vec2(21, 0), Vec2(9, 23), Vec2(4, 11)), // MouseCursor.ResizeNS
1121-
arrayOf(Vec2(55, 18), Vec2(23, 9), Vec2(11, 4)), // MouseCursor.ResizeEW
1122-
arrayOf(Vec2(73, 0), Vec2(17), Vec2(8)), // MouseCursor.ResizeNESW
1123-
arrayOf(Vec2(55, 0), Vec2(17), Vec2(8)), // MouseCursor.ResizeNWSE
1124-
arrayOf(Vec2(91, 0), Vec2(17, 22), Vec2(5, 0)), // ImGuiMouseCursor_Hand
1125-
arrayOf(Vec2(109, 0), Vec2(13, 15), Vec2(6, 7))) // ImGuiMouseCursor_NotAllowed
1116+
// Pos ........ Size ......... Offset ......
1117+
arrayOf(Vec2(0, 3), Vec2(12, 19), Vec2(0)), // MouseCursor.Arrow
1118+
arrayOf(Vec2(13, 0), Vec2(7, 16), Vec2(1, 8)), // MouseCursor.TextInput
1119+
arrayOf(Vec2(31, 0), Vec2(23), Vec2(11)), // MouseCursor.Move
1120+
arrayOf(Vec2(21, 0), Vec2(9, 23), Vec2(4, 11)), // MouseCursor.ResizeNS
1121+
arrayOf(Vec2(55, 18), Vec2(23, 9), Vec2(11, 4)), // MouseCursor.ResizeEW
1122+
arrayOf(Vec2(73, 0), Vec2(17), Vec2(8)), // MouseCursor.ResizeNESW
1123+
arrayOf(Vec2(55, 0), Vec2(17), Vec2(8)), // MouseCursor.ResizeNWSE
1124+
arrayOf(Vec2(91, 0), Vec2(17, 22), Vec2(5, 0)), // ImGuiMouseCursor_Hand
1125+
arrayOf(Vec2(109, 0), Vec2(13, 15), Vec2(6, 7))) // ImGuiMouseCursor_NotAllowed
11261126
}
11271127
}

core/src/main/kotlin/imgui/stb_/new texture baking api.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class PackRange {
6565
var firstUnicodeCodepointInRange = 0 // if non-zero, then the chars are continuous, and this is the first codepoint
6666
var arrayOfUnicodeCodepoints: IntArray? = null // if non-zero, then this is an array of unicode codepoints
6767
var numChars = 0
68-
var chardataForRange: ArrayList<PackedChar> = ArrayList() // output
68+
var chardataForRange: Array<PackedChar> = emptyArray() // output
6969

7070
// don't set these, they're used internally
7171
var hOversample = 0u
@@ -146,7 +146,7 @@ fun PackContext.packSetOversampling(hOversample: UInt, vOversample: UInt) {
146146
// spc->skip_missing = skip;
147147
//}
148148

149-
fun getPackedQuad(charData: List<PackedChar>, pw: Int, ph: Int, // same data as above
149+
fun getPackedQuad(charData: Array<PackedChar>, pw: Int, ph: Int, // same data as above
150150
charIndex: Int, // character to display
151151
pos: Vec2 = Vec2(), // pointers to current position in screen pixel space
152152
q: AlignedQuad, // output: quad to draw

core/src/test/kotlin/fontAtlasTest.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
import com.aayushatharva.brotli4j.Brotli4jLoader
32
import com.aayushatharva.brotli4j.decoder.Decoder
43
import com.aayushatharva.brotli4j.decoder.DecoderJNI
@@ -33,7 +32,7 @@ class fontAtlasTest {
3332
val texPixelsAlpha8 = Decoder.decompress(value.toByteArray()).run {
3433
check(resultStatus == DecoderJNI.Status.DONE)
3534
decompressedData
36-
}
35+
}
3736

3837
for (j in atlas.texPixelsAlpha8!!.indices) {
3938
if (texPixelsAlpha8[j] != atlas.texPixelsAlpha8!![j])

0 commit comments

Comments
 (0)