Skip to content

Commit a3b9e47

Browse files
committed
fixed menuSet bug
1 parent f4e90d1 commit a3b9e47

File tree

5 files changed

+26
-27
lines changed

5 files changed

+26
-27
lines changed

imgui.ini

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
[Window][ImGui Demo]
2-
Pos=650.0,20.0
3-
Size=550,680
4-
Collapsed=0
5-
61
[Window][Debug##Default]
72
Pos=60.0,60.0
83
Size=400,400
94
Collapsed=0
105

6+
[Window][ImGui Demo]
7+
Pos=650.0,20.0
8+
Size=550,680
9+
Collapsed=0
10+

src/main/kotlin/imgui/imgui/internal.kt

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -164,14 +164,14 @@ interface imgui_internal {
164164
// Always align ourselves on pixel boundaries
165165
val lineHeight = glm.max(window.dc.currentLineHeight, size.y)
166166
val textBaseOffset = glm.max(window.dc.currentLineTextBaseOffset, textOffsetY)
167-
//if (g.io.KeyAlt) window->DrawList->AddRect(window->DC.CursorPos, window->DC.CursorPos + ImVec2(size.x, line_height), IM_COL32(255,0,0,200)); // [DEBUG]
167+
//if (io.keyAlt) window.drawList.addRect(window.dc.cursorPos, window.dc.cursorPos + Vec2(size.x, lineHeight), COL32(255,0,0,200)); // [DEBUG]
168168
window.dc.cursorPosPrevLine.put(window.dc.cursorPos.x + size.x, window.dc.cursorPos.y)
169169
window.dc.cursorPos.x = (window.pos.x + window.dc.indentX + window.dc.columnsOffsetX).i.f
170170
window.dc.cursorPos.y = (window.dc.cursorPos.y + lineHeight + style.itemSpacing.y).i.f
171171
window.dc.cursorMaxPos.x = glm.max(window.dc.cursorMaxPos.x, window.dc.cursorPosPrevLine.x)
172172
window.dc.cursorMaxPos.y = glm.max(window.dc.cursorMaxPos.y, window.dc.cursorPos.y - style.itemSpacing.y)
173173

174-
//if (g.io.KeyAlt) window->DrawList->AddCircle(window->DC.CursorMaxPos, 3.0f, IM_COL32(255,0,0,255), 4); // [DEBUG]
174+
//if (io.keyAlt) window.drawList.addCircle(window.dc.cursorMaxPos, 3f, COL32(255,0,0,255), 4); // [DEBUG]
175175

176176
window.dc.prevLineHeight = lineHeight
177177
window.dc.prevLineTextBaseOffset = textBaseOffset
@@ -436,12 +436,10 @@ interface imgui_internal {
436436
return false
437437
}
438438

439-
val name =
440-
if (extraFlags has Wf.ChildMenu)
441-
"##Menu_%02d".format(style.locale, g.currentPopupStack.size) // Recycle windows based on depth
442-
else
443-
"##Popup_%08x".format(style.locale, id) // Not recycling, so we can close/open during the same frame
444-
439+
val name = when {
440+
extraFlags has Wf.ChildMenu -> "##Menu_%02d".format(style.locale, g.currentPopupStack.size) // Recycle windows based on depth
441+
else -> "##Popup_%08x".format(style.locale, id) // Not recycling, so we can close/open during the same frame
442+
}
445443
val isOpen = begin(name, null, extraFlags or Wf.Popup)
446444
if (!isOpen) // NB: Begin can return false when the popup is completely clipped (e.g. zero size display)
447445
endPopup()

src/main/kotlin/imgui/imgui/menus.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ interface imgui_menus {
178178
g.openPopupStack[g.currentPopupStack.size].openParentId == window.idStack.last()
179179
val backedNavWindow = g.navWindow
180180
if (menusetIsOpen)
181-
// Odd hack to allow hovering across menus of a same menu-set (otherwise we wouldn't be able to hover parent)
181+
// Odd hack to allow hovering across menus of a same menu-set (otherwise we wouldn't be able to hover parent)
182182
g.navWindow = window
183183

184184
/* The reference position stored in popupPos will be used by Begin() to find a suitable position for the child
@@ -251,8 +251,7 @@ interface imgui_menus {
251251
wantOpen = true
252252
navMoveRequestCancel()
253253
}
254-
} else
255-
// Menu bar
254+
} else // Menu bar
256255
if (menuIsOpen && pressed && menusetIsOpen) { // Click an open menu again to close it
257256
wantClose = true
258257
wantOpen = false
@@ -277,8 +276,7 @@ interface imgui_menus {
277276
}
278277

279278
menuIsOpen = menuIsOpen || wantOpen
280-
if (wantOpen)
281-
openPopup(label)
279+
if (wantOpen) openPopup(label)
282280

283281
if (menuIsOpen) {
284282
/* Sub-menus are ChildWindow so that mouse can be hovering across them (otherwise top-most popup menu
@@ -289,6 +287,7 @@ interface imgui_menus {
289287
// menuIsOpen can be 'false' when the popup is completely clipped (e.g. zero size display)
290288
menuIsOpen = beginPopupEx(id, flags)
291289
}
290+
292291
return menuIsOpen
293292
}
294293

src/main/kotlin/imgui/imgui/window.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,8 @@ interface imgui_window {
342342

343343
val windowPosWithPivot = window.setWindowPosVal.x != Float.MAX_VALUE && window.hiddenFrames == 0
344344
if (windowPosWithPivot)
345-
window.setPos(glm.max(style.displaySafeAreaPadding, window.setWindowPosVal - window.sizeFull * window.setWindowPosPivot), Cond.Null) // Position given a pivot (e.g. for centering)
345+
// Position given a pivot (e.g. for centering)
346+
window.setPos(glm.max(style.displaySafeAreaPadding, window.setWindowPosVal - window.sizeFull * window.setWindowPosPivot), Cond.Null)
346347
else if (flags has Wf.ChildMenu)
347348
window.pos = findBestWindowPosForPopup(window)
348349
else if (flags has Wf.Popup && !windowPosSetByApi && windowJustAppearingAfterHiddenForResize)
@@ -352,7 +353,7 @@ interface imgui_window {
352353

353354
// Clamp position so it stays visible
354355
if (flags hasnt Wf.ChildWindow)
355-
/* Ignore zero-sized display explicitly to avoid losing positions if a window manager reports zero-sized
356+
/* Ignore zero-sized display explicitly to avoid losing positions if a window manager reports zero-sized
356357
window when initializing or minimizing. */
357358
if (!windowPosSetByApi && window.autoFitFrames.x <= 0 && window.autoFitFrames.y <= 0 && io.displaySize greaterThan 0) {
358359
val padding = glm.max(style.displayWindowPadding, style.displaySafeAreaPadding)
@@ -516,7 +517,7 @@ interface imgui_window {
516517

517518
with(window) {
518519

519-
/* Update ContentsRegionMax. All the variable it depends on are set above in this function.
520+
/* Update ContentsRegionMax. Variables they depends on are set above in this function.
520521
FIXME: window->ContentsRegion.Max is currently very misleading / partly faulty,
521522
but some BeginChild() patterns relies on it. */
522523
contentsRegionRect.let {

src/main/kotlin/imgui/internal/classes.kt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -740,17 +740,18 @@ class Window(var context: Context, var name: String) {
740740
return
741741
// JVM, useless
742742
// assert(cond == Cond.Null || cond.isPowerOfTwo) { "Make sure the user doesn't attempt to combine multiple condition flags." }
743-
setWindowPosAllowFlags = setWindowPosAllowFlags and (Cond.Once or Cond.FirstUseEver or Cond.Appearing).inv()
743+
setWindowPosAllowFlags = setWindowPosAllowFlags wo (Cond.Once or Cond.FirstUseEver or Cond.Appearing)
744744
setWindowPosVal put Float.MAX_VALUE
745745
setWindowPosPivot put Float.MAX_VALUE
746746

747747
// Set
748-
val oldPos = Vec2(pos)
748+
val oldPos = Vec2(this.pos)
749749
this.pos put glm.floor(pos)
750750
// As we happen to move the window while it is being appended to (which is a bad idea - will smear) let's at least
751751
// offset the cursor
752-
dc.cursorPos plusAssign pos - oldPos
753-
dc.cursorMaxPos plus (pos - oldPos) // And more importantly we need to adjust this so size calculation doesn't get affected.
752+
val offset = pos - oldPos
753+
dc.cursorPos plusAssign offset
754+
dc.cursorMaxPos plusAssign offset // And more importantly we need to adjust this so size calculation doesn't get affected.
754755
}
755756

756757
fun setSize(size: Vec2, cond: Cond) {
@@ -938,8 +939,8 @@ class Window(var context: Context, var name: String) {
938939
}
939940

940941
fun calcSizeContents() = Vec2(
941-
(if (sizeContentsExplicit.x != 0f) sizeContentsExplicit.x else dc.cursorMaxPos.x - pos.x + scroll.x).i.f,
942-
(if (sizeContentsExplicit.y != 0f) sizeContentsExplicit.y else dc.cursorMaxPos.y - pos.y + scroll.y).i.f) + windowPadding
942+
(if (sizeContentsExplicit.x != 0f) sizeContentsExplicit.x else dc.cursorMaxPos.x - pos.x + scroll.x).i.f + windowPadding.x,
943+
(if (sizeContentsExplicit.y != 0f) sizeContentsExplicit.y else dc.cursorMaxPos.y - pos.y + scroll.y).i.f + windowPadding.y)
943944

944945
fun findOrAddColumnsSet(id: ID): ColumnsSet {
945946
for (c in columnsStorage)

0 commit comments

Comments
 (0)