Skip to content

Commit 9fe93b3

Browse files
committed
- fixed downstream flag format
- layout - finished a renaming from a native commit - fixed demo bugs: - char printing - a misplaced `treePop` - wrong condition on some `menuItem`s - adding missing `ListBoxes` in `ShowDemoWindowWidgets` - fixed `textCharToUtf8` - expanding and amending `textCharToUtf8Inline` with pointer and size
1 parent 1e01811 commit 9fe93b3

File tree

8 files changed

+54
-64
lines changed

8 files changed

+54
-64
lines changed

core/src/main/kotlin/imgui/api/demoDebugInformations.kt

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ interface demoDebugInformations {
264264
for (columnN in 0 until table.columnsCount) {
265265
val r = Funcs.getTableRect(table, rectN, columnN)
266266
val buf = "(%6.1f,%6.1f) (%6.1f,%6.1f) Size (%6.1f,%6.1f) Col $columnN ${rectN.name}"
267-
.format(r.min.x, r.min.y, r.max.x, r.max.y, r.width, r.height)
267+
.format(r.min.x, r.min.y, r.max.x, r.max.y, r.width, r.height)
268268
selectable(buf)
269269
if (isItemHovered())
270270
foregroundDrawList.addRect(r.min - 1, r.max + 1, COL32(255, 255, 0, 255), thickness = 2f)
@@ -758,19 +758,16 @@ interface demoDebugInformations {
758758
if (io.configInputTextCursorBlink) text("io.configInputTextCursorBlink")
759759
if (io.configWindowsResizeFromEdges) text("io.configWindowsResizeFromEdges")
760760
if (io.configWindowsMoveFromTitleBarOnly) text("io.configWindowsMoveFromTitleBarOnly")
761-
if (io.configMemoryCompactTimer >= 0f) text("io.ConfigMemoryCompactTimer = %.1f",
762-
io.configMemoryCompactTimer)
761+
if (io.configMemoryCompactTimer >= 0f) text("io.ConfigMemoryCompactTimer = %.1f", io.configMemoryCompactTimer)
763762
text("io.backendFlags: 0x%08X", io.backendFlags)
764763
if (io.backendFlags has BackendFlag.HasGamepad) text(" HasGamepad")
765764
if (io.backendFlags has BackendFlag.HasMouseCursors) text(" HasMouseCursors")
766765
if (io.backendFlags has BackendFlag.HasSetMousePos) text(" HasSetMousePos")
767766
if (io.backendFlags has BackendFlag.RendererHasVtxOffset) text(" RendererHasVtxOffset") // @formatter:on
768767
separator()
769-
text("io.fonts: ${io.fonts.fonts.size} fonts, Flags: 0x%08X, TexSize: ${io.fonts.texSize.x},${io.fonts.texSize.y}",
770-
io.fonts.flags)
768+
text("io.fonts: ${io.fonts.fonts.size} fonts, Flags: 0x%08X, TexSize: ${io.fonts.texSize.x},${io.fonts.texSize.y}", io.fonts.flags)
771769
text("io.displaySize: ${io.displaySize.x},${io.displaySize.y}")
772-
text("io.displayFramebufferScale: %.2f,%.2f".format(io.displayFramebufferScale.x,
773-
io.displayFramebufferScale.y))
770+
text("io.displayFramebufferScale: %.2f,%.2f".format(io.displayFramebufferScale.x, io.displayFramebufferScale.y))
774771
separator()
775772
text("style.windowPadding: %.2f,%.2f", style.windowPadding.x, style.windowPadding.y)
776773
text("style.windowBorderSize: %.2f", style.windowBorderSize)

core/src/main/kotlin/imgui/api/widgetsSliders.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import imgui.internal.sections.ItemFlag
2424
import imgui.internal.sections.ItemStatusFlag
2525
import kool.getValue
2626
import kool.setValue
27+
import java.lang.Exception
2728
import kotlin.reflect.KMutableProperty0
2829

2930
// Widgets: Regular Sliders
@@ -90,7 +91,8 @@ interface widgetsSliders {
9091

9192
val tempInputAllowed = flags hasnt SliderFlag.NoInput
9293
ImGui.itemSize(totalBb, ImGui.style.framePadding.y)
93-
if (!ImGui.itemAdd(totalBb, id, frameBb, if (tempInputAllowed) ItemFlag.Inputable else none)) return false
94+
if (!ImGui.itemAdd(totalBb, id, frameBb, if (tempInputAllowed) ItemFlag.Inputable else none))
95+
return false
9496

9597
// Default format string when passing NULL
9698
val format = format_ ?: defaultFormat

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ object DemoWindow {
185185
//if (ImGui::MenuItem("MenuItem")) {} // You can also use MenuItem() inside a menu bar!
186186
menu("Tools") {
187187

188-
val hasDebugTools = IMGUI_DISABLE_DEBUG_TOOLS
188+
val hasDebugTools = !IMGUI_DISABLE_DEBUG_TOOLS
189189

190190
menuItem("Metrics/Debugger", "", show::metrics, hasDebugTools)
191191
menuItem("Debug Log", "", show::debugLog, hasDebugTools)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ object ShowDemoWindowWidgets {
223223
Text()
224224
Images()
225225
Combo()
226+
ListBoxes()
226227
Selectables()
227228
`Text Input`()
228229
Tabs()

core/src/main/kotlin/imgui/demo/showExampleApp/StyleEditor.kt

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,7 @@ object StyleEditor {
130130
sameLine()
131131
if (button("Revert Ref")) g.style = ref!!
132132
sameLine()
133-
helpMarker(
134-
"Save/Revert in local non-persistent storage. Default Colors definition are not affected. " + "Use \"Export\" below to save them somewhere.")
133+
helpMarker("Save/Revert in local non-persistent storage. Default Colors definition are not affected. " + "Use \"Export\" below to save them somewhere.")
135134

136135
separator()
137136

@@ -166,7 +165,7 @@ object StyleEditor {
166165
slider("GrabRounding", style::grabRounding, 0f, 12f, "%.0f")
167166
slider("TabRounding", style::tabRounding, 0f, 12f, "%.0f")
168167

169-
separatorText("Alignment")
168+
separatorText("Widgets")
170169
slider2("WindowTitleAlign", style.windowTitleAlign, 0f, 1f, "%.2f")
171170
run {
172171
val sideRef = (style.windowMenuButtonPosition.i + 1).mutableReference
@@ -185,10 +184,9 @@ object StyleEditor {
185184
sameLine(); helpMarker("Alignment applies when a button is larger than its text content.")
186185
slider2("SelectableTextAlign", style.selectableTextAlign, 0f, 1f, "%.2f")
187186
sameLine(); helpMarker("Alignment applies when a selectable is larger than its text content.")
188-
189187
slider("SeparatorTextBorderSize", style::separatorTextBorderSize, 0f, 10f, "%.0f")
190188
slider2("SeparatorTextAlign", style.separatorTextAlign, 0f, 1f, "%.2f")
191-
slider2("SeparatorTextPadding", style.separatorTextPadding, 0f, 40f, "%0.f")
189+
slider2("SeparatorTextPadding", style.separatorTextPadding, 0f, 40f, "%.0f")
192190
slider("LogSliderDeadzone", style::logSliderDeadzone, 0f, 12f, "%.0f")
193191

194192
separatorText("Misc")
@@ -205,9 +203,8 @@ object StyleEditor {
205203
for (i in Col.values()) {
206204
val col = style.colors[i]
207205
val name = i.name
208-
if (!outputOnlyModified || col != ref!!.colors[i]) logText(
209-
"colors[Col_$name]%s = Vec4(%.2f, %.2f, %.2f, %.2f)\n", " ".repeat(23 - name.length), col.x,
210-
col.y, col.z, col.w)
206+
if (!outputOnlyModified || col != ref!!.colors[i])
207+
logText("colors[Col_$name]%s = Vec4(%.2f, %.2f, %.2f, %.2f)\n", " ".repeat(23 - name.length), col.x, col.y, col.z, col.w)
211208
}
212209
logFinish()
213210
}
@@ -222,19 +219,13 @@ object StyleEditor {
222219

223220
radioButton("Opaque", alphaFlags.isEmpty) { alphaFlags = none }; sameLine()
224221
radioButton("Alpha", alphaFlags == Cef.AlphaPreview) { alphaFlags = Cef.AlphaPreview }; sameLine()
225-
radioButton("Both", alphaFlags == Cef.AlphaPreviewHalf) {
226-
alphaFlags = Cef.AlphaPreviewHalf
227-
}; sameLine()
222+
radioButton("Both", alphaFlags == Cef.AlphaPreviewHalf) { alphaFlags = Cef.AlphaPreviewHalf }; sameLine()
228223
helpMarker("""
229224
In the color list:
230225
Left-click on color square to open color picker,
231-
Right-click to open edit options menu.""".trimIndent()
232-
)
226+
Right-click to open edit options menu.""".trimIndent())
233227

234-
child(
235-
"#colors", Vec2(), true,
236-
Wf.AlwaysVerticalScrollbar or Wf.AlwaysHorizontalScrollbar or Wf._NavFlattened
237-
) {
228+
child("#colors", Vec2(), true, Wf.AlwaysVerticalScrollbar or Wf.AlwaysHorizontalScrollbar or Wf._NavFlattened) {
238229
withItemWidth(-160) {
239230
for (i in 0 until Col.COUNT) {
240231
val name = Col.values()[i].name
@@ -314,7 +305,7 @@ object StyleEditor {
314305
val segmentCount = drawList._calcCircleAutoSegmentCount(rad)
315306

316307
group {
317-
text("R: %.f\nN: ${drawList._calcCircleAutoSegmentCount(rad)}", rad)
308+
text("R: %.0f\nN: ${drawList._calcCircleAutoSegmentCount(rad)}", rad)
318309

319310
val canvasWidth = minWidgetWidth max (rad * 2f)
320311
val offsetX = floor(canvasWidth * 0.5f)
@@ -350,9 +341,7 @@ object StyleEditor {
350341

351342
fun debugNodeFont(font: Font) {
352343
val name = font.configData.getOrNull(0)?.name ?: ""
353-
val fontDetailsOpened = treeNode(font,
354-
"Font \\\"$name\\\"\\n%.2f px, %.2f px, ${font.glyphs.size} glyphs, ${font.configDataCount} file(s)",
355-
font.fontSize)
344+
val fontDetailsOpened = treeNode(font, "Font \\\"$name\\\"\\n%.2f px ${font.glyphs.size} glyphs, ${font.configDataCount} file(s)", font.fontSize)
356345
sameLine(); smallButton("Set as default") { io.fontDefault = font }
357346
if (!fontDetailsOpened)
358347
return
@@ -374,15 +363,13 @@ object StyleEditor {
374363
|(Glimmer of hope: the atlas system should hopefully be rewritten in the future to make scaling more natural and automatic.)""".trimMargin())
375364
text("Ascent: ${font.ascent}, Descent: ${font.descent}, Height: ${font.ascent - font.descent}")
376365
val cStr = ByteArray(5)
377-
text("Fallback character: '${textCharToUtf8(cStr, font.fallbackChar.code)}' (U+%04X)", font.fallbackChar)
378-
text("Ellipsis character: '${textCharToUtf8(cStr, font.ellipsisChar.code)}' (U+%04X)", font.ellipsisChar)
366+
text("Fallback character: '${textCharToUtf8(cStr, font.fallbackChar)}' (U+%04X)", font.fallbackChar.code)
367+
text("Ellipsis character: '${textCharToUtf8(cStr, font.ellipsisChar)}' (U+%04X)", font.ellipsisChar.code)
379368
val side = sqrt(font.metricsTotalSurface.f).i
380369
text("Texture Area: about ${font.metricsTotalSurface} px ~${side}x$side px")
381370
for (c in 0 until font.configDataCount)
382371
font.configData.getOrNull(c)?.let {
383-
bulletText(
384-
"Input $c: '${it.name}', Oversample: ${it.oversample}, PixelSnapH: ${it.pixelSnapH}, Offset: (%.1f,%.1f)",
385-
it.glyphOffset.x, it.glyphOffset.y)
372+
bulletText("Input $c: '${it.name}', Oversample: ${it.oversample}, PixelSnapH: ${it.pixelSnapH}, Offset: (%.1f,%.1f)", it.glyphOffset.x, it.glyphOffset.y)
386373
}
387374

388375
// Display all glyphs of the fonts in separate pages of 256 characters
@@ -409,7 +396,7 @@ object StyleEditor {
409396
val drawList = windowDrawList
410397
for (n in 0 until 256) {
411398
val cellP1 = Vec2(basePos.x + (n % 16) * (cellSize + cellSpacing),
412-
basePos.y + (n / 16) * (cellSize + cellSpacing))
399+
basePos.y + (n / 16) * (cellSize + cellSpacing))
413400
val cellP2 = Vec2(cellP1.x + cellSize, cellP1.y + cellSize)
414401
val glyph = font.findGlyphNoFallback((base + n).c)
415402
drawList.addRect(cellP1, cellP2, COL32(255, 255, 255, if (glyph != null) 100 else 50)) // We use ImFont::RenderChar as a shortcut because we don't have UTF-8 conversion functions
@@ -432,7 +419,7 @@ object StyleEditor {
432419
}
433420
base += 256
434421
}
435-
treePop()
436422
}
423+
treePop()
437424
}
438425
}

core/src/main/kotlin/imgui/internal/api/debugTools.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,8 +433,8 @@ internal interface debugTools {
433433
"(Glimmer of hope: the atlas system will be rewritten in the future to make scaling more flexible.)")
434434
text("Ascent: ${font.ascent}, Descent: ${font.descent}, Height: ${font.ascent - font.descent}")
435435
val cStr = ByteArray(5)
436-
text("Fallback character: '${textCharToUtf8(cStr, font.fallbackChar.code).cStr}' (U+%04X)", font.fallbackChar)
437-
text("Ellipsis character: '${textCharToUtf8(cStr, font.ellipsisChar.code)}' (U+%04X)", font.ellipsisChar)
436+
text("Fallback character: '${textCharToUtf8(cStr, font.fallbackChar)}' (U+%04X)", font.fallbackChar.code)
437+
text("Ellipsis character: '${textCharToUtf8(cStr, font.ellipsisChar)}' (U+%04X)", font.ellipsisChar.code)
438438
val surfaceSqrt = sqrt(font.metricsTotalSurface.f).i
439439
text("Texture Area: about ${font.metricsTotalSurface} px ~${surfaceSqrt}x$surfaceSqrt px")
440440
for (configI in 0 until font.configDataCount)

core/src/main/kotlin/imgui/internal/api/templateFunctions.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,8 +437,11 @@ internal interface templateFunctions {
437437
}
438438
}
439439

440+
441+
// ~SliderScalarN
440442
inline fun widgetN(label: String, components: Int, widgets: (Int) -> Boolean): Boolean {
441-
if (currentWindow.skipItems) return false
443+
if (currentWindow.skipItems)
444+
return false
442445

443446
var valueChanged = false
444447
group {

core/src/main/kotlin/imgui/internal/generic helpers.kt

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ val Char.isBlankW: Boolean
255255
// -----------------------------------------------------------------------------------------------------------------
256256

257257
fun formatString(buf: ByteArray, fmt: String, vararg args: Any): Int {
258-
val bytes = fmt.format(*args).toByteArray()
258+
val bytes = fmt.format(*args.map { if (it is Flag<*>) it.i else it }.toTypedArray()).toByteArray()
259259
bytes.copyInto(buf) // TODO IndexOutOfBoundsException?
260260
return bytes.size.also { w -> buf[w] = 0 }
261261
}
@@ -379,53 +379,53 @@ fun parseFormatPrecision(fmt: String, defaultPrecision: Int): Int {
379379
// -----------------------------------------------------------------------------------------------------------------
380380

381381
/* return out_buf */
382-
fun textCharToUtf8(outBuf: ByteArray, c: Int): ByteArray {
383-
val count = textCharToUtf8Inline(outBuf, 5, c)
382+
fun textCharToUtf8(outBuf: ByteArray, c: Char): String {
383+
val count = textCharToUtf8Inline(outBuf, size = 5, c = c.code)
384384
outBuf[count] = 0
385-
return outBuf
385+
return outBuf.cStr
386386
}
387387

388388
/** return output UTF-8 bytes count */
389389
fun textStrToUtf8(outBuf: ByteArray, text: CharArray): Int {
390-
var b = 0
390+
var bufP = 0
391391
var t = 0
392-
while (b < outBuf.size && t < text.size && text[t] != NUL) {
392+
while (bufP < outBuf.size && t < text.size && text[t] != NUL) {
393393
val c = text[t++].code
394394
if (c < 0x80)
395-
outBuf[b++] = c.b
395+
outBuf[bufP++] = c.b
396396
else
397-
b += textCharToUtf8Inline(outBuf, b, c)
397+
bufP += textCharToUtf8Inline(outBuf, ptr = bufP, c = c)
398398
}
399-
if (b < outBuf.size) outBuf[b] = 0
400-
return b
399+
if (bufP < outBuf.size) outBuf[bufP] = 0
400+
return bufP
401401
}
402402

403403
/** Based on stb_to_utf8() from github.com/nothings/stb/
404404
* ~ImTextCharToUtf8 */
405-
fun textCharToUtf8Inline(buf: ByteArray, b: Int, c: Int): Int {
405+
fun textCharToUtf8Inline(buf: ByteArray, ptr: Int = 0, size: Int = buf.size, c: Int): Int {
406406
if (c < 0x80) {
407-
buf[b + 0] = c.b
407+
buf[ptr + 0] = c.b
408408
return 1
409409
}
410410
if (c < 0x800) {
411-
if (buf.size < b + 2) return 0
412-
buf[b + 0] = (0xc0 + (c ushr 6)).b
413-
buf[b + 1] = (0x80 + (c and 0x3f)).b
411+
if (size < ptr + 2) return 0
412+
buf[ptr + 0] = (0xc0 + (c ushr 6)).b
413+
buf[ptr + 1] = (0x80 + (c and 0x3f)).b
414414
return 2
415415
}
416416
if (c < 0x10000) {
417-
if (buf.size < 3) return 0
418-
buf[b + 0] = (0xe0 + (c ushr 12)).b
419-
buf[b + 1] = (0x80 + ((c ushr 6) and 0x3f)).b
420-
buf[b + 2] = (0x80 + (c and 0x3f)).b
417+
if (size < 3) return 0
418+
buf[ptr + 0] = (0xe0 + (c ushr 12)).b
419+
buf[ptr + 1] = (0x80 + ((c ushr 6) and 0x3f)).b
420+
buf[ptr + 2] = (0x80 + (c and 0x3f)).b
421421
return 3
422422
}
423423
if (c <= 0x10FFFF) {
424-
if (buf.size < b + 4) return 0
425-
buf[b + 0] = (0xf0 + (c ushr 18)).b
426-
buf[b + 1] = (0x80 + ((c ushr 12) and 0x3f)).b
427-
buf[b + 2] = (0x80 + ((c ushr 6) and 0x3f)).b
428-
buf[b + 3] = (0x80 + (c and 0x3f)).b
424+
if (size < ptr + 4) return 0
425+
buf[ptr + 0] = (0xf0 + (c ushr 18)).b
426+
buf[ptr + 1] = (0x80 + ((c ushr 12) and 0x3f)).b
427+
buf[ptr + 2] = (0x80 + ((c ushr 6) and 0x3f)).b
428+
buf[ptr + 3] = (0x80 + (c and 0x3f)).b
429429
return 4
430430
}
431431
// Invalid code point, the max unicode is 0x10FFFF

0 commit comments

Comments
 (0)