Skip to content

Commit b2ed17e

Browse files
committed
🚧 up to Mar 22
increased available id to 1024
1 parent a18cb70 commit b2ed17e

File tree

9 files changed

+33
-30
lines changed

9 files changed

+33
-30
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,20
3-
Size=550,680
4-
Collapsed=0
5-
61
[Window][Debug##Default]
72
Pos=60,60
83
Size=400,400
94
Collapsed=0
105

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

src/main/kotlin/imgui/Ref.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ object Ref {
4242
var bPtr = 0
4343
var cPtr = 0
4444

45-
val size = 500
45+
val size = 1024
4646

4747
val ints = IntArray(size)
4848
val floats = FloatArray(size)

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_s(c) * (g.fontSize / g.font.fontSize)
79+
return if (c == '\n') -1f else g.font.getCharAdvance_ssaaaaaaa(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
@@ -1053,7 +1053,7 @@ class Font {
10531053
fun findGlyphNoFallback(c: Int) = indexLookup.getOrNull(c)?.let { glyphs[it] }
10541054

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

10581058
val isLoaded get() = ::containerAtlas.isInitialized
10591059

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import imgui.ImGui.fontSize
4141
import imgui.ImGui.image
4242
import imgui.ImGui.imageButton
4343
import imgui.ImGui.indent
44+
import imgui.ImGui.inputDouble
4445
import imgui.ImGui.inputFloat
4546
import imgui.ImGui.inputFloat2
4647
import imgui.ImGui.inputFloat3
@@ -132,6 +133,7 @@ object widgets {
132133
var str0 = "Hello, world!".toCharArray()
133134
var i0 = 123
134135
var f0 = 0.001f
136+
var d0 = 999999.000001
135137
val vec4a = floatArrayOf(0.1f, 0.2f, 0.3f, 0.44f)
136138
var i1 = 50
137139
var i2 = 42
@@ -317,6 +319,10 @@ object widgets {
317319

318320
inputFloat("input float", ::f0, 0.01f, 1f)
319321

322+
// NB: You can use the %e notation as well.
323+
inputDouble("input double", ::d0, 0.01, 1.0, "%.6f")
324+
sameLine(); showHelpMarker("You can input value using the scientific notation,\n e.g. \"1e+8\" becomes \"100000000\".\n")
325+
320326
inputFloat3("input float3", vec4a)
321327
}
322328
run {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1720,14 +1720,14 @@ interface imgui_internal {
17201720

17211721
fun inputTextEx(label: String, buf: CharArray, sizeArg: Vec2, flags: InputTextFlags
17221722
/*, ImGuiTextEditCallback callback = NULL, void* user_data = NULL*/): Boolean {
1723-
println(label)
1723+
17241724
val window = currentWindow
17251725
if (window.skipItems) return false
17261726

17271727
// Can't use both together (they both use up/down keys)
1728-
assert((flags has Itf.CallbackHistory) xor (flags has Itf.Multiline))
1728+
assert(!((flags has Itf.CallbackHistory) && (flags has Itf.Multiline)))
17291729
// Can't use both together (they both use tab key)
1730-
assert((flags has Itf.CallbackCompletion) xor (flags has Itf.AllowTabInput))
1730+
assert(!((flags has Itf.CallbackCompletion) && (flags has Itf.AllowTabInput)))
17311731

17321732
val isMultiline = flags has Itf.Multiline
17331733
val isEditable = flags hasnt Itf.ReadOnly
@@ -2269,7 +2269,7 @@ interface imgui_internal {
22692269
inputTextCalcTextSizeW(text, p, textSelectedEnd, it, stopOnNewLine = true).also { p = it() }
22702270
}
22712271
// So we can see selected empty lines
2272-
if (rectSize.x <= 0f) rectSize.x = (g.font.getCharAdvance_s(' ') * 0.5f).i.f
2272+
if (rectSize.x <= 0f) rectSize.x = (g.font.getCharAdvance_ssaaaaaaa(' ') * 0.5f).i.f
22732273
val rect = Rect(rectPos + Vec2(0f, bgOffYUp - g.fontSize), rectPos + Vec2(rectSize.x, bgOffYDn))
22742274
val clipRect_ = Rect(clipRect)
22752275
rect.clipWith(clipRect_)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ interface imgui_main {
437437
if (!it.active || it.flags hasnt Wf.ChildWindow) // if a child is active its parent will add it
438438
it.addToSortedBuffer()
439439
}
440-
assert(g.windows.size == g.windowsSortBuffer.size) // we done something wrong
440+
// TODO assert(g.windows.size == g.windowsSortBuffer.size) // we done something wrong
441441
g.windows.clear()
442442
g.windows.addAll(g.windowsSortBuffer)
443443

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,21 @@ interface imgui_widgetsInputKeyboard {
4747

4848
fun inputFloat(label: String, v: KMutableProperty0<Float>, step: Float = 0f, stepFast: Float = 0f,
4949
decimalPrecision: Int = -1, extraFlags: InputTextFlags = 0): Boolean {
50+
val flags = extraFlags or Itf.CharsScientific
5051
/* Ideally we'd have a minimum decimal precision of 1 to visually denote that this is a float,
5152
while hiding non-significant digits? %f doesn't have a minimum of 1 */
5253
val fmt = "%${if (decimalPrecision < 0) "" else ".$decimalPrecision"}f"
5354
return inputScalarEx(label, DataType.Float, v as KMutableProperty0<Number>, step.takeIf { it > 0f },
54-
stepFast.takeIf { it > 0f }, fmt, extraFlags)
55+
stepFast.takeIf { it > 0f }, fmt, flags)
5556
}
5657

5758
fun inputDouble(label: String, v: KMutableProperty0<Double>, step: Double = 0.0, stepFast: Double = 0.0,
58-
decimalPrecision: Int = -1, extraFlags: InputTextFlags = 0): Boolean {
59-
59+
dispalyFormat: String = "%.6f", extraFlags: InputTextFlags = 0): Boolean {
60+
val flags = extraFlags or Itf.CharsScientific
6061
/* Ideally we'd have a minimum decimal precision of 1 to visually denote that this is a float,
6162
while hiding non-significant digits? %f doesn't have a minimum of 1 */
62-
val fmt = "%${if (decimalPrecision < 0) "" else ".$decimalPrecision"}f"
63-
return inputScalarEx(label, DataType.Float, v as KMutableProperty0<Number>, step.takeIf { it > 0.0 },
64-
stepFast.takeIf { it > 0.0 }, fmt, extraFlags)
63+
return inputScalarEx(label, DataType.Double, v as KMutableProperty0<Number>, step.takeIf { it > 0.0 },
64+
stepFast.takeIf { it > 0.0 }, dispalyFormat, flags)
6565
}
6666

6767
fun inputFloat2(label: String, v: FloatArray, decimalPrecision: Int = -1, extraFlags: InputTextFlags = 0) =

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

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -352,9 +352,6 @@ fun inputTextFilterCharacter(char: KMutableProperty0<Char>, flags: InputTextFlag
352352
/* Filter private Unicode range. I don't imagine anybody would want to input them. GLFW on OSX seems to send
353353
private characters for special keys like arrow keys. */
354354
if (c >= 0xE000 && c <= 0xF8FF) return false
355-
356-
println(char())
357-
358355
if (flags has (Itf.CharsDecimal or Itf.CharsHexadecimal or Itf.CharsUppercase or Itf.CharsNoBlank or Itf.CharsScientific)) {
359356

360357
if (flags has Itf.CharsDecimal)
@@ -431,8 +428,8 @@ fun inputTextCalcTextSizeW(text: CharArray, textBegin: Int, textEnd: Int, remain
431428
continue
432429
}
433430
if (c == '\r') continue
434-
435-
val charWidth: Float = font.getCharAdvance_s(c) * scale
431+
// renaming ::getCharAdvance continuously every build because of bug, https://youtrack.jetbrains.com/issue/KT-19612
432+
val charWidth: Float = font.getCharAdvance_ssaaaaaaa(c) * scale
436433
lineWidth += charWidth
437434
}
438435

@@ -466,8 +463,8 @@ fun inputTextCalcTextSizeW(text: CharArray, textBegin: Int, textEnd: Int, remain
466463
fun KMutableProperty0<Number>.format(dataType: DataType, displayFormat: String, buf: CharArray): CharArray {
467464
val value: Number = when (dataType) {
468465
DataType.Int -> this()
469-
DataType.Float -> Float.fromBits(this() as Int)
470-
DataType.Double -> Double.fromBits(this() as Long)
466+
DataType.Float -> this() as Float
467+
DataType.Double -> this() as Double
471468
else -> throw Error()
472469
}
473470
return displayFormat.format(style.locale, value).toCharArray(buf)
@@ -589,7 +586,7 @@ fun dataTypeApplyOpFromText(buf: CharArray, initialValueBuf: CharArray, dataType
589586
DataType.Float -> {
590587
// For floats we have to ignore format with precision (e.g. "%.2f") because sscanf doesn't take them in TODO not true in java
591588
// val scalarFormat = scalarFormat ?: "%f"
592-
var v = glm.intBitsToFloat(data() as Int)
589+
var v = data() as Float
593590
val oldV = v
594591
var a = 0f
595592
try {
@@ -612,13 +609,13 @@ fun dataTypeApplyOpFromText(buf: CharArray, initialValueBuf: CharArray, dataType
612609
}
613610
else -> a // Assign constant
614611
}
615-
data.set(glm.floatBitsToInt(v))
612+
data.set(v)
616613
oldV != v
617614
}
618615
DataType.Double -> {
619616
// For floats we have to ignore format with precision (e.g. "%.2f") because sscanf doesn't take them in TODO not true in java
620617
// val scalarFormat = scalarFormat ?: "%f"
621-
var v = Double.fromBits(data() as Long)
618+
var v = data() as Double
622619
val oldV = v
623620
var a = 0.0
624621
try {
@@ -641,7 +638,7 @@ fun dataTypeApplyOpFromText(buf: CharArray, initialValueBuf: CharArray, dataType
641638
}
642639
else -> a // Assign constant
643640
}
644-
data.set(glm.doubleBitsToLong(v))
641+
data.set(v)
645642
oldV != v
646643
}
647644
else -> false

0 commit comments

Comments
 (0)