Skip to content

Commit c455a62

Browse files
committed
- isMouseDragging(MouseButton) -> MouseButton.isDragging()
- `isMouseDragPastThreshold(MouseButton)` -> `MouseButton.isDragPastThreshold()` - default values on `setScroll*`
1 parent 17ce9fd commit c455a62

File tree

14 files changed

+36
-34
lines changed

14 files changed

+36
-34
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import imgui.ImGui.endTooltip
77
import imgui.ImGui.focusWindow
88
import imgui.ImGui.io
99
import imgui.ImGui.isDown
10-
import imgui.ImGui.isMouseDragging
10+
import imgui.ImGui.isDragging
1111
import imgui.ImGui.itemHoverable
1212
import imgui.ImGui.keepAliveID
1313
import imgui.ImGui.setActiveID
@@ -85,8 +85,8 @@ interface dragAndDrop {
8585
}
8686
if (g.activeId != sourceId)
8787
return false
88-
sourceParentId = window!!.idStack.last()
89-
sourceDragActive = isMouseDragging(mouseButton)
88+
sourceParentId = window.idStack.last()
89+
sourceDragActive = mouseButton.isDragging()
9090

9191
// Disable navigation and key inputs while dragging + cancel existing request if any
9292
setActiveIdUsingAllKeyboardKeys()

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import glm_.vec2.Vec2
55
import imgui.*
66
import imgui.ImGui.io
77
import imgui.ImGui.isClicked
8-
import imgui.ImGui.isMouseDragPastThreshold
8+
import imgui.ImGui.isDragPastThreshold
99
import imgui.ImGui.style
1010
import imgui.ImGui.testOwner
1111
import imgui.internal.classes.InputFlag
@@ -94,11 +94,11 @@ interface inputUtilitiesMouse {
9494
get() = Vec2(g.beginPopupStack.lastOrNull()?.openMousePos ?: io.mousePos)
9595

9696
/** is mouse dragging? (if lock_threshold < -1.0f, uses io.MouseDraggingThreshold) */
97-
fun isMouseDragging(button: MouseButton, lockThreshold: Float = -1f): Boolean {
98-
assert(button.i in io.mouseDown.indices)
99-
if (!io.mouseDown[button.i])
97+
fun MouseButton.isDragging(lockThreshold: Float = -1f): Boolean {
98+
assert(i in io.mouseDown.indices)
99+
if (!io.mouseDown[i])
100100
return false
101-
return isMouseDragPastThreshold(button, lockThreshold)
101+
return isDragPastThreshold(lockThreshold)
102102
}
103103

104104
/** return the delta from the initial clicking position while the mouse button is clicked or was just released.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ import imgui.ImGui.getColumnName
2020
import imgui.ImGui.getColumnWidthAuto
2121
import imgui.ImGui.getID
2222
import imgui.ImGui.getInstanceData
23+
import imgui.ImGui.isDragging
2324
import imgui.ImGui.isItemHovered
24-
import imgui.ImGui.isMouseDragging
2525
import imgui.ImGui.isReleased
2626
import imgui.ImGui.itemAdd
2727
import imgui.ImGui.itemSize
@@ -591,7 +591,7 @@ interface tables {
591591

592592
// Drag and drop to re-order columns.
593593
// FIXME-TABLE: Scroll request while reordering a column and it lands out of the scrolling zone.
594-
if (held && table.flags has Tf.Reorderable && isMouseDragging(MouseButton.Left) && !g.dragDropActive) {
594+
if (held && table.flags has Tf.Reorderable && MouseButton.Left.isDragging() && !g.dragDropActive) {
595595
// While moving a column it will jump on the other side of the mouse, so we also test for MouseDelta.x
596596
table.reorderColumn = columnN
597597
table.instanceInteracted = table.instanceCurrent

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import imgui.ImGui.findRenderedTextEnd
1919
import imgui.ImGui.focusWindow
2020
import imgui.ImGui.io
2121
import imgui.ImGui.isClicked
22-
import imgui.ImGui.isMouseDragPastThreshold
22+
import imgui.ImGui.isDragPastThreshold
2323
import imgui.ImGui.logSetNextTextDecoration
2424
import imgui.ImGui.popID
2525
import imgui.ImGui.popItemWidth
@@ -299,7 +299,7 @@ interface widgetsDrags {
299299

300300
// (Optional) simple click (without moving) turns Drag into an InputText
301301
if (io.configDragClickToInputText && tempInputAllowed && !tempInputIsActive)
302-
if (g.activeId == id && hovered && io.mouseReleased[0] && !isMouseDragPastThreshold(MouseButton.Left, io.mouseDragThreshold * DRAG_MOUSE_THRESHOLD_FACTOR)) {
302+
if (g.activeId == id && hovered && io.mouseReleased[0] && !MouseButton.Left.isDragPastThreshold(io.mouseDragThreshold * DRAG_MOUSE_THRESHOLD_FACTOR)) {
303303
g.navActivateId = id
304304
tempInputIsActive = true
305305
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ interface windowScrolling {
4141
/** center_x_ratio: 0.0f left of last item, 0.5f horizontal center of last item, 1.0f right of last item.
4242
*
4343
* adjust scrolling amount to make current cursor position visible. center_x_ratio=0.0: left, 0.5: center, 1.0: right. When using to make a "default/current item" visible, consider using SetItemDefaultFocus() instead. */
44-
fun setScrollHereX(centerXRatio: Float) {
44+
fun setScrollHereX(centerXRatio: Float = 0.5f) {
4545
val window = g.currentWindow!!
4646
val spacingX = window.windowPadding.x max style.itemSpacing.x
4747
val targetPosX = lerp(g.lastItemData.rect.min.x - spacingX, g.lastItemData.rect.max.x + spacingX, centerXRatio)
@@ -64,7 +64,7 @@ interface windowScrolling {
6464
window.scrollTargetEdgeSnapDist.y = 0f max (window.windowPadding.y - spacingY)
6565
}
6666

67-
fun setScrollFromPosX(localX: Float, centerXratio: Float) = g.currentWindow!!.setScrollFromPosX(localX, centerXratio)
67+
fun setScrollFromPosX(localX: Float, centerXratio: Float = 0.5f) = g.currentWindow!!.setScrollFromPosX(localX, centerXratio)
6868

69-
fun setScrollFromPosY(localY: Float, centerYratio: Float) = g.currentWindow!!.setScrollFromPosY(localY, centerYratio)
69+
fun setScrollFromPosY(localY: Float, centerYratio: Float = 0.5f) = g.currentWindow!!.setScrollFromPosY(localY, centerYratio)
7070
}

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,14 @@ import imgui.ImGui.bullet
1010
import imgui.ImGui.button
1111
import imgui.ImGui.checkboxFlags
1212
import imgui.ImGui.colorButton
13-
import imgui.ImGui.data
1413
import imgui.ImGui.endDisabled
1514
import imgui.ImGui.foregroundDrawList
1615
import imgui.ImGui.getMouseDragDelta
1716
import imgui.ImGui.inputText
1817
import imgui.ImGui.io
1918
import imgui.ImGui.isDown
19+
import imgui.ImGui.isDragging
2020
import imgui.ImGui.isItemActive
21-
import imgui.ImGui.isMouseDragging
2221
import imgui.ImGui.isMousePosValid
2322
import imgui.ImGui.popTabStop
2423
import imgui.ImGui.pushTabStop
@@ -155,9 +154,9 @@ object ShowDemoWindowInputs {
155154
for (button in MouseButton.values())
156155
if (button != MouseButton.None) {
157156
text("IsMouseDragging(${button.i}):")
158-
text(" w/ default threshold: ${isMouseDragging(button).i},")
159-
text(" w/ zero threshold: ${isMouseDragging(button, 0f).i},")
160-
text(" w/ large threshold: ${isMouseDragging(button, 20f)},")
157+
text(" w/ default threshold: ${button.isDragging().i},")
158+
text(" w/ zero threshold: ${button.isDragging(0f).i},")
159+
text(" w/ large threshold: ${button.isDragging(20f)},")
161160
}
162161
button("Drag Me")
163162
if (isItemActive)

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import imgui.ImGui.getColumnWidth
4242
import imgui.ImGui.getID
4343
import imgui.ImGui.invisibleButton
4444
import imgui.ImGui.io
45+
import imgui.ImGui.isDragging
4546
import imgui.ImGui.isItemActive
4647
import imgui.ImGui.isItemHovered
4748
import imgui.ImGui.itemRectMax
@@ -797,7 +798,7 @@ object ShowDemoWindowLayout {
797798
pushID(n)
798799

799800
invisibleButton("##canvas", size)
800-
if (ImGui.isItemActive && ImGui.isMouseDragging(MouseButton.Left))
801+
if (ImGui.isItemActive && MouseButton.Left.isDragging())
801802
offset += io.mouseDelta
802803
popID()
803804
if (!ImGui.isItemVisible) // Skip rendering as ImDrawList elements are not clipped.

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import imgui.ImGui.invisibleButton
2424
import imgui.ImGui.io
2525
import imgui.ImGui.isClicked
2626
import imgui.ImGui.isDown
27+
import imgui.ImGui.isDragging
2728
import imgui.ImGui.openPopupOnItemClick
2829
import imgui.ImGui.popItemWidth
2930
import imgui.ImGui.pushItemWidth
@@ -220,7 +221,7 @@ object CustomRendering {
220221
// Pan (we use a zero mouse threshold when there's no context menu)
221222
// You may decide to make that threshold dynamic based on whether the mouse is hovering something etc.
222223
val mouseThresholdForPan = if (optEnableContextMenu) -1f else 0f
223-
if (isActive && ImGui.isMouseDragging(MouseButton.Right, mouseThresholdForPan))
224+
if (isActive && MouseButton.Right.isDragging(mouseThresholdForPan))
224225
scrolling += io.mouseDelta
225226

226227
// Context menu (under default mouse threshold)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ import imgui.internal.api.*
1010
const val IMGUI_BUILD = 0
1111

1212
/** get the compiled version string e.g. "1.80 WIP" (essentially the value for IMGUI_VERSION from the compiled version of imgui.cpp) */
13-
const val IMGUI_VERSION = "1.89.5 WIP"
13+
const val IMGUI_VERSION = "1.89.5"
1414
const val IMGUI_VERSION_BUILD = "$IMGUI_VERSION.$IMGUI_BUILD"
1515

1616
/** Integer encoded as XYYZZ for use in #if preprocessor conditionals.
1717
Work in progress versions typically starts at XYY99 then bounce up to XYY00, XYY01 etc. when release tagging happens) */
18-
const val IMGUI_VERSION_NUM = 18949
18+
const val IMGUI_VERSION_NUM = 18950
1919

2020

2121
// Helpers macros to generate 32-bits encoded colors

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,14 @@ internal interface inputs {
9494

9595
/** Return if a mouse click/drag went past the given threshold. Valid to call during the MouseReleased frame.
9696
* [Internal] This doesn't test if the button is pressed */
97-
fun isMouseDragPastThreshold(button: MouseButton, lockThreshold_: Float): Boolean {
98-
99-
assert(button.i in io.mouseDown.indices)
100-
if (!io.mouseDown[button.i])
97+
infix fun MouseButton.isDragPastThreshold(lockThreshold_: Float): Boolean {
98+
assert(i in io.mouseDown.indices)
99+
if (!io.mouseDown[i])
101100
return false
102101
var lockThreshold = lockThreshold_
103102
if (lockThreshold < 0f)
104103
lockThreshold = io.mouseDragThreshold
105-
return io.mouseDragMaxDistanceSqr[button.i] >= lockThreshold * lockThreshold
104+
return io.mouseDragMaxDistanceSqr[i] >= lockThreshold * lockThreshold
106105
}
107106

108107
/** Return 2D vector representing the combination of four cardinal direction, with analog value support (for e.g. ImGuiKey_GamepadLStick* values). */

0 commit comments

Comments
 (0)