Skip to content

Commit 99d1c14

Browse files
committed
Advanced ImGUI style settings
1 parent 905f3ec commit 99d1c14

File tree

2 files changed

+195
-43
lines changed

2 files changed

+195
-43
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ package com.lambda.gui
2020
import com.lambda.Lambda.mc
2121
import com.lambda.core.Loadable
2222
import com.lambda.gui.dsl.ImGuiBuilder
23+
import com.lambda.module.modules.client.ClickGui
2324
import com.lambda.module.modules.client.GuiSettings
2425
import com.lambda.util.path
2526
import com.mojang.blaze3d.opengl.GlStateManager
@@ -50,9 +51,6 @@ object DearImGui : Loadable {
5051
private var targetScale = 0f
5152

5253
private fun updateScale(scale: Float) {
53-
val scaleFactor = if (lastScale > 0) scale / lastScale else scale
54-
ImGui.getStyle().scaleAllSizes(scaleFactor)
55-
5654
io.fonts.clear()
5755
val baseFontSize = 13f
5856
io.fonts.addFontFromFileTTF("fonts/FiraSans-Regular.ttf".path, baseFontSize * scale)
@@ -92,6 +90,8 @@ object DearImGui : Loadable {
9290

9391
implGlfw.newFrame()
9492
implGl3.newFrame()
93+
94+
ClickGui.applyStyle(lastScale)
9595
ImGui.newFrame()
9696

9797
ImGuiBuilder.block()

src/main/kotlin/com/lambda/module/modules/client/ClickGui.kt

Lines changed: 192 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ import com.lambda.gui.LambdaScreen
2121
import com.lambda.module.Module
2222
import com.lambda.module.tag.ModuleTag
2323
import com.lambda.util.KeyCode
24-
import com.lambda.util.math.setAlpha
24+
import com.lambda.util.NamedEnum
25+
import imgui.ImGui
26+
import imgui.flag.ImGuiCol
2527
import net.minecraft.client.gui.screen.ChatScreen
2628
import net.minecraft.client.gui.screen.Screen
2729
import net.minecraft.client.gui.screen.ingame.AnvilScreen
@@ -35,59 +37,209 @@ object ClickGui : Module(
3537
tag = ModuleTag.CLIENT,
3638
defaultKeybind = KeyCode.Y,
3739
) {
38-
val titleBarHeight by setting("Title Bar Height", 18.0, 10.0..25.0, 0.1)
39-
val moduleHeight by setting("Module Height", 16.0, 10.0..25.0, 0.1)
40-
val settingsHeight by setting("Settings Height", 16.0, 10.0..25.0, 0.1)
41-
val padding by setting("Padding", 1.0, 1.0..6.0, 0.1)
42-
val listStep by setting("List Step", 1.0, 0.0..6.0, 0.1)
43-
val autoResize by setting("Auto Resize", false)
44-
45-
val roundRadius by setting("Round Radius", 3.0, 0.0..10.0, 0.1)
46-
47-
val backgroundTint by setting("Background Tint", Color.BLACK.setAlpha(0.4))
48-
val backgroundCornerTint by setting("Background Corner Tint", Color.WHITE.setAlpha(0.4))
49-
val cornerTintWidth by setting("Corner Tint Width", 100.0, 1.0..500.0, 0.1)
50-
val cornerTintShade by setting("Corner Tint Shade", true)
51-
52-
val titleBackgroundColor by setting("Title Background Color", Color(80, 80, 80))
53-
val backgroundColor by setting("Background Color", titleBackgroundColor)
54-
val backgroundShade by setting("Background Shade", true)
40+
private enum class Group(override val displayName: String) : NamedEnum {
41+
General("General"),
42+
Sizing("Sizing"),
43+
Rounding("Rounding"),
44+
Colors("Colors"),
45+
Font("Font")
46+
}
5547

56-
val outline by setting("Outline", true)
57-
val outlineWidth by setting("Outline Width", 0.5, 0.5..5.0, 0.1) { outline }
58-
val outlineColor by setting("Outline Color", Color.WHITE) { outline }
59-
val outlineShade by setting("Outline Shade", true) { outline }
48+
// General
49+
val alpha by setting("Alpha", 1.0f, 0.0f..1.0f, 0.01f).group(Group.General)
50+
val disabledAlpha by setting("Disabled Alpha", 0.6f, 0.0f..1.0f, 0.01f).group(Group.General)
6051

61-
val glow by setting("Glow", true)
62-
val glowWidth by setting("Glow Width", 8.0, 1.0..20.0, 0.1) { glow }
63-
val glowColor by setting("Glow Color", Color.WHITE.setAlpha(0.35)) { glow }
64-
val glowShade by setting("Glow Shade", true) { glow }
52+
// Sizing
53+
val windowPaddingX by setting("Window Padding X", 8.0f, 0.0f..20.0f, 0.1f).group(Group.Sizing)
54+
val windowPaddingY by setting("Window Padding Y", 8.0f, 0.0f..20.0f, 0.1f).group(Group.Sizing)
55+
val windowMinSizeX by setting("Window Min Size X", 32.0f, 0.0f..100.0f, 1.0f).group(Group.Sizing)
56+
val windowMinSizeY by setting("Window Min Size Y", 32.0f, 0.0f..100.0f, 1.0f).group(Group.Sizing)
57+
val windowTitleAlignX by setting("Window Title Align X", 0.0f, 0.0f..1.0f, 0.01f).group(Group.Sizing)
58+
val windowTitleAlignY by setting("Window Title Align Y", 0.5f, 0.0f..1.0f, 0.01f).group(Group.Sizing)
59+
val framePaddingX by setting("Frame Padding X", 4.0f, 0.0f..20.0f, 0.1f).group(Group.Sizing)
60+
val framePaddingY by setting("Frame Padding Y", 3.0f, 0.0f..20.0f, 0.1f).group(Group.Sizing)
61+
val itemSpacingX by setting("Item Spacing X", 8.0f, 0.0f..20.0f, 0.1f).group(Group.Sizing)
62+
val itemSpacingY by setting("Item Spacing Y", 4.0f, 0.0f..20.0f, 0.1f).group(Group.Sizing)
63+
val itemInnerSpacingX by setting("Item Inner Spacing X", 4.0f, 0.0f..20.0f, 0.1f).group(Group.Sizing)
64+
val itemInnerSpacingY by setting("Item Inner Spacing Y", 4.0f, 0.0f..20.0f, 0.1f).group(Group.Sizing)
65+
val indentSpacing by setting("Indent Spacing", 21.0f, 0.0f..50.0f, 0.1f).group(Group.Sizing)
66+
val scrollbarSize by setting("Scrollbar Size", 14.0f, 0.0f..30.0f, 0.1f).group(Group.Sizing)
67+
val grabMinSize by setting("Grab Min Size", 10.0f, 0.0f..30.0f, 0.1f).group(Group.Sizing)
68+
val windowBorderSize by setting("Window Border Size", 1.0f, 0.0f..5.0f, 0.1f).group(Group.Sizing)
69+
val childBorderSize by setting("Child Border Size", 1.0f, 0.0f..5.0f, 0.1f).group(Group.Sizing)
70+
val popupBorderSize by setting("Popup Border Size", 1.0f, 0.0f..5.0f, 0.1f).group(Group.Sizing)
71+
val frameBorderSize by setting("Frame Border Size", 0.0f, 0.0f..5.0f, 0.1f).group(Group.Sizing)
72+
val tabBorderSize by setting("Tab Border Size", 0.0f, 0.0f..5.0f, 0.1f).group(Group.Sizing)
6573

66-
val fontScale by setting("Font Scale", 1.0, 0.5..2.0, 0.1)
67-
val fontOffset by setting("Font Offset", 4.0, 0.0..5.0, 0.1)
68-
val dockingGridSize by setting("Docking Grid Size", 1.0, 0.1..10.0, 0.1)
74+
// Rounding
75+
val windowRounding by setting("Window Rounding", 0.0f, 0.0f..12.0f, 0.1f).group(Group.Rounding)
76+
val childRounding by setting("Child Rounding", 0.0f, 0.0f..12.0f, 0.1f).group(Group.Rounding)
77+
val frameRounding by setting("Frame Rounding", 0.0f, 0.0f..12.0f, 0.1f).group(Group.Rounding)
78+
val popupRounding by setting("Popup Rounding", 0.0f, 0.0f..12.0f, 0.1f).group(Group.Rounding)
79+
val scrollbarRounding by setting("Scrollbar Rounding", 9.0f, 0.0f..12.0f, 0.1f).group(Group.Rounding)
80+
val grabRounding by setting("Grab Rounding", 0.0f, 0.0f..12.0f, 0.1f).group(Group.Rounding)
81+
val tabRounding by setting("Tab Rounding", 4.0f, 0.0f..12.0f, 0.1f).group(Group.Rounding)
82+
val curveTessellationTol by setting("Curve Tessellation Tol", 1.25f, 0.1f..10.0f, 0.05f).group(Group.Rounding)
6983

70-
val moduleEnabledColor by setting("Module Enabled Color", Color.WHITE.setAlpha(0.4))
71-
val moduleDisabledColor by setting("Module Disabled Color", Color.WHITE.setAlpha(0.0))
72-
val moduleHoverAccent by setting("Module Hover Accent", 0.15, 0.0..0.3, 0.01)
73-
val moduleOpenAccent by setting("Module Open Accent", 0.3, 0.0..0.5, 0.01)
84+
// Font
85+
val fontScale by setting("Font Scale", 1.0, 0.5..2.0, 0.1).group(Group.Font)
7486

75-
val multipleSettingWindows by setting("Multiple Setting Windows", false)
87+
// Colors
88+
val text by setting("Text", Color(255, 255, 255)).group(Group.Colors)
89+
val textDisabled by setting("Text Disabled", Color(128, 128, 128)).group(Group.Colors)
90+
val windowBg by setting("Window Background", Color(15, 15, 15, 240)).group(Group.Colors)
91+
val childBg by setting("Child Background", Color(0, 0, 0, 0)).group(Group.Colors)
92+
val popupBg by setting("Popup Background", Color(20, 20, 20, 240)).group(Group.Colors)
93+
val border by setting("Border", Color(110, 110, 128, 128)).group(Group.Colors)
94+
val borderShadow by setting("Border Shadow", Color(0, 0, 0, 0)).group(Group.Colors)
95+
val frameBg by setting("Frame Background", Color(66, 66, 66, 138)).group(Group.Colors)
96+
val frameBgHovered by setting("Frame Background Hovered", Color(66, 150, 255, 102)).group(Group.Colors)
97+
val frameBgActive by setting("Frame Background Active", Color(66, 150, 255, 171)).group(Group.Colors)
98+
val titleBg by setting("Title Background", Color(20, 20, 20, 255)).group(Group.Colors)
99+
val titleBgActive by setting("Title Background Active", Color(41, 79, 120, 255)).group(Group.Colors)
100+
val titleBgCollapsed by setting("Title Background Collapsed", Color(0, 0, 0, 130)).group(Group.Colors)
101+
val menuBarBg by setting("MenuBar Background", Color(36, 36, 36, 255)).group(Group.Colors)
102+
val scrollbarBg by setting("Scrollbar Background", Color(5, 5, 5, 135)).group(Group.Colors)
103+
val scrollbarGrab by setting("Scrollbar Grab", Color(79, 79, 79, 255)).group(Group.Colors)
104+
val scrollbarGrabHovered by setting("Scrollbar Grab Hovered", Color(105, 105, 105, 255)).group(Group.Colors)
105+
val scrollbarGrabActive by setting("Scrollbar Grab Active", Color(130, 130, 130, 255)).group(Group.Colors)
106+
val checkMark by setting("Check Mark", Color(66, 150, 255, 255)).group(Group.Colors)
107+
val sliderGrab by setting("Slider Grab", Color(61, 134, 204, 255)).group(Group.Colors)
108+
val sliderGrabActive by setting("Slider Grab Active", Color(66, 150, 255, 255)).group(Group.Colors)
109+
val button by setting("Button", Color(66, 150, 255, 102)).group(Group.Colors)
110+
val buttonHovered by setting("Button Hovered", Color(66, 150, 255, 255)).group(Group.Colors)
111+
val buttonActive by setting("Button Active", Color(16, 110, 199, 255)).group(Group.Colors)
112+
val header by setting("Header", Color(66, 150, 255, 79)).group(Group.Colors)
113+
val headerHovered by setting("Header Hovered", Color(66, 150, 255, 204)).group(Group.Colors)
114+
val headerActive by setting("Header Active", Color(66, 150, 255, 255)).group(Group.Colors)
115+
val separator by setting("Separator", Color(110, 110, 128, 128)).group(Group.Colors)
116+
val separatorHovered by setting("Separator Hovered", Color(26, 96, 171, 199)).group(Group.Colors)
117+
val separatorActive by setting("Separator Active", Color(26, 96, 171, 255)).group(Group.Colors)
118+
val resizeGrip by setting("Resize Grip", Color(66, 150, 255, 51)).group(Group.Colors)
119+
val resizeGripHovered by setting("Resize Grip Hovered", Color(66, 150, 255, 171)).group(Group.Colors)
120+
val resizeGripActive by setting("Resize Grip Active", Color(66, 150, 255, 242)).group(Group.Colors)
121+
val tab by setting("Tab", Color(46, 81, 122, 219)).group(Group.Colors)
122+
val tabHovered by setting("Tab Hovered", Color(66, 150, 255, 204)).group(Group.Colors)
123+
val tabActive by setting("Tab Active", Color(51, 105, 166, 255)).group(Group.Colors)
124+
val tabUnfocused by setting("Tab Unfocused", Color(18, 32, 48, 248)).group(Group.Colors)
125+
val tabUnfocusedActive by setting("Tab Unfocused Active", Color(36, 71, 110, 255)).group(Group.Colors)
126+
val dockingPreview by setting("Docking Preview", Color(66, 150, 255, 179)).group(Group.Colors)
127+
val dockingEmptyBg by setting("Docking Empty Background", Color(51, 51, 51, 255)).group(Group.Colors)
128+
val plotLines by setting("Plot Lines", Color(156, 156, 156, 255)).group(Group.Colors)
129+
val plotLinesHovered by setting("Plot Lines Hovered", Color(255, 110, 89, 255)).group(Group.Colors)
130+
val plotHistogram by setting("Plot Histogram", Color(230, 179, 0, 255)).group(Group.Colors)
131+
val plotHistogramHovered by setting("Plot Histogram Hovered", Color(255, 153, 0, 255)).group(Group.Colors)
132+
val tableHeaderBg by setting("Table Header Background", Color(48, 48, 51, 255)).group(Group.Colors)
133+
val tableBorderStrong by setting("Table Border Strong", Color(84, 84, 92, 255)).group(Group.Colors)
134+
val tableBorderLight by setting("Table Border Light", Color(68, 68, 74, 255)).group(Group.Colors)
135+
val tableRowBg by setting("Table Row Background", Color(0, 0, 0, 0)).group(Group.Colors)
136+
val tableRowBgAlt by setting("Table Row Background Alt", Color(255, 255, 255, 15)).group(Group.Colors)
137+
val textSelectedBg by setting("Text Selected Background", Color(66, 150, 255, 89)).group(Group.Colors)
138+
val dragDropTarget by setting("Drag Drop Target", Color(255, 255, 0, 230)).group(Group.Colors)
139+
val navHighlight by setting("Nav Highlight", Color(66, 150, 255, 255)).group(Group.Colors)
140+
val navWindowingHighlight by setting("Nav Windowing Highlight", Color(255, 255, 255, 179)).group(Group.Colors)
141+
val navWindowingDimBg by setting("Nav Windowing Dim Background", Color(204, 204, 204, 51)).group(Group.Colors)
142+
val modalWindowDimBg by setting("Modal Window Dim Background", Color(20, 20, 20, 89)).group(Group.Colors)
76143

77-
val hudPadding by setting("Hud Padding", 3.0, 0.0..10.0, 0.1)
78144

79145
val Screen?.hasInput: Boolean
80146
get() = this is ChatScreen ||
81147
this is SignEditScreen ||
82148
this is AnvilScreen ||
83149
this is CommandBlockScreen
84150

85-
init {
86-
/*listenUnsafe<KeyboardEvent.Press> {
87-
if (it.translated == keybind && it.isReleased)
88-
toggle()
89-
}*/
151+
fun applyStyle(scale: Float) {
152+
val style = ImGui.getStyle()
153+
154+
style.alpha = alpha
155+
style.disabledAlpha = disabledAlpha
156+
style.windowPadding.set(windowPaddingX * scale, windowPaddingY * scale)
157+
style.windowMinSize.set(windowMinSizeX * scale, windowMinSizeY * scale)
158+
style.windowTitleAlign.set(windowTitleAlignX, windowTitleAlignY)
159+
style.windowRounding = windowRounding * scale
160+
style.windowBorderSize = windowBorderSize * scale
161+
style.childRounding = childRounding * scale
162+
style.childBorderSize = childBorderSize * scale
163+
style.popupRounding = popupRounding * scale
164+
style.popupBorderSize = popupBorderSize * scale
165+
style.framePadding.set(framePaddingX * scale, framePaddingY * scale)
166+
style.frameRounding = frameRounding * scale
167+
style.frameBorderSize = frameBorderSize * scale
168+
style.itemSpacing.set(itemSpacingX * scale, itemSpacingY * scale)
169+
style.itemInnerSpacing.set(itemInnerSpacingX * scale, itemInnerSpacingY * scale)
170+
style.indentSpacing = indentSpacing * scale
171+
style.scrollbarSize = scrollbarSize * scale
172+
style.scrollbarRounding = scrollbarRounding * scale
173+
style.grabMinSize = grabMinSize * scale
174+
style.grabRounding = grabRounding * scale
175+
style.tabRounding = tabRounding * scale
176+
style.tabBorderSize = tabBorderSize * scale
177+
style.curveTessellationTol = curveTessellationTol * scale
90178

179+
setColor(ImGuiCol.Text, text)
180+
setColor(ImGuiCol.TextDisabled, textDisabled)
181+
setColor(ImGuiCol.WindowBg, windowBg)
182+
setColor(ImGuiCol.ChildBg, childBg)
183+
setColor(ImGuiCol.PopupBg, popupBg)
184+
setColor(ImGuiCol.Border, border)
185+
setColor(ImGuiCol.BorderShadow, borderShadow)
186+
setColor(ImGuiCol.FrameBg, frameBg)
187+
setColor(ImGuiCol.FrameBgHovered, frameBgHovered)
188+
setColor(ImGuiCol.FrameBgActive, frameBgActive)
189+
setColor(ImGuiCol.TitleBg, titleBg)
190+
setColor(ImGuiCol.TitleBgActive, titleBgActive)
191+
setColor(ImGuiCol.TitleBgCollapsed, titleBgCollapsed)
192+
setColor(ImGuiCol.MenuBarBg, menuBarBg)
193+
setColor(ImGuiCol.ScrollbarBg, scrollbarBg)
194+
setColor(ImGuiCol.ScrollbarGrab, scrollbarGrab)
195+
setColor(ImGuiCol.ScrollbarGrabHovered, scrollbarGrabHovered)
196+
setColor(ImGuiCol.ScrollbarGrabActive, scrollbarGrabActive)
197+
setColor(ImGuiCol.CheckMark, checkMark)
198+
setColor(ImGuiCol.SliderGrab, sliderGrab)
199+
setColor(ImGuiCol.SliderGrabActive, sliderGrabActive)
200+
setColor(ImGuiCol.Button, button)
201+
setColor(ImGuiCol.ButtonHovered, buttonHovered)
202+
setColor(ImGuiCol.ButtonActive, buttonActive)
203+
setColor(ImGuiCol.Header, header)
204+
setColor(ImGuiCol.HeaderHovered, headerHovered)
205+
setColor(ImGuiCol.HeaderActive, headerActive)
206+
setColor(ImGuiCol.Separator, separator)
207+
setColor(ImGuiCol.SeparatorHovered, separatorHovered)
208+
setColor(ImGuiCol.SeparatorActive, separatorActive)
209+
setColor(ImGuiCol.ResizeGrip, resizeGrip)
210+
setColor(ImGuiCol.ResizeGripHovered, resizeGripHovered)
211+
setColor(ImGuiCol.ResizeGripActive, resizeGripActive)
212+
setColor(ImGuiCol.Tab, tab)
213+
setColor(ImGuiCol.TabHovered, tabHovered)
214+
setColor(ImGuiCol.TabActive, tabActive)
215+
setColor(ImGuiCol.TabUnfocused, tabUnfocused)
216+
setColor(ImGuiCol.TabUnfocusedActive, tabUnfocusedActive)
217+
setColor(ImGuiCol.DockingPreview, dockingPreview)
218+
setColor(ImGuiCol.DockingEmptyBg, dockingEmptyBg)
219+
setColor(ImGuiCol.PlotLines, plotLines)
220+
setColor(ImGuiCol.PlotLinesHovered, plotLinesHovered)
221+
setColor(ImGuiCol.PlotHistogram, plotHistogram)
222+
setColor(ImGuiCol.PlotHistogramHovered, plotHistogramHovered)
223+
setColor(ImGuiCol.TableHeaderBg, tableHeaderBg)
224+
setColor(ImGuiCol.TableBorderStrong, tableBorderStrong)
225+
setColor(ImGuiCol.TableBorderLight, tableBorderLight)
226+
setColor(ImGuiCol.TableRowBg, tableRowBg)
227+
setColor(ImGuiCol.TableRowBgAlt, tableRowBgAlt)
228+
setColor(ImGuiCol.TextSelectedBg, textSelectedBg)
229+
setColor(ImGuiCol.DragDropTarget, dragDropTarget)
230+
setColor(ImGuiCol.NavHighlight, navHighlight)
231+
setColor(ImGuiCol.NavWindowingHighlight, navWindowingHighlight)
232+
setColor(ImGuiCol.NavWindowingDimBg, navWindowingDimBg)
233+
setColor(ImGuiCol.ModalWindowDimBg, modalWindowDimBg)
234+
}
235+
236+
private fun setColor(imGuiCol: Int, color: Color) {
237+
val style = ImGui.getStyle()
238+
val comp = color.getRGBComponents(null)
239+
style.setColor(imGuiCol, comp[0], comp[1], comp[2], comp[3])
240+
}
241+
242+
init {
91243
onEnable {
92244
// When there is a screen active, we don't want to replace the screen because it will interfere with the
93245
// game.

0 commit comments

Comments
 (0)