Skip to content

Commit

Permalink
- renamed some demo objects
Browse files Browse the repository at this point in the history
- implemented single word double click selection (and fixed it) ocornut/imgui#2244
  • Loading branch information
elect86 committed Feb 17, 2020
1 parent e6d5e06 commit debc051
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 42 deletions.
11 changes: 6 additions & 5 deletions imgui-core/src/main/kotlin/imgui/demo/ExampleApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import imgui.ImGui.text
import imgui.ImGui.textWrapped
import imgui.ImGui.time
import imgui.api.demoDebugInformations.Companion.helpMarker
import imgui.api.g
import imgui.classes.TextFilter
import imgui.dsl.collapsingHeader
import imgui.dsl.menu
Expand Down Expand Up @@ -253,11 +254,11 @@ object ExampleApp {
}

// All demo contents
showDemoWindowWidgets()
showDemoWindowLayout()
showDemoWindowPopups()
showDemoWindowColumns()
showDemoWindowMisc()
ShowDemoWindowWidgets()
ShowDemoWindowLayout()
ShowDemoWindowPopups()
ShowDemoWindowColumns()
ShowDemoWindowMisc()

// End of ShowDemoWindow()
end()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import imgui.dsl.collapsingHeader
import imgui.dsl.selectable
import imgui.dsl.treeNode

object showDemoWindowColumns {
object ShowDemoWindowColumns {

/* Columns */
var selected = -1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ import kotlin.math.sin
import imgui.InputTextFlag as Itf
import imgui.WindowFlag as Wf

object showDemoWindowLayout {
object ShowDemoWindowLayout {

/* Child regions */
var disableMouseWheel = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import imgui.dsl.treeNode
import imgui.api.demoDebugInformations.Companion.helpMarker
import imgui.toByteArray

object showDemoWindowMisc {
object ShowDemoWindowMisc {

/* Tabbing */
var buf0 = "dummy".toByteArray(32)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import imgui.dsl.withStyleVar
import imgui.demo.showExampleApp.MenuFile
import imgui.WindowFlag as Wf

object showDemoWindowPopups {
object ShowDemoWindowPopups {

/* Popus */
var selectedFish = -1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ import imgui.ImGui.vSliderFloat
import imgui.ImGui.vSliderInt
import imgui.ImGui.windowDrawList
import imgui.api.demoDebugInformations.Companion.helpMarker
import imgui.api.g
import imgui.classes.Color
import imgui.classes.InputTextCallbackData
import imgui.dsl.collapsingHeader
Expand All @@ -166,7 +167,7 @@ import imgui.InputTextFlag as Itf
import imgui.SelectableFlag as Sf
import imgui.TreeNodeFlag as Tnf

object showDemoWindowWidgets {
object ShowDemoWindowWidgets {

/* Basic */
var counter = 0
Expand Down
2 changes: 0 additions & 2 deletions imgui-core/src/main/kotlin/imgui/demo/showApp.kt

This file was deleted.

14 changes: 8 additions & 6 deletions imgui-core/src/main/kotlin/imgui/demo/showExampleApp/Log.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package imgui.demo.showExampleApp

import glm_.vec2.Vec2
import imgui.*
import imgui.Cond
import imgui.ImGui.begin
import imgui.ImGui.beginChild
import imgui.ImGui.beginPopup
Expand All @@ -22,6 +22,7 @@ import imgui.ImGui.setNextWindowSize
import imgui.ImGui.setScrollHereY
import imgui.ImGui.smallButton
import imgui.ImGui.textEx
import imgui.StyleVar
import imgui.api.g
import imgui.classes.ListClipper
import imgui.classes.TextFilter
Expand Down Expand Up @@ -68,8 +69,10 @@ object Log {

val buf = StringBuilder()
val filter = TextFilter()

/** Index to lines offset. We maintain this with AddLog() calls, allowing us to have a random access on lines */
val lineOffsets = ArrayList<Int>()

/** Keep scrolling if already at the bottom */
var autoScroll = true

Expand Down Expand Up @@ -130,12 +133,11 @@ object Log {
}
else {
val clipper = ListClipper(lineOffsets.size)
while(clipper.step()) {
for(line_no in clipper.display) {
val line = buf.subSequence(lineOffsets[line_no], if(line_no + 1 < lineOffsets.size) lineOffsets[line_no + 1] - 1 else buf.length).toString()
textEx(line)
while (clipper.step())
for (lineNo in clipper.display) {
val lineEnd = if (lineNo + 1 < lineOffsets.size) lineOffsets[lineNo + 1] - 1 else buf.length
textEx(buf.subSequence(lineOffsets[lineNo], lineEnd).toString())
}
}
clipper.end()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,16 @@ import imgui.static.navRestoreLastChildNavWindow
import uno.kotlin.getValue
import uno.kotlin.setValue
import kotlin.reflect.KMutableProperty0
import imgui.WindowFlag as Wf

/** Popups, Modals, Tooltips */
internal interface PopupsModalsTooltips {

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

val parentWindow = g.currentWindow!!
var flags = WindowFlag.NoTitleBar or WindowFlag.NoResize or WindowFlag.NoSavedSettings or WindowFlag._ChildWindow
flags = flags or (parentWindow.flags and WindowFlag.NoMove.i) // Inherit the NoMove flag
var flags = flags_ or Wf.NoTitleBar or Wf.NoResize or Wf.NoSavedSettings or Wf._ChildWindow
flags = flags or (parentWindow.flags and Wf.NoMove.i) // Inherit the NoMove flag

// Size
val contentAvail = contentRegionAvail
Expand Down Expand Up @@ -68,7 +69,7 @@ internal interface PopupsModalsTooltips {
parentWindow.dc.cursorPos put childWindow.pos

// Process navigation-in immediately so NavInit can run on first frame
if (g.navActivateId == id && flags hasnt WindowFlag._NavFlattened && (childWindow.dc.navLayerActiveMask != 0 || childWindow.dc.navHasScroll)) {
if (g.navActivateId == id && flags hasnt Wf._NavFlattened && (childWindow.dc.navLayerActiveMask != 0 || childWindow.dc.navHasScroll)) {
focusWindow(childWindow)
navInitWindow(childWindow, false)
setActiveID(id + 1, childWindow) // Steal ActiveId with a dummy id so that key-press won't activate child item
Expand Down Expand Up @@ -154,8 +155,8 @@ internal interface PopupsModalsTooltips {
popupCountToKeep++
continue
}
assert(popup.window!!.flags has WindowFlag._Popup)
if (popup.window!!.flags has WindowFlag._ChildWindow) {
assert(popup.window!!.flags has Wf._Popup)
if (popup.window!!.flags has Wf._ChildWindow) {
popupCountToKeep++
continue
}
Expand Down Expand Up @@ -192,10 +193,10 @@ internal interface PopupsModalsTooltips {

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

/** ~GetTopMostPopupModal */
val topMostPopupModal: Window?
get() {
for (n in g.openPopupStack.size - 1 downTo 0)
g.openPopupStack[n].window?.let { if (it.flags has WindowFlag._Modal) return it }
g.openPopupStack[n].window?.let { if (it.flags has Wf._Modal) return it }
return null
}

fun findBestWindowPosForPopup(window: Window): Vec2 {

val rOuter = window.getAllowedExtentRect()
if (window.flags has WindowFlag._ChildMenu) {
if (window.flags has Wf._ChildMenu) {
/* Child menus typically request _any_ position within the parent menu item,
and then we move the new menu outside the parent bounds.
This is how we end up with child menus appearing (most-commonly) on the right of the parent menu. */
Expand All @@ -260,11 +261,11 @@ internal interface PopupsModalsTooltips {
}
return findBestWindowPosForPopupEx(Vec2(window.pos), window.size, window::autoPosLastDirection, rOuter, rAvoid)
}
if (window.flags has WindowFlag._Popup) {
if (window.flags has Wf._Popup) {
val rAvoid = Rect(window.pos.x - 1, window.pos.y - 1, window.pos.x + 1, window.pos.y + 1)
return findBestWindowPosForPopupEx(Vec2(window.pos), window.size, window::autoPosLastDirection, rOuter, rAvoid)
}
if (window.flags has WindowFlag._Tooltip) {
if (window.flags has Wf._Tooltip) {
// Position tooltip (always follows mouse)
val sc = style.mouseCursorScale
val refPos = navCalcPreferredRefPos()
Expand Down
22 changes: 11 additions & 11 deletions imgui-core/src/main/kotlin/imgui/internal/api/inputText.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import imgui.internal.classes.InputTextState.K
import imgui.internal.classes.Rect
import imgui.stb.te.click
import imgui.stb.te.cut
import imgui.stb.te.drag
import imgui.stb.te.locateCoord
import imgui.stb.te.paste
import uno.kotlin.getValue
Expand All @@ -64,6 +65,7 @@ import kotlin.math.max
import kotlin.math.min
import kotlin.reflect.KMutableProperty0
import imgui.InputTextFlag as Itf
import imgui.WindowFlag as Wf

/** InputText */
internal interface inputText {
Expand Down Expand Up @@ -126,7 +128,7 @@ internal interface inputText {
pushStyleVar(StyleVar.ChildRounding, style.frameRounding)
pushStyleVar(StyleVar.ChildBorderSize, style.frameBorderSize)
pushStyleVar(StyleVar.WindowPadding, style.framePadding)
val childVisible = beginChildEx(label, id, frameBb.size, true, WindowFlag.NoMove or WindowFlag.AlwaysUseWindowPadding)
val childVisible = beginChildEx(label, id, frameBb.size, true, Wf.NoMove or Wf.AlwaysUseWindowPadding)
popStyleVar(3)
popStyleColor()
if (!childVisible) {
Expand Down Expand Up @@ -292,10 +294,10 @@ internal interface inputText {

// OS X style: Double click selects by word instead of selecting whole text
val isOsx = io.configMacOSXBehaviors
if (selectAll || (hovered && !isOsx && io.mouseDoubleClicked[0])) {
if (selectAll /*|| (hovered && !isOsx && io.mouseDoubleClicked[0])*/) { // [JVM] https://github.com/ocornut/imgui/pull/2244
state.selectAll()
state.selectedAllMouseLock = true
} else if (hovered && isOsx && io.mouseDoubleClicked[0]) {
} else if (hovered /*&& isOsx*/ && io.mouseDoubleClicked[0]) { // [JVM] https://github.com/ocornut/imgui/pull/2244
// Double-click select a word only, OS X style (by simulating keystrokes)
state.onKeyPressed(K.WORDLEFT)
state.onKeyPressed(K.WORDRIGHT or K.SHIFT)
Expand All @@ -304,11 +306,10 @@ internal interface inputText {
state.click(mouseX, mouseY)
state.cursorAnimReset()
}
} else if (io.mouseDown[0] && !state.selectedAllMouseLock && io.mouseDelta.anyNotEqual(0f)) {
state.stb.selectStart = state.stb.cursor
state.stb.selectEnd = state.locateCoord(mouseX, mouseY)
state.cursorFollow = true
} else if (io.mouseDown[0] && !state.selectedAllMouseLock && (io.mouseDelta.x != 0f || io.mouseDelta.y != 0f)) { // TODO -> glm once anyNotEqual gets fixed
state.drag(mouseX, mouseY)
state.cursorAnimReset()
state.cursorFollow = true
}
if (state.selectedAllMouseLock && !io.mouseDown[0])
state.selectedAllMouseLock = false
Expand All @@ -326,8 +327,7 @@ internal interface inputText {

// Process regular text input (before we check for Return because using some IME will effectively send a Return?)
// 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.
if (io.inputQueueCharacters.isNotEmpty())
/*if (io.inputQueueCharacters[0] != NUL) I cant explaing why JVM had this TODO check */ {
if (io.inputQueueCharacters.isNotEmpty()) {
if (!ignoreCharInputs && !isReadOnly && !userNavInputStart)
io.inputQueueCharacters.filter { it != NUL || (it == '\t' && io.keyShift) }.map {
// TODO check
Expand Down Expand Up @@ -735,8 +735,8 @@ internal interface inputText {
val drawScroll = Vec2(state.scrollX, 0f)
if (renderSelection) {

val textSelectedBegin = glm.min(state.stb.selectStart, state.stb.selectEnd)
val textSelectedEnd = glm.max(state.stb.selectStart, state.stb.selectEnd)
val textSelectedBegin = state.stb.selectStart min state.stb.selectEnd
val textSelectedEnd = state.stb.selectStart max state.stb.selectEnd

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.
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.
Expand Down
1 change: 1 addition & 0 deletions imgui-gl/src/test/kotlin/imgui/opengl3.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import glm_.vec4.Vec4
import gln.checkError
import gln.glClearColor
import gln.glViewport
import imgui.api.g
import imgui.classes.Context
import imgui.classes.IO
import imgui.impl.gl.ImplGL3
Expand Down
2 changes: 1 addition & 1 deletion imgui.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Size=400,400
Collapsed=0

[Window][Dear ImGui Demo]
Pos=650.0,20.0
Pos=620.0,20.0
Size=550,680
Collapsed=0

Expand Down

0 comments on commit debc051

Please sign in to comment.