Skip to content

Commit d44d214

Browse files
committed
Update format in font/misc.kt
Improved readability of the misc.kt file in the 'imgui' application by adding space between variable declarations. Refactored several arrays for better code alignment. No changes to functionality were made in this commit, this is purely a refactor for better code style and readability.
1 parent cd4f936 commit d44d214

File tree

15 files changed

+343
-348
lines changed

15 files changed

+343
-348
lines changed

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

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -266,15 +266,14 @@ interface demoDebugInformations {
266266
for (columnN in 0 until table.columnsCount) {
267267
val r = Funcs.getTableRect(table, rectN, columnN)
268268
val buf = "(%6.1f,%6.1f) (%6.1f,%6.1f) Size (%6.1f,%6.1f) Col $columnN ${rectN.name}"
269-
.format(r.min.x, r.min.y, r.max.x, r.max.y, r.width, r.height)
269+
.format(r.min.x, r.min.y, r.max.x, r.max.y, r.width, r.height)
270270
selectable(buf)
271271
if (isItemHovered())
272272
foregroundDrawList.addRect(r.min - 1, r.max + 1, COL32(255, 255, 0, 255), thickness = 2f)
273273
}
274274
} else {
275275
val r = Funcs.getTableRect(table, rectN, -1)
276-
val buf = "(%6.1f,%6.1f) (%6.1f,%6.1f) Size (%6.1f,%6.1f) ${rectN.name}".format(
277-
r.min.x, r.min.y, r.max.x, r.max.y, r.width, r.height)
276+
val buf = "(%6.1f,%6.1f) (%6.1f,%6.1f) Size (%6.1f,%6.1f) ${rectN.name}".format(r.min.x, r.min.y, r.max.x, r.max.y, r.width, r.height)
278277
selectable(buf)
279278
if (isItemHovered())
280279
foregroundDrawList.addRect(r.min - 1, r.max + 1, COL32(255, 255, 0, 255), thickness = 2f)
@@ -801,14 +800,14 @@ interface demoDebugInformations {
801800
*
802801
* add style selector block (not a window), essentially a combo listing the default styles. */
803802
operator fun invoke(label: String) =
804-
if (combo(label, ::styleIdx, "Dark\u0000Light\u0000Classic\u0000")) {
805-
when (styleIdx) {
806-
0 -> styleColorsDark()
807-
1 -> styleColorsLight()
808-
2 -> styleColorsClassic()
809-
}
810-
true
811-
} else false
803+
if (combo(label, ::styleIdx, "Dark\u0000Light\u0000Classic\u0000")) {
804+
when (styleIdx) {
805+
0 -> styleColorsDark()
806+
1 -> styleColorsLight()
807+
2 -> styleColorsClassic()
808+
}
809+
true
810+
} else false
812811
}
813812

814813
/** Demo helper function to select among loaded fonts.

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ interface main {
338338
if (g.dragDropActive) {
339339
val isDelivered = g.dragDropPayload.delivery
340340
val isElapsed = g.dragDropPayload.dataFrameCount + 1 < g.frameCount &&
341-
(g.dragDropSourceFlags has DragDropFlag.SourceAutoExpirePayload || !g.dragDropMouseButton.isDown)
341+
(g.dragDropSourceFlags has DragDropFlag.SourceAutoExpirePayload || !g.dragDropMouseButton.isDown)
342342
if (isDelivered || isElapsed)
343343
clearDragDrop()
344344
}
@@ -362,7 +362,7 @@ interface main {
362362
g.windowsTempSortBuffer.clear()
363363
g.windowsTempSortBuffer.ensureCapacity(g.windows.size)
364364
g.windows.filter { !it.active || it.flags hasnt Wf._ChildWindow } // if a child is active its parent will add it
365-
.forEach { it addToSortBuffer g.windowsTempSortBuffer }
365+
.forEach { it addToSortBuffer g.windowsTempSortBuffer }
366366
assert(g.windows.size == g.windowsTempSortBuffer.size) { "This usually assert if there is a mismatch between the ImGuiWindowFlags_ChildWindow / ParentWindow values and DC.ChildWindows[] in parents, aka we've done something wrong." }
367367
g.windows.clear()
368368
g.windows += g.windowsTempSortBuffer
@@ -408,16 +408,15 @@ interface main {
408408
renderDimmedBackgrounds()
409409

410410
// Add ImDrawList to render
411-
val windowsToRenderTopMost = arrayOf(
412-
g.navWindowingTarget?.rootWindow?.takeIf { it.flags has Wf.NoBringToFrontOnFocus },
413-
g.navWindowingTarget?.let { g.navWindowingListWindow })
411+
val windowsToRenderTopMost = arrayOf(g.navWindowingTarget?.rootWindow?.takeIf { it.flags has Wf.NoBringToFrontOnFocus },
412+
g.navWindowingTarget?.let { g.navWindowingListWindow })
414413
g.windows
415-
.filter { it.isActiveAndVisible && it.flags hasnt Wf._ChildWindow && it !== windowsToRenderTopMost[0] && it !== windowsToRenderTopMost[1] }
416-
.forEach { it.addRootToDrawData() }
414+
.filter { it.isActiveAndVisible && it.flags hasnt Wf._ChildWindow && it !== windowsToRenderTopMost[0] && it !== windowsToRenderTopMost[1] }
415+
.forEach { it.addRootToDrawData() }
417416
windowsToRenderTopMost
418-
.filterNotNull()
419-
.filter { it.isActiveAndVisible } // NavWindowingTarget is always temporarily displayed as the top-most window
420-
.forEach { it.addRootToDrawData() }
417+
.filterNotNull()
418+
.filter { it.isActiveAndVisible } // NavWindowingTarget is always temporarily displayed as the top-most window
419+
.forEach { it.addRootToDrawData() }
421420

422421
// Draw software mouse cursor if requested by io.MouseDrawCursor flag
423422
if (g.io.mouseDrawCursor && firstRenderOfFrame && g.mouseCursor != MouseCursor.None)

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,7 @@ interface widgetsDrags {
271271

272272
val labelSize = ImGui.calcTextSize(label, hideTextAfterDoubleHash = true)
273273
val frameBb = Rect(window.dc.cursorPos, window.dc.cursorPos + Vec2(w, labelSize.y + style.framePadding.y * 2f))
274-
val totalBb = Rect(
275-
frameBb.min, frameBb.max + Vec2(if (labelSize.x > 0f) style.itemInnerSpacing.x + labelSize.x else 0f, 0f)
276-
)
274+
val totalBb = Rect(frameBb.min, frameBb.max + Vec2(if (labelSize.x > 0f) style.itemInnerSpacing.x + labelSize.x else 0f, 0f))
277275

278276
val tempInputAllowed = flags hasnt SliderFlag.NoInput
279277
ImGui.itemSize(totalBb, ImGui.style.framePadding.y)
@@ -339,7 +337,7 @@ interface widgetsDrags {
339337
if (labelSize.x > 0f)
340338
ImGui.renderText(Vec2(frameBb.max.x + ImGui.style.itemInnerSpacing.x, frameBb.min.y + ImGui.style.framePadding.y), label)
341339

342-
IMGUI_TEST_ENGINE_ITEM_INFO(id, label, g.lastItemData.statusFlags / if(tempInputAllowed) ItemStatusFlag.Inputable else none)
340+
IMGUI_TEST_ENGINE_ITEM_INFO(id, label, g.lastItemData.statusFlags / if (tempInputAllowed) ItemStatusFlag.Inputable else none)
343341
return valueChanged
344342
}
345343
}
@@ -351,7 +349,7 @@ inline fun <reified N> drag(label: String,
351349
max: N? = null,
352350
format_: String? = null,
353351
flags: SliderFlags = none): Boolean where N : Number, N : Comparable<N> =
354-
ImGui.drag(label, pData, vSpeed, min, max, format_, flags)
352+
ImGui.drag(label, pData, vSpeed, min, max, format_, flags)
355353

356354
inline fun <reified N> ImGui.drag(label: String,
357355
pData: KMutableProperty0<N>,
@@ -360,7 +358,7 @@ inline fun <reified N> ImGui.drag(label: String,
360358
max: N? = null,
361359
format_: String? = null,
362360
flags: SliderFlags = none): Boolean where N : Number, N : Comparable<N> =
363-
numberOps<N>().drag(label, pData, vSpeed, min, max, format_, flags)
361+
numberOps<N>().drag(label, pData, vSpeed, min, max, format_, flags)
364362

365363
/** Note: p_data, p_min and p_max are _pointers_ to a memory address holding the data. For a Drag widget,
366364
* p_min and p_max are optional.
@@ -374,7 +372,7 @@ inline fun <reified N> dragN(label: String,
374372
format: String? = null,
375373
flags: SliderFlags = none,
376374
properties: (Int) -> KMutableProperty0<N>): Boolean where N : Number, N : Comparable<N> =
377-
ImGui.dragN(label, components, vSpeed, min, max, format, flags, properties)
375+
ImGui.dragN(label, components, vSpeed, min, max, format, flags, properties)
378376

379377
/** Note: p_data, p_min and p_max are _pointers_ to a memory address holding the data. For a Drag widget,
380378
* p_min and p_max are optional.
@@ -388,7 +386,7 @@ inline fun <reified N> ImGui.dragN(label: String,
388386
format: String? = null,
389387
flags: SliderFlags = none,
390388
properties: (Int) -> KMutableProperty0<N>): Boolean where N : Number, N : Comparable<N> =
391-
numberOps<N>().dragN(label, components, vSpeed, min, max, format, flags, properties)
389+
numberOps<N>().dragN(label, components, vSpeed, min, max, format, flags, properties)
392390

393391
inline fun <N> NumberOps<N>.dragN(label: String,
394392
components: Int,
@@ -398,4 +396,4 @@ inline fun <N> NumberOps<N>.dragN(label: String,
398396
format: String? = null,
399397
flags: SliderFlags = none,
400398
properties: (Int) -> KMutableProperty0<N>): Boolean where N : Number, N : Comparable<N> =
401-
widgetN(label, components) { i -> drag("", properties(i), vSpeed, min, max, format, flags) }
399+
widgetN(label, components) { i -> drag("", properties(i), vSpeed, min, max, format, flags) }

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,9 +277,9 @@ interface windows {
277277
else -> style.windowBorderSize
278278
}
279279
window.windowPadding put style.windowPadding
280-
if (flags has Wf._ChildWindow && !(flags has (Wf.AlwaysUseWindowPadding or Wf._Popup)) && window.windowBorderSize == 0f) window.windowPadding.put(
281-
0f,
282-
if (flags has Wf.MenuBar) style.windowPadding.y else 0f)
280+
if (flags has Wf._ChildWindow && !(flags has (Wf.AlwaysUseWindowPadding or Wf._Popup)) && window.windowBorderSize == 0f)
281+
window.windowPadding.put(0f,
282+
if (flags has Wf.MenuBar) style.windowPadding.y else 0f)
283283

284284
// Lock menu offset so size calculation can use it as menu-bar windows need a minimum size.
285285
window.dc.menuBarOffset.x = (window.windowPadding.x max style.itemSpacing.x) max g.nextWindowData.menuBarOffsetMinVal.x

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ object DemoWindow {
205205
bulletText("Sections below are demonstrating many aspects of the library.")
206206
bulletText("The \"Examples\" menu above leads to more demo contents.")
207207
bulletText("The \"Tools\" menu above gives access to: About Box, Style Editor,\n" +
208-
"and Metrics/Debugger (general purpose Dear ImGui debugging tool).")
208+
"and Metrics/Debugger (general purpose Dear ImGui debugging tool).")
209209

210210
separatorText("PROGRAMMER GUIDE:")
211211
bulletText("See the ShowDemoWindow() code in imgui_demo.cpp. <- you are here!")
@@ -274,11 +274,9 @@ object DemoWindow {
274274
spacing()
275275
}
276276
treeNode("Backend Flags") {
277-
helpMarker(
278-
"""
277+
helpMarker("""
279278
Those flags are set by the backends (imgui_impl_xxx files) to specify their capabilities.
280-
Here we expose them as read-only fields to avoid breaking interactions with your backend.""".trimIndent()
281-
)
279+
Here we expose them as read-only fields to avoid breaking interactions with your backend.""".trimIndent())
282280

283281
// FIXME: Maybe we need a BeginReadonly() equivalent to keep label bright?
284282
beginDisabled()

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

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ object ShowDemoWindowInputs {
4949
setNextItemOpen(true, Cond.Once)
5050
treeNode("Inputs") {
5151
helpMarker("This is a simplified view. See more detailed input state:\n" +
52-
"- in 'Tools->Metrics/Debugger->Inputs'.\n" +
53-
"- in 'Tools->Debug Log->IO'.")
52+
"- in 'Tools->Metrics/Debugger->Inputs'.\n" +
53+
"- in 'Tools->Debug Log->IO'.")
5454
if (isMousePosValid())
5555
text("Mouse pos: (%g, %g)", io.mousePos.x, io.mousePos.y)
5656
else
@@ -86,13 +86,12 @@ object ShowDemoWindowInputs {
8686
// IMGUI_DEMO_MARKER("Inputs & Focus/Outputs");
8787
setNextItemOpen(true, Cond.Once)
8888
treeNode("Outputs") {
89-
helpMarker(
90-
"The value of io.WantCaptureMouse and io.WantCaptureKeyboard are normally set by Dear ImGui " +
91-
"to instruct your application of how to route inputs. Typically, when a value is true, it means " +
92-
"Dear ImGui wants the corresponding inputs and we expect the underlying application to ignore them.\n\n" +
93-
"The most typical case is: when hovering a window, Dear ImGui set io.WantCaptureMouse to true, " +
94-
"and underlying application should ignore mouse inputs (in practice there are many and more subtle " +
95-
"rules leading to how those flags are set).")
89+
helpMarker("The value of io.WantCaptureMouse and io.WantCaptureKeyboard are normally set by Dear ImGui " +
90+
"to instruct your application of how to route inputs. Typically, when a value is true, it means " +
91+
"Dear ImGui wants the corresponding inputs and we expect the underlying application to ignore them.\n\n" +
92+
"The most typical case is: when hovering a window, Dear ImGui set io.WantCaptureMouse to true, " +
93+
"and underlying application should ignore mouse inputs (in practice there are many and more subtle " +
94+
"rules leading to how those flags are set).")
9695
text("io.WantCaptureMouse: ${io.wantCaptureMouse.i}")
9796
text("io.WantCaptureMouseUnlessPopupClose: ${io.wantCaptureMouseUnlessPopupClose.i}")
9897
text("io.WantCaptureKeyboard: ${io.wantCaptureKeyboard.i}")
@@ -102,9 +101,8 @@ object ShowDemoWindowInputs {
102101

103102
// IMGUI_DEMO_MARKER("Inputs & Focus/Outputs/WantCapture override");
104103
treeNode("WantCapture override") {
105-
helpMarker(
106-
"Hovering the colored canvas will override io.WantCaptureXXX fields.\n" +
107-
"Notice how normally (when set to none), the value of io.WantCaptureKeyboard would be false when hovering and true when clicking.")
104+
helpMarker("Hovering the colored canvas will override io.WantCaptureXXX fields.\n" +
105+
"Notice how normally (when set to none), the value of io.WantCaptureKeyboard would be false when hovering and true when clicking.")
108106
val captureOverrideDesc = listOf("None", "Set to false", "Set to true")
109107
setNextItemWidth(ImGui.fontSize * 15)
110108
slider("SetNextFrameWantCaptureMouse() on hover", ::captureOverrideMouse, -1, +1, captureOverrideDesc[captureOverrideMouse + 1], SliderFlag.AlwaysClamp)
@@ -133,8 +131,8 @@ object ShowDemoWindowInputs {
133131

134132
text("Hover to see mouse cursors:")
135133
sameLine(); helpMarker("Your application can render a different mouse cursor based on what ImGui::GetMouseCursor() returns. " +
136-
"If software cursor rendering (io.MouseDrawCursor) is set ImGui will draw the right cursor for you, " +
137-
"otherwise your backend needs to handle it.")
134+
"If software cursor rendering (io.MouseDrawCursor) is set ImGui will draw the right cursor for you, " +
135+
"otherwise your backend needs to handle it.")
138136
for (i in 0 until MouseCursor.COUNT) {
139137
val cursor = MouseCursor of i
140138
val label = "Mouse cursor $i: $cursor"
@@ -175,6 +173,7 @@ object ShowDemoWindowInputs {
175173
}
176174
}
177175
}
176+
178177
object Tabbing {
179178
var buf = "hello".toByteArray(32)
180179
operator fun invoke() {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,7 @@ object ShowDemoWindowPopups {
9393
// This may be a bit confusing at first but it should quickly make sense. Follow on the examples below.
9494
treeNode("Popups") {
9595

96-
textWrapped(
97-
"When a popup is active, it inhibits interacting with windows that are behind the popup. " +
96+
textWrapped("When a popup is active, it inhibits interacting with windows that are behind the popup. " +
9897
"Clicking outside the popup closes it.")
9998

10099
val names = arrayOf("Bream", "Haddock", "Mackerel", "Pollock", "Tilefish")
@@ -155,6 +154,7 @@ object ShowDemoWindowPopups {
155154
object `Context Menus` {
156155
var selected = -1
157156
var value = 0.5f
157+
158158
// [JVM] this needs to by a ByteArray to hold a reference, since Strings are final by design
159159
var name = "Label1"
160160
operator fun invoke() {

0 commit comments

Comments
 (0)