Skip to content

Commit 560125c

Browse files
committed
fixed number conversions
1 parent 677d038 commit 560125c

File tree

7 files changed

+28
-29
lines changed

7 files changed

+28
-29
lines changed

imgui.ini

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

6+
[Window][Debug##Default]
7+
Pos=60,60
8+
Size=400,400
9+
Collapsed=0
10+

src/main/kotlin/imgui/Ref.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,16 @@ object Ref {
5151

5252
var int
5353
get() = ints[iPtr]
54-
set(value) { ints[iPtr] = value }
54+
set(value) = ints.set(iPtr, value)
5555
var float
5656
get() = floats[fPtr]
57-
set(value) { floats[fPtr] = value }
57+
set(value) = floats.set(fPtr, value)
5858
var bool
5959
get() = bools[bPtr]
60-
set(value) { bools[bPtr] = value }
60+
set(value) = bools.set(bPtr, value)
6161
var char
6262
get() = chars[cPtr]
63-
set(value) { chars[cPtr] = value }
63+
set(value) = chars.set(cPtr, value)
6464
}
6565

6666
//inline fun <R>withInt(block: (KMutableProperty0<Int>) -> R): R {

src/main/kotlin/imgui/TextEditState.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class TextEditState {
7676
fun getChar(idx: Int) = text[idx]
7777
fun getWidth(lineStartIdx: Int, charIdx: Int): Float {
7878
val c = text[lineStartIdx + charIdx]
79-
return if (c == '\n') -1f else g.font.getCharAdvance_ssaaaaaaa(c) * (g.fontSize / g.font.fontSize)
79+
return if (c == '\n') -1f else g.font.getCharAdvance_ssaaaaaaaa(c) * (g.fontSize / g.font.fontSize)
8080
}
8181

8282
fun keyToText(key: Int) = if (key >= 0x10000) 0 else key

src/main/kotlin/imgui/font.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1055,7 +1055,7 @@ class Font {
10551055
fun findGlyphNoFallback(c: Int) = indexLookup.getOrNull(c)?.let { glyphs[it] }
10561056

10571057
// IMGUI_API void SetFallbackChar(ImWchar c);
1058-
fun getCharAdvance_ssaaaaaaa(c: Char) = if (c < indexAdvanceX.size) indexAdvanceX[c.i] else fallbackAdvanceX
1058+
fun getCharAdvance_ssaaaaaaaa(c: Char) = if (c < indexAdvanceX.size) indexAdvanceX[c.i] else fallbackAdvanceX
10591059

10601060
val isLoaded get() = ::containerAtlas.isInitialized
10611061

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

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -335,8 +335,8 @@ interface imgui_internal {
335335
itemFlags = itemFlagsStack.lastOrNull() ?: If.Default_.i
336336
}
337337

338-
fun setCurrentFont(font: Font) {
339-
assert(font.isLoaded){"Font Atlas not created. Did you call io.Fonts->GetTexDataAsRGBA32 / GetTexDataAsAlpha8 ?"}
338+
fun setCurrentFont(font: Font) {
339+
assert(font.isLoaded) { "Font Atlas not created. Did you call io.Fonts->GetTexDataAsRGBA32 / GetTexDataAsAlpha8 ?" }
340340
assert(font.scale > 0f)
341341
g.font = font
342342
g.fontBaseSize = io.fontGlobalScale * g.font.fontSize * g.font.scale
@@ -2261,7 +2261,7 @@ interface imgui_internal {
22612261
inputTextCalcTextSizeW(text, p, textSelectedEnd, it, stopOnNewLine = true).also { p = it() }
22622262
}
22632263
// So we can see selected empty lines
2264-
if (rectSize.x <= 0f) rectSize.x = (g.font.getCharAdvance_ssaaaaaaa(' ') * 0.5f).i.f
2264+
if (rectSize.x <= 0f) rectSize.x = (g.font.getCharAdvance_ssaaaaaaaa(' ') * 0.5f).i.f
22652265
val rect = Rect(rectPos + Vec2(0f, bgOffYUp - g.fontSize), rectPos + Vec2(rectSize.x, bgOffYDn))
22662266
val clipRect_ = Rect(clipRect)
22672267
rect.clipWith(clipRect_)
@@ -2442,9 +2442,10 @@ interface imgui_internal {
24422442
g.scalarAsInputTextId = g.activeId
24432443
setHoveredId(id)
24442444
}
2445-
return if (textValueChanged)
2446-
dataTypeApplyOpFromText(buf, g.inputTextState.initialText, dataType, data)
2447-
else false
2445+
return when {
2446+
textValueChanged -> dataTypeApplyOpFromText(buf, g.inputTextState.initialText, dataType, data)
2447+
else -> false
2448+
}
24482449
}
24492450

24502451
/** Note: only access 3 floats if ColorEditFlag.NoAlpha flag is set. */
@@ -2811,17 +2812,17 @@ interface imgui_internal {
28112812

28122813
// Modal windows prevents cursor from hovering behind them.
28132814
val modalWindow = frontMostModalRootWindow
2814-
if(modalWindow != null)
2815-
if(g.hoveredRootWindow?.isChildOf(modalWindow) == false)
2815+
if (modalWindow != null)
2816+
if (g.hoveredRootWindow?.isChildOf(modalWindow) == false)
28162817
nullate()
28172818
// Disabled mouse?
28182819
if (io.configFlags has ConfigFlag.NoMouse)
28192820
nullate()
28202821

28212822
// We track click ownership. When clicked outside of a window the click is owned by the application and won't report hovering nor request capture even while dragging over our windows afterward.
2822-
var mouseEarliestButtonDown = - 1
2823+
var mouseEarliestButtonDown = -1
28232824
var mouseAnyDown = false
2824-
for (i in io.mouseDown.indices) {
2825+
for (i in io.mouseDown.indices) {
28252826
if (io.mouseClicked[i])
28262827
io.mouseDownOwned[i] = g.hoveredWindow != null || g.openPopupStack.isNotEmpty()
28272828
mouseAnyDown = mouseAnyDown || io.mouseDown[i]
@@ -2852,7 +2853,7 @@ interface imgui_internal {
28522853
io.wantCaptureKeyboard = true
28532854

28542855
// Update io.WantTextInput flag, this is to allow systems without a keyboard (e.g. mobile, hand-held) to show a software keyboard if possible
2855-
io.wantTextInput = if(g.wantTextInputNextFrame != -1) g.wantTextInputNextFrame != 0 else false
2856+
io.wantTextInput = if (g.wantTextInputNextFrame != -1) g.wantTextInputNextFrame != 0 else false
28562857
}
28572858

28582859
/** Parse display precision back from the display format string */

src/main/kotlin/imgui/imgui/widgets drags.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,7 @@ interface imgui_widgetsDrag {
104104
}
105105
}
106106
if (startTextInput || (g.activeId == id && g.scalarAsInputTextId == id))
107-
return withFloatAsInt(v) {
108-
inputScalarAsWidgetReplacement(frameBb, label, DataType.Float, it as KMutableProperty0<Number>, id, decimalPrecision)
109-
}
107+
return inputScalarAsWidgetReplacement(frameBb, label, DataType.Float, v as KMutableProperty0<Number>, id, decimalPrecision)
110108

111109
// Actual drag behavior
112110
itemSize(totalBb, style.framePadding.y)

src/main/kotlin/imgui/static funcs.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ fun inputTextCalcTextSizeW(text: CharArray, textBegin: Int, textEnd: Int, remain
430430
}
431431
if (c == '\r') continue
432432
// renaming ::getCharAdvance continuously every build because of bug, https://youtrack.jetbrains.com/issue/KT-19612
433-
val charWidth: Float = font.getCharAdvance_ssaaaaaaa(c) * scale
433+
val charWidth: Float = font.getCharAdvance_ssaaaaaaaa(c) * scale
434434
lineWidth += charWidth
435435
}
436436

@@ -486,11 +486,11 @@ fun KMutableProperty0<Number>.format(dataType: DataType, decimalPrecision: Int,
486486
val precision = if (decimalPrecision < 0) "" else ".$decimalPrecision"
487487
return when (dataType) {
488488

489-
DataType.Int -> "%${precision}d".format(style.locale, this())
489+
DataType.Int -> "%${precision}d".format(style.locale, this() as Int)
490490
/* Ideally we'd have a minimum decimal precision of 1 to visually denote that it is a float, while hiding
491491
non-significant digits? */
492-
DataType.Float -> "%${precision}f".format(style.locale, Float.fromBits(this() as Int))
493-
DataType.Double -> "%${precision}f".format(style.locale, Double.fromBits(this() as Long))
492+
DataType.Float -> "%${precision}f".format(style.locale, this() as Float)
493+
DataType.Double -> "%${precision}f".format(style.locale, this() as Double)
494494
else -> throw Error("unsupported format data type")
495495
}.toCharArray(buf)
496496
}

0 commit comments

Comments
 (0)