Skip to content

Commit 2627287

Browse files
committed
- renamed some demo objects
- implemented single word double click selection (and fixed it) ocornut/imgui#2244
1 parent fdea4bd commit 2627287

File tree

12 files changed

+46
-42
lines changed

12 files changed

+46
-42
lines changed

imgui-core/src/main/kotlin/imgui/demo/ExampleApp.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import imgui.ImGui.text
2929
import imgui.ImGui.textWrapped
3030
import imgui.ImGui.time
3131
import imgui.api.demoDebugInformations.Companion.helpMarker
32+
import imgui.api.g
3233
import imgui.classes.TextFilter
3334
import imgui.dsl.collapsingHeader
3435
import imgui.dsl.menu
@@ -253,11 +254,11 @@ object ExampleApp {
253254
}
254255

255256
// All demo contents
256-
showDemoWindowWidgets()
257-
showDemoWindowLayout()
258-
showDemoWindowPopups()
259-
showDemoWindowColumns()
260-
showDemoWindowMisc()
257+
ShowDemoWindowWidgets()
258+
ShowDemoWindowLayout()
259+
ShowDemoWindowPopups()
260+
ShowDemoWindowColumns()
261+
ShowDemoWindowMisc()
261262

262263
// End of ShowDemoWindow()
263264
end()

imgui-core/src/main/kotlin/imgui/demo/showDemoWindowColumns.kt renamed to imgui-core/src/main/kotlin/imgui/demo/ShowDemoWindowColumns.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import imgui.dsl.collapsingHeader
3737
import imgui.dsl.selectable
3838
import imgui.dsl.treeNode
3939

40-
object showDemoWindowColumns {
40+
object ShowDemoWindowColumns {
4141

4242
/* Columns */
4343
var selected = -1

imgui-core/src/main/kotlin/imgui/demo/showDemoWindowLayout.kt renamed to imgui-core/src/main/kotlin/imgui/demo/ShowDemoWindowLayout.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ import kotlin.math.sin
107107
import imgui.InputTextFlag as Itf
108108
import imgui.WindowFlag as Wf
109109

110-
object showDemoWindowLayout {
110+
object ShowDemoWindowLayout {
111111

112112
/* Child regions */
113113
var disableMouseWheel = false

imgui-core/src/main/kotlin/imgui/demo/showDemoWindowMisc.kt renamed to imgui-core/src/main/kotlin/imgui/demo/ShowDemoWindowMisc.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import imgui.dsl.treeNode
3737
import imgui.api.demoDebugInformations.Companion.helpMarker
3838
import imgui.toByteArray
3939

40-
object showDemoWindowMisc {
40+
object ShowDemoWindowMisc {
4141

4242
/* Tabbing */
4343
var buf0 = "dummy".toByteArray(32)

imgui-core/src/main/kotlin/imgui/demo/showDemoWindowPopus.kt renamed to imgui-core/src/main/kotlin/imgui/demo/ShowDemoWindowPopus.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import imgui.dsl.withStyleVar
4141
import imgui.demo.showExampleApp.MenuFile
4242
import imgui.WindowFlag as Wf
4343

44-
object showDemoWindowPopups {
44+
object ShowDemoWindowPopups {
4545

4646
/* Popus */
4747
var selectedFish = -1

imgui-core/src/main/kotlin/imgui/demo/showDemoWindowWidgets.kt renamed to imgui-core/src/main/kotlin/imgui/demo/ShowDemoWindowWidgets.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ import imgui.ImGui.vSliderFloat
140140
import imgui.ImGui.vSliderInt
141141
import imgui.ImGui.windowDrawList
142142
import imgui.api.demoDebugInformations.Companion.helpMarker
143+
import imgui.api.g
143144
import imgui.classes.Color
144145
import imgui.classes.InputTextCallbackData
145146
import imgui.dsl.collapsingHeader
@@ -166,7 +167,7 @@ import imgui.InputTextFlag as Itf
166167
import imgui.SelectableFlag as Sf
167168
import imgui.TreeNodeFlag as Tnf
168169

169-
object showDemoWindowWidgets {
170+
object ShowDemoWindowWidgets {
170171

171172
/* Basic */
172173
var counter = 0

imgui-core/src/main/kotlin/imgui/demo/showApp.kt

Lines changed: 0 additions & 2 deletions
This file was deleted.

imgui-core/src/main/kotlin/imgui/demo/showExampleApp/Log.kt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package imgui.demo.showExampleApp
22

33
import glm_.vec2.Vec2
4-
import imgui.*
4+
import imgui.Cond
55
import imgui.ImGui.begin
66
import imgui.ImGui.beginChild
77
import imgui.ImGui.beginPopup
@@ -22,6 +22,7 @@ import imgui.ImGui.setNextWindowSize
2222
import imgui.ImGui.setScrollHereY
2323
import imgui.ImGui.smallButton
2424
import imgui.ImGui.textEx
25+
import imgui.StyleVar
2526
import imgui.api.g
2627
import imgui.classes.ListClipper
2728
import imgui.classes.TextFilter
@@ -68,8 +69,10 @@ object Log {
6869

6970
val buf = StringBuilder()
7071
val filter = TextFilter()
72+
7173
/** Index to lines offset. We maintain this with AddLog() calls, allowing us to have a random access on lines */
7274
val lineOffsets = ArrayList<Int>()
75+
7376
/** Keep scrolling if already at the bottom */
7477
var autoScroll = true
7578

@@ -130,12 +133,11 @@ object Log {
130133
}
131134
else {
132135
val clipper = ListClipper(lineOffsets.size)
133-
while(clipper.step()) {
134-
for(line_no in clipper.display) {
135-
val line = buf.subSequence(lineOffsets[line_no], if(line_no + 1 < lineOffsets.size) lineOffsets[line_no + 1] - 1 else buf.length).toString()
136-
textEx(line)
136+
while (clipper.step())
137+
for (lineNo in clipper.display) {
138+
val lineEnd = if (lineNo + 1 < lineOffsets.size) lineOffsets[lineNo + 1] - 1 else buf.length
139+
textEx(buf.subSequence(lineOffsets[lineNo], lineEnd).toString())
137140
}
138-
}
139141
clipper.end()
140142
}
141143

imgui-core/src/main/kotlin/imgui/internal/api/PopupsModalsTooltips.kt

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,16 @@ import imgui.static.navRestoreLastChildNavWindow
2727
import uno.kotlin.getValue
2828
import uno.kotlin.setValue
2929
import kotlin.reflect.KMutableProperty0
30+
import imgui.WindowFlag as Wf
3031

3132
/** Popups, Modals, Tooltips */
3233
internal interface PopupsModalsTooltips {
3334

3435
fun beginChildEx(name: String, id: ID, sizeArg: Vec2, border: Boolean, flags_: WindowFlags): Boolean {
3536

3637
val parentWindow = g.currentWindow!!
37-
var flags = WindowFlag.NoTitleBar or WindowFlag.NoResize or WindowFlag.NoSavedSettings or WindowFlag._ChildWindow
38-
flags = flags or (parentWindow.flags and WindowFlag.NoMove.i) // Inherit the NoMove flag
38+
var flags = flags_ or Wf.NoTitleBar or Wf.NoResize or Wf.NoSavedSettings or Wf._ChildWindow
39+
flags = flags or (parentWindow.flags and Wf.NoMove.i) // Inherit the NoMove flag
3940

4041
// Size
4142
val contentAvail = contentRegionAvail
@@ -68,7 +69,7 @@ internal interface PopupsModalsTooltips {
6869
parentWindow.dc.cursorPos put childWindow.pos
6970

7071
// Process navigation-in immediately so NavInit can run on first frame
71-
if (g.navActivateId == id && flags hasnt WindowFlag._NavFlattened && (childWindow.dc.navLayerActiveMask != 0 || childWindow.dc.navHasScroll)) {
72+
if (g.navActivateId == id && flags hasnt Wf._NavFlattened && (childWindow.dc.navLayerActiveMask != 0 || childWindow.dc.navHasScroll)) {
7273
focusWindow(childWindow)
7374
navInitWindow(childWindow, false)
7475
setActiveID(id + 1, childWindow) // Steal ActiveId with a dummy id so that key-press won't activate child item
@@ -154,8 +155,8 @@ internal interface PopupsModalsTooltips {
154155
popupCountToKeep++
155156
continue
156157
}
157-
assert(popup.window!!.flags has WindowFlag._Popup)
158-
if (popup.window!!.flags has WindowFlag._ChildWindow) {
158+
assert(popup.window!!.flags has Wf._Popup)
159+
if (popup.window!!.flags has Wf._ChildWindow) {
159160
popupCountToKeep++
160161
continue
161162
}
@@ -192,10 +193,10 @@ internal interface PopupsModalsTooltips {
192193

193194
var flags = flags_
194195
val name = when {
195-
flags has WindowFlag._ChildMenu -> "##Menu_%02d".format(style.locale, g.beginPopupStack.size) // Recycle windows based on depth
196+
flags has Wf._ChildMenu -> "##Menu_%02d".format(style.locale, g.beginPopupStack.size) // Recycle windows based on depth
196197
else -> "##Popup_%08x".format(style.locale, id) // Not recycling, so we can close/open during the same frame
197198
}
198-
flags = flags or WindowFlag._Popup
199+
flags = flags or Wf._Popup
199200
val isOpen = begin(name, null, flags)
200201
if (!isOpen) // NB: Begin can return false when the popup is completely clipped (e.g. zero size display)
201202
endPopup()
@@ -229,22 +230,22 @@ internal interface PopupsModalsTooltips {
229230
windowName = "##Tooltip_%02d".format(++g.tooltipOverrideCount)
230231
}
231232
}
232-
val flags = WindowFlag._Tooltip or WindowFlag.NoMouseInputs or WindowFlag.NoTitleBar or WindowFlag.NoMove or WindowFlag.NoResize or WindowFlag.NoSavedSettings or WindowFlag.AlwaysAutoResize
233+
val flags = Wf._Tooltip or Wf.NoMouseInputs or Wf.NoTitleBar or Wf.NoMove or Wf.NoResize or Wf.NoSavedSettings or Wf.AlwaysAutoResize
233234
begin(windowName, null, flags or extraFlags)
234235
}
235236

236237
/** ~GetTopMostPopupModal */
237238
val topMostPopupModal: Window?
238239
get() {
239240
for (n in g.openPopupStack.size - 1 downTo 0)
240-
g.openPopupStack[n].window?.let { if (it.flags has WindowFlag._Modal) return it }
241+
g.openPopupStack[n].window?.let { if (it.flags has Wf._Modal) return it }
241242
return null
242243
}
243244

244245
fun findBestWindowPosForPopup(window: Window): Vec2 {
245246

246247
val rOuter = window.getAllowedExtentRect()
247-
if (window.flags has WindowFlag._ChildMenu) {
248+
if (window.flags has Wf._ChildMenu) {
248249
/* Child menus typically request _any_ position within the parent menu item,
249250
and then we move the new menu outside the parent bounds.
250251
This is how we end up with child menus appearing (most-commonly) on the right of the parent menu. */
@@ -260,11 +261,11 @@ internal interface PopupsModalsTooltips {
260261
}
261262
return findBestWindowPosForPopupEx(Vec2(window.pos), window.size, window::autoPosLastDirection, rOuter, rAvoid)
262263
}
263-
if (window.flags has WindowFlag._Popup) {
264+
if (window.flags has Wf._Popup) {
264265
val rAvoid = Rect(window.pos.x - 1, window.pos.y - 1, window.pos.x + 1, window.pos.y + 1)
265266
return findBestWindowPosForPopupEx(Vec2(window.pos), window.size, window::autoPosLastDirection, rOuter, rAvoid)
266267
}
267-
if (window.flags has WindowFlag._Tooltip) {
268+
if (window.flags has Wf._Tooltip) {
268269
// Position tooltip (always follows mouse)
269270
val sc = style.mouseCursorScale
270271
val refPos = navCalcPreferredRefPos()

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ import imgui.internal.classes.InputTextState.K
5555
import imgui.internal.classes.Rect
5656
import imgui.stb.te.click
5757
import imgui.stb.te.cut
58+
import imgui.stb.te.drag
5859
import imgui.stb.te.locateCoord
5960
import imgui.stb.te.paste
6061
import uno.kotlin.getValue
@@ -64,6 +65,7 @@ import kotlin.math.max
6465
import kotlin.math.min
6566
import kotlin.reflect.KMutableProperty0
6667
import imgui.InputTextFlag as Itf
68+
import imgui.WindowFlag as Wf
6769

6870
/** InputText */
6971
internal interface inputText {
@@ -126,7 +128,7 @@ internal interface inputText {
126128
pushStyleVar(StyleVar.ChildRounding, style.frameRounding)
127129
pushStyleVar(StyleVar.ChildBorderSize, style.frameBorderSize)
128130
pushStyleVar(StyleVar.WindowPadding, style.framePadding)
129-
val childVisible = beginChildEx(label, id, frameBb.size, true, WindowFlag.NoMove or WindowFlag.AlwaysUseWindowPadding)
131+
val childVisible = beginChildEx(label, id, frameBb.size, true, Wf.NoMove or Wf.AlwaysUseWindowPadding)
130132
popStyleVar(3)
131133
popStyleColor()
132134
if (!childVisible) {
@@ -292,10 +294,10 @@ internal interface inputText {
292294

293295
// OS X style: Double click selects by word instead of selecting whole text
294296
val isOsx = io.configMacOSXBehaviors
295-
if (selectAll || (hovered && !isOsx && io.mouseDoubleClicked[0])) {
297+
if (selectAll /*|| (hovered && !isOsx && io.mouseDoubleClicked[0])*/) { // [JVM] https://github.com/ocornut/imgui/pull/2244
296298
state.selectAll()
297299
state.selectedAllMouseLock = true
298-
} else if (hovered && isOsx && io.mouseDoubleClicked[0]) {
300+
} else if (hovered /*&& isOsx*/ && io.mouseDoubleClicked[0]) { // [JVM] https://github.com/ocornut/imgui/pull/2244
299301
// Double-click select a word only, OS X style (by simulating keystrokes)
300302
state.onKeyPressed(K.WORDLEFT)
301303
state.onKeyPressed(K.WORDRIGHT or K.SHIFT)
@@ -304,11 +306,10 @@ internal interface inputText {
304306
state.click(mouseX, mouseY)
305307
state.cursorAnimReset()
306308
}
307-
} else if (io.mouseDown[0] && !state.selectedAllMouseLock && io.mouseDelta.anyNotEqual(0f)) {
308-
state.stb.selectStart = state.stb.cursor
309-
state.stb.selectEnd = state.locateCoord(mouseX, mouseY)
310-
state.cursorFollow = true
309+
} else if (io.mouseDown[0] && !state.selectedAllMouseLock && (io.mouseDelta.x != 0f || io.mouseDelta.y != 0f)) { // TODO -> glm once anyNotEqual gets fixed
310+
state.drag(mouseX, mouseY)
311311
state.cursorAnimReset()
312+
state.cursorFollow = true
312313
}
313314
if (state.selectedAllMouseLock && !io.mouseDown[0])
314315
state.selectedAllMouseLock = false
@@ -326,8 +327,7 @@ internal interface inputText {
326327

327328
// Process regular text input (before we check for Return because using some IME will effectively send a Return?)
328329
// We ignore CTRL inputs, but need to allow ALT+CTRL as some keyboards (e.g. German) use AltGR (which _is_ Alt+Ctrl) to input certain characters.
329-
if (io.inputQueueCharacters.isNotEmpty())
330-
/*if (io.inputQueueCharacters[0] != NUL) I cant explaing why JVM had this TODO check */ {
330+
if (io.inputQueueCharacters.isNotEmpty()) {
331331
if (!ignoreCharInputs && !isReadOnly && !userNavInputStart)
332332
io.inputQueueCharacters.filter { it != NUL || (it == '\t' && io.keyShift) }.map {
333333
// TODO check
@@ -735,8 +735,8 @@ internal interface inputText {
735735
val drawScroll = Vec2(state.scrollX, 0f)
736736
if (renderSelection) {
737737

738-
val textSelectedBegin = glm.min(state.stb.selectStart, state.stb.selectEnd)
739-
val textSelectedEnd = glm.max(state.stb.selectStart, state.stb.selectEnd)
738+
val textSelectedBegin = state.stb.selectStart min state.stb.selectEnd
739+
val textSelectedEnd = state.stb.selectStart max state.stb.selectEnd
740740

741741
val bgColor = getColorU32(Col.TextSelectedBg, if (renderCursor) 1f else 0.6f) // FIXME: current code flow mandate that render_cursor is always true here, we are leaving the transparent one for tests.
742742
val bgOffYUp = if (isMultiline) 0f else -1f // FIXME: those offsets should be part of the style? they don't play so well with multi-line selection.

0 commit comments

Comments
 (0)