Skip to content

Commit 5722cbc

Browse files
committed
Remove redundant code and improve string formatting
Several changes were made throughout different functions in the ImGui codes. A redundant itemSize() call was removed from the inputText method to improve code performance. TextureId formatting was expanded in the debugTools method to avoid truncation of longer Ids. Inconsistent usage of white spaces and indents were adjusted for standardization purpose. Several methods in DemoWindow and ShowDemoWindowWidgets files got their string representations adjusted for better readability and to avoid unintended syntax errors like unclosed quotations. A couple of unused imports were also removed from the ShowDemoWindowPopus file to clean up the code base. The for-loop in the same file was simplified for improving readability.
1 parent 898ea8a commit 5722cbc

File tree

5 files changed

+11
-14
lines changed

5 files changed

+11
-14
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -295,15 +295,15 @@ object DemoWindow {
295295
}
296296

297297
treeNode("Capture/Logging") {
298-
textWrapped("""
298+
helpMarker("""
299299
The logging API redirects all text output so you can easily capture the content of a window or a block. Tree nodes can be automatically expanded.
300-
Try opening any of the contents below in this window and then click one of the \"Log To\" button.""".trimIndent())
300+
Try opening any of the contents below in this window and then click one of the "Log To" button.""".trimIndent())
301301
logButtons()
302302

303303
helpMarker("You can also call ImGui::LogText() to output directly to the log without a visual output.")
304-
if (button("Copy \"Hello, world!\" to clipboard")) {
304+
if (button("""Copy "Hello, world!" to clipboard""")) {
305305
logToClipboard()
306-
logText("%s", "Hello, world!")
306+
logText("Hello, world!")
307307
logFinish()
308308
}
309309
}

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import imgui.ImGui.endMenu
1616
import imgui.ImGui.endMenuBar
1717
import imgui.ImGui.endPopup
1818
import imgui.ImGui.inputText
19-
import imgui.ImGui.isItemHovered
2019
import imgui.ImGui.mainViewport
2120
import imgui.ImGui.menuItem
2221
import imgui.ImGui.openPopup
@@ -29,7 +28,6 @@ import imgui.ImGui.setItemDefaultFocus
2928
import imgui.ImGui.setItemTooltip
3029
import imgui.ImGui.setNextItemWidth
3130
import imgui.ImGui.setNextWindowPos
32-
import imgui.ImGui.setTooltip
3331
import imgui.ImGui.text
3432
import imgui.ImGui.textEx
3533
import imgui.ImGui.textWrapped
@@ -160,7 +158,7 @@ object ShowDemoWindowPopups {
160158
operator fun invoke() {
161159
treeNode("Context menus") {
162160

163-
helpMarker("\"Context\" functions are simple helpers to associate a Popup to a given Item or Window identifier.")
161+
helpMarker(""""Context" functions are simple helpers to associate a Popup to a given Item or Window identifier.""")
164162

165163
// BeginPopupContextItem() is a helper to provide common/simple popup behavior of essentially doing:
166164
// if (id == 0)
@@ -176,13 +174,13 @@ object ShowDemoWindowPopups {
176174
// and BeginPopupContextItem() will use the last item ID as the popup ID.
177175
run {
178176
val names = listOf("Label1", "Label2", "Label3", "Label4", "Label5")
179-
for (n in 0..4) {
180-
selectable(names[n])
181-
if (selectable(names[n], selected == n))
177+
for (n in names.indices) {
178+
val name = names[n]
179+
if (selectable(name, selected == n))
182180
selected = n
183181
popupContextItem { // <-- use last item id as popup id
184182
selected = n
185-
text("This a popup for \"${names[n]}\"!")
183+
text("""This a popup for "$name"!""")
186184
if (button("Close"))
187185
closeCurrentPopup()
188186
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2055,7 +2055,7 @@ object ShowDemoWindowWidgets {
20552055
| "" display all lines
20562056
| "xxx" display lines containing "xxx"
20572057
| "xxx,yyy" display lines containing "xxx" or "yyy"
2058-
| "-xxx" hide lines containing "xxx"""")
2058+
| "-xxx" hide lines containing "xxx"""".trimMargin())
20592059
filter.draw()
20602060
val lines = listOf("aaa1.c", "bbb1.c", "ccc1.c", "aaa2.cpp", "bbb2.cpp", "ccc2.cpp", "abc.h", "hello, world")
20612061
for (line in lines)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ internal interface debugTools {
322322
continue
323323
}
324324

325-
var buf = "DrawCmd:%5d tris, Tex 0x%02d, ClipRect (%4.0f,%4.0f)-(%4.0f,%4.0f)".format(
325+
var buf = "DrawCmd:%5d tris, Tex 0x%016d, ClipRect (%4.0f,%4.0f)-(%4.0f,%4.0f)".format(
326326
cmd.elemCount / 3, cmd.textureId, cmd.clipRect.x, cmd.clipRect.y, cmd.clipRect.z, cmd.clipRect.w)
327327
val pcmdNodeOpen = treeNode(drawList.cmdBuffer.indexOf(cmd), buf)
328328
if (isItemHovered() && (cfg.showDrawCmdMesh || cfg.showDrawCmdBoundingBoxes) /*&& fgDrawList != null*/)

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ internal interface inputText {
136136
val backupPos = Vec2(window.dc.cursorPos)
137137
itemSize(totalBb, style.framePadding.y)
138138
if (!itemAdd(totalBb, id, frameBb, ItemFlag.Inputable)) {
139-
itemSize(totalBb, style.framePadding.y)
140139
endGroup()
141140
return false
142141
}

0 commit comments

Comments
 (0)