Skip to content

Commit 5010951

Browse files
committed
"fixed" window positions and scaling
1 parent ecd9401 commit 5010951

File tree

4 files changed

+52
-39
lines changed

4 files changed

+52
-39
lines changed

src/main/kotlin/com/lambda/gui/MenuBar.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,12 @@ object MenuBar {
5858
val lambdaLogo = upload("textures/lambda.png")
5959
val githubLogo = upload("textures/github_logo.png")
6060

61+
var height = 0f
62+
6163
fun ImGuiBuilder.buildMenuBar() {
6264
mainMenuBar {
65+
height = windowHeight
66+
6367
lambdaMenu()
6468
menu("HUD") { buildHudMenu() }
6569
menu("GUI") { buildGuiMenu() }

src/main/kotlin/com/lambda/gui/components/ClickGuiLayout.kt

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package com.lambda.gui.components
1919

20+
import com.lambda.Lambda.LOG
2021
import com.lambda.Lambda.mc
2122
import com.lambda.config.Configurable
2223
import com.lambda.config.configurations.GuiConfig
@@ -26,6 +27,7 @@ import com.lambda.event.events.KeyboardEvent
2627
import com.lambda.event.listener.SafeListener.Companion.listen
2728
import com.lambda.gui.DearImGui
2829
import com.lambda.gui.LambdaScreen
30+
import com.lambda.gui.MenuBar
2931
import com.lambda.gui.MenuBar.buildMenuBar
3032
import com.lambda.gui.components.QuickSearch.renderQuickSearch
3133
import com.lambda.gui.dsl.ImGuiBuilder.buildLayout
@@ -39,10 +41,12 @@ import com.lambda.util.KeyCode
3941
import com.lambda.util.NamedEnum
4042
import com.lambda.util.WindowUtils.setLambdaWindowIcon
4143
import imgui.ImGui
44+
import imgui.ImVec2
4245
import imgui.extension.implot.ImPlot
4346
import imgui.flag.ImGuiCol
47+
import imgui.flag.ImGuiCond
4448
import imgui.flag.ImGuiHoveredFlags
45-
import imgui.flag.ImGuiWindowFlags.AlwaysAutoResize
49+
import imgui.flag.ImGuiWindowFlags
4650
import net.minecraft.SharedConstants
4751
import net.minecraft.client.gui.screen.ChatScreen
4852
import net.minecraft.client.gui.screen.Screen
@@ -77,8 +81,16 @@ object ClickGuiLayout : Loadable, Configurable(GuiConfig) {
7781
LongDelay("Long Delay", "Show tooltip after a longer delay (~0.40s), and only after the mouse has been still briefly on the item.", ImGuiHoveredFlags.DelayNormal)
7882
}
7983

84+
const val RELATION = 0.02604
85+
const val BASE_SCALE = 150
86+
val width = mc.window.monitor!!.currentVideoMode!!.width
87+
88+
// don't worry, I'm a professional
89+
// linear interpolation :3
90+
val defaultScale = (RELATION * width + BASE_SCALE).toInt()
91+
8092
// General
81-
internal val scaleSetting by setting("Scale", 100, 50..300, 1, unit = "%").group(Group.General)
93+
internal val scaleSetting by setting("Scale", defaultScale, 50..300, 1, unit = "%").group(Group.General)
8294
val alpha by setting("Alpha", 1.0f, 0.0f..1.0f, 0.01f).group(Group.General)
8395
val disabledAlpha by setting("Disabled Alpha", 0.6f, 0.0f..1.0f, 0.01f).group(Group.General)
8496
val tooltipType by setting("Tooltip Type", TooltipType.Stationary, description = "When to show the tooltip.").group(Group.General)
@@ -191,29 +203,45 @@ object ClickGuiLayout : Loadable, Configurable(GuiConfig) {
191203
val navWindowingDimBg by setting("Nav Windowing Dim Background", Color(204, 204, 204, 51)).group(Group.Colors)
192204
val modalWindowDimBg by setting("Modal Window Dim Background", Color(20, 20, 20, 89)).group(Group.Colors)
193205

206+
var firstRender = true
207+
194208
init {
195209
listen<GuiEvent.NewFrame> {
196210
if (!open) return@listen
197211

198212
buildLayout {
213+
buildMenuBar()
214+
199215
val tags = if (developerMode) shownTags + ModuleTag.DEBUG else shownTags
200216
if (tags.isEmpty()) return@buildLayout
201217

218+
var nextX = 20f
219+
val baseY = MenuBar.height + 10f
220+
202221
tags.forEach { tag ->
203-
window(tag.name, flags = AlwaysAutoResize) {
222+
// FixMe:
223+
// Ok so, ImGui has many different conditions and after having tried for multiple hours
224+
// I could not get either ImGuiCond.Appearing or ImGuiCond.FirstEverUse to work correctly
225+
// for this use case so for the time being we will leave the positions fixed. Too bad!
226+
ImGui.setNextWindowPos(nextX, baseY)
227+
228+
window(tag.name, flags = ImGuiWindowFlags.AlwaysAutoResize) {
204229
ModuleRegistry.modules
205230
.filter { it.tag == tag }
206231
.forEach { with(ModuleEntry(it)) { buildLayout() } }
232+
233+
nextX += windowContentRegionMaxX + 20f // hard coded offset, need to find a get to get the outer position of the window
207234
}
208235
}
209236

210-
buildMenuBar()
211237
renderQuickSearch()
212238

213239
if (developerMode) {
214240
ImGui.showDemoWindow()
215241
ImPlot.showDemoWindow()
216242
}
243+
244+
firstRender = false
217245
}
218246
}
219247

src/main/kotlin/com/lambda/gui/dsl/ImGuiBuilder.kt

Lines changed: 15 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ import net.minecraft.util.math.Vec3i
180180
import java.awt.Color
181181
import kotlin.reflect.KMutableProperty0
182182
import imgui.ImGui.plotLines
183+
import imgui.flag.ImGuiChildFlags
183184

184185
typealias ProcedureBlock = ImGuiBuilder.() -> Unit
185186
typealias WrappedBlock<In, Out> = ImGuiBuilder.(In) -> Out
@@ -361,16 +362,6 @@ object ImGuiBuilder {
361362
@ImGuiDsl
362363
fun showUserGuide() = ImGui.showUserGuide()
363364

364-
/**
365-
* Creates a new window.
366-
*
367-
* @param name The title of the window
368-
* @param open Boolean property that controls window visibility
369-
* @param flags Window flags (see ImGuiWindowFlags)
370-
* @param block Content of the window
371-
*
372-
* @see ImGuiWindowFlags
373-
*/
374365
@ImGuiDsl
375366
inline fun window(
376367
name: String,
@@ -380,16 +371,6 @@ object ImGuiBuilder {
380371
) =
381372
withBool(open) { window(name, it, flags, block) }
382373

383-
/**
384-
* Creates a new window.
385-
*
386-
* @param name The title of the window
387-
* @param open Optional ImBoolean that controls window visibility
388-
* @param flags Window flags (see ImGuiWindowFlags)
389-
* @param block Content of the window
390-
*
391-
* @see ImGuiWindowFlags
392-
*/
393374
@ImGuiDsl
394375
inline fun window(
395376
name: String,
@@ -405,28 +386,16 @@ object ImGuiBuilder {
405386
end()
406387
}
407388

408-
/**
409-
* Creates a child window.
410-
*
411-
* @param strId Unique identifier for the child
412-
* @param width Width of the child (0.0f = auto)
413-
* @param height Height of the child (0.0f = auto)
414-
* @param border Whether to show a border
415-
* @param extraFlags Additional window flags
416-
* @param block Content of the child window
417-
*
418-
* @see ImGuiWindowFlags
419-
*/
420389
@ImGuiDsl
421390
inline fun child(
422391
strId: String,
423392
width: Float = 0f,
424393
height: Float = 0f,
425394
border: Boolean = false,
426-
extraFlags: Int = ImGuiWindowFlags.None,
395+
flags: Int = ImGuiChildFlags.None,
427396
block: ProcedureBlock
428397
) {
429-
if (beginChild(strId, width, height, border, extraFlags))
398+
if (beginChild(strId, width, height, border, flags))
430399
block()
431400

432401
endChild()
@@ -2080,6 +2049,18 @@ object ImGuiBuilder {
20802049
inline fun <T : Any> withInt(property: KMutableProperty0<Int>, block: WrappedBlock<ImInt, T>) =
20812050
ImInt(property()).let { v -> block(v).also { property.set(v.get()) } }
20822051

2052+
@ImGuiDsl
2053+
inline fun withVec2(value: Vec2d, block: WrappedBlock<ImVec2, Unit>) =
2054+
block(ImVec2(value.x.toFloat(), value.y.toFloat()))
2055+
2056+
@ImGuiDsl
2057+
inline fun withVec2(x: Double, y: Double, block: WrappedBlock<ImVec2, Unit>) =
2058+
block(ImVec2(x.toFloat(), y.toFloat()))
2059+
2060+
@ImGuiDsl
2061+
inline fun withVec2(x: Float, y: Float, block: WrappedBlock<ImVec2, Unit>) =
2062+
block(ImVec2(x, y))
2063+
20832064
@ImGuiDsl
20842065
inline fun <T : Any> withString(
20852066
property: KMutableProperty0<String>,

src/main/kotlin/com/lambda/interaction/request/DebugLogger.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class DebugLogger(
7676
var flags = if (autoScroll) ImGuiWindowFlags.NoScrollbar or ImGuiWindowFlags.NoScrollWithMouse else 0
7777
flags = flags or ImGuiWindowFlags.NoBackground
7878
if (!ClickGuiLayout.open) flags = flags or ImGuiWindowFlags.NoInputs
79-
child("Log Content", extraFlags = flags) {
79+
child("Log Content", flags = flags) {
8080
if (wrapText) ImGui.pushTextWrapPos()
8181

8282
logs.forEach { logEntry ->

0 commit comments

Comments
 (0)