Skip to content

Commit 081b677

Browse files
committed
misc ui changes
1 parent 31157fc commit 081b677

File tree

9 files changed

+68
-41
lines changed

9 files changed

+68
-41
lines changed

common/src/main/kotlin/com/lambda/graphics/renderer/gui/font/FontRenderer.kt

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import com.lambda.graphics.shader.Shader.Companion.shader
2727
import com.lambda.graphics.texture.TextureOwner.bind
2828
import com.lambda.module.modules.client.LambdaMoji
2929
import com.lambda.module.modules.client.RenderSettings
30+
import com.lambda.util.math.MathUtils.toInt
3031
import com.lambda.util.math.Vec2d
3132
import com.lambda.util.math.a
3233
import com.lambda.util.math.setAlpha
@@ -69,7 +70,7 @@ object FontRenderer : AbstractGUIRenderer(VertexAttrib.Group.FONT, shader("font/
6970

7071
bind(chars, emojis)
7172

72-
processText(text, color, scale, shadow, parseEmoji) { char, pos1, pos2, col ->
73+
processText(text, color, scale, shadow, parseEmoji) { char, pos1, pos2, col, _ ->
7374
buildGlyph(char, position, pos1, pos2, col)
7475
}
7576
}
@@ -142,7 +143,9 @@ object FontRenderer : AbstractGUIRenderer(VertexAttrib.Group.FONT, shader("font/
142143
parseEmoji: Boolean = LambdaMoji.isEnabled,
143144
): Double {
144145
var width = 0.0
145-
processText(text, scale = scale, parseEmoji = parseEmoji) { char, _, _, _ -> width += char.width }
146+
processText(text, scale = scale, parseEmoji = parseEmoji) {
147+
char, _, _, _, isShadow -> width += char.width * isShadow.toInt()
148+
}
146149
return width * getScaleFactor(scale)
147150
}
148151

@@ -170,7 +173,7 @@ object FontRenderer : AbstractGUIRenderer(VertexAttrib.Group.FONT, shader("font/
170173
scale: Double = 1.0,
171174
shadow: Boolean = RenderSettings.shadow,
172175
parseEmoji: Boolean = LambdaMoji.isEnabled,
173-
block: (GlyphInfo, Vec2d, Vec2d, Color) -> Unit
176+
block: (GlyphInfo, Vec2d, Vec2d, Color, Boolean) -> Unit
174177
) {
175178
val actualScale = getScaleFactor(scale)
176179
val scaledGap = gap * actualScale
@@ -183,13 +186,14 @@ object FontRenderer : AbstractGUIRenderer(VertexAttrib.Group.FONT, shader("font/
183186

184187
fun drawGlyph(info: GlyphInfo?, color: Color, offset: Double = 0.0) {
185188
if (info == null) return
189+
val isShadow = offset != 0.0
186190

187191
val scaledSize = info.size * actualScale
188192
val pos1 = Vec2d(posX, posY) + offset * actualScale
189193
val pos2 = pos1 + scaledSize
190194

191-
block(info, pos1, pos2, color)
192-
if (offset == 0.0) posX += scaledSize.x + scaledGap
195+
block(info, pos1, pos2, color, isShadow)
196+
if (!isShadow) posX += scaledSize.x + scaledGap
193197
}
194198

195199
val parsed = if (parseEmoji) emojis.parse(text) else mutableListOf()
@@ -244,7 +248,7 @@ object FontRenderer : AbstractGUIRenderer(VertexAttrib.Group.FONT, shader("font/
244248
* @param scale The base scale factor.
245249
* @return The adjusted scale factor.
246250
*/
247-
fun getScaleFactor(scale: Double): Double = scale * 9.0 / chars.height
251+
fun getScaleFactor(scale: Double): Double = scale * 8.5 / chars.height
248252

249253
/**
250254
* Calculates the shadow color by adjusting the brightness of the input color.

common/src/main/kotlin/com/lambda/gui/component/layout/Layout.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,19 @@ open class Layout(
317317
overrideHeight(overrideHeight)
318318
}
319319

320+
/**
321+
* Removes this layout from its parent
322+
*/
323+
fun destroy() {
324+
check(owner != null) {
325+
"Unable to destroy root layout. Owner is null."
326+
}
327+
328+
check(owner.children.remove(this)) {
329+
"destroy() called twice. The layout was already removed"
330+
}
331+
}
332+
320333
init {
321334
onUpdate { // Update the layout
322335
screenSize = RenderMain.screenSize

common/src/main/kotlin/com/lambda/gui/component/window/TitleBar.kt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@ package com.lambda.gui.component.window
1919

2020
import com.lambda.module.modules.client.ClickGui
2121
import com.lambda.gui.component.HAlign
22+
import com.lambda.gui.component.core.FilledRect.Companion.rect
2223
import com.lambda.gui.component.core.TextField.Companion.textField
2324
import com.lambda.gui.component.core.UIBuilder
2425
import com.lambda.gui.component.layout.Layout
2526
import com.lambda.util.Mouse
2627
import com.lambda.util.math.Vec2d
28+
import com.lambda.util.math.lerp
2729

2830
/**
2931
* Represents a titlebar component
@@ -58,6 +60,23 @@ class TitleBar(
5860
}
5961
}
6062

63+
val backgroundRect = rect {
64+
onUpdate {
65+
rectangle = this@TitleBar.rect
66+
setColor(ClickGui.titleBackgroundColor)
67+
68+
val radius = ClickGui.roundRadius
69+
leftTopRadius = radius
70+
rightTopRadius = radius
71+
72+
val bottomRadius = lerp(owner.content.renderHeight, radius, 0.0)
73+
leftBottomRadius = bottomRadius
74+
rightBottomRadius = bottomRadius
75+
76+
shade = ClickGui.backgroundShade
77+
}
78+
}
79+
6180
val textField = textField {
6281
text = title
6382

common/src/main/kotlin/com/lambda/gui/component/window/Window.kt

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ open class Window(
4141
owner: Layout,
4242
initialTitle: String = "Untitled",
4343
initialPosition: Vec2d = Vec2d.ZERO,
44-
initialSize: Vec2d = Vec2d(120.0, 300.0),
44+
initialSize: Vec2d = Vec2d(110, 300),
4545
draggable: Boolean = true,
4646
scrollable: Boolean = true,
4747
private val minimizing: Minimizing = Minimizing.Relative,
@@ -52,26 +52,9 @@ open class Window(
5252
private val cursorController = cursorController()
5353

5454
val titleBar = titleBar(initialTitle, draggable)
55-
val content = windowContent(scrollable)
5655

57-
protected val titleBarRect = rect {
58-
onUpdate {
59-
rectangle = titleBar.rect
60-
setColor(ClickGui.titleBackgroundColor)
61-
62-
val radius = ClickGui.roundRadius
63-
leftTopRadius = radius
64-
rightTopRadius = radius
65-
66-
val bottomRadius = lerp(content.renderHeight, radius, 0.0)
67-
leftBottomRadius = bottomRadius
68-
rightBottomRadius = bottomRadius
69-
70-
shade = ClickGui.backgroundShade
71-
}
72-
}
73-
74-
protected val contentRect = rect {
56+
protected val titleBarBackground by titleBar::backgroundRect
57+
protected val contentBackground = rect { // It's here because content cannot contain something by default
7558
onUpdate {
7659
rectangle = Rect(titleBar.leftBottom, this@Window.rightBottom)
7760
setColor(ClickGui.backgroundColor)
@@ -83,6 +66,8 @@ open class Window(
8366
}
8467
}
8568

69+
val content = windowContent(scrollable)
70+
8671
protected val outlineRect = outline {
8772
onUpdate {
8873
rectangle = this@Window.rect

common/src/main/kotlin/com/lambda/gui/component/window/WindowContent.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
package com.lambda.gui.component.window
1919

2020
import com.lambda.graphics.animation.Animation.Companion.exp
21-
import com.lambda.event.events.GuiEvent
2221
import com.lambda.gui.component.core.LayoutBuilder
2322
import com.lambda.module.modules.client.ClickGui
2423
import com.lambda.gui.component.core.UIBuilder

common/src/main/kotlin/com/lambda/gui/impl/clickgui/ModuleLayout.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,13 @@ import java.awt.Color
3333

3434
class ModuleLayout(
3535
owner: Layout,
36-
module: Module
36+
module: Module,
37+
initialPosition: Vec2d = Vec2d.ZERO,
38+
initialSize: Vec2d = Vec2d(100, 18)
3739
) : Window(
3840
owner,
3941
module.name,
40-
Vec2d.ZERO, Vec2d.ZERO,
42+
initialPosition, initialSize,
4143
false, true, Minimizing.Relative, false,
4244
AutoResize.ForceEnabled
4345
) {
@@ -117,12 +119,12 @@ class ModuleLayout(
117119
}
118120
}
119121

120-
titleBarRect.onUpdate {
122+
titleBarBackground.onUpdate {
121123
setColor(lerp(enableAnimation, ClickGui.moduleDisabledColor, ClickGui.moduleEnabledColor))
122124
correctRadius()
123125
}
124126

125-
contentRect.onUpdate {
127+
contentBackground.onUpdate {
126128
setColor(lerp(enableAnimation, ClickGui.moduleDisabledColor, ClickGui.moduleEnabledColor))
127129
correctRadius()
128130
}

common/src/main/kotlin/com/lambda/gui/impl/clickgui/SettingLayout.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ abstract class SettingLayout <V : Any, T: AbstractSetting<V>> (
3535
owner: Layout,
3636
val setting: T,
3737
expandable: Boolean = false
38-
) : Window( // going to use window to easily implement expandable settings (such as color picker)
38+
) : Window(
3939
owner,
4040
setting.name,
4141
Vec2d.ZERO, Vec2d.ZERO,
@@ -73,7 +73,12 @@ abstract class SettingLayout <V : Any, T: AbstractSetting<V>> (
7373
}
7474
}
7575

76-
children.removeAll(listOf(titleBarRect, contentRect, outlineRect))
76+
listOf(
77+
titleBarBackground,
78+
contentBackground,
79+
outlineRect
80+
).forEach(Layout::destroy)
81+
7782
if (!expandable) children.remove(content)
7883
}
7984
}

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,21 @@ object ClickGui : Module(
3232
defaultTags = setOf(ModuleTag.CLIENT)
3333
) {
3434
val titleBarHeight by setting("Title Bar Height", 18.0, 10.0..25.0, 0.1)
35-
val moduleHeight by setting("Module Height", 18.0, 10.0..25.0, 0.1)
35+
val moduleHeight by setting("Module Height", 16.0, 10.0..25.0, 0.1)
3636
val settingsHeight by setting("Settings Height", 14.0, 10.0..25.0, 0.1)
37-
val padding by setting("Padding", 2.0, 1.0..6.0, 0.1)
38-
val listStep by setting("List Step", 2.0, 0.0..6.0, 0.1)
39-
val autoResize by setting("Auto Resize", false)
37+
val padding by setting("Padding", 1.0, 1.0..6.0, 0.1)
38+
val listStep by setting("List Step", 1.0, 0.0..6.0, 0.1)
39+
val autoResize by setting("Auto Resize", true)
4040

4141
val roundRadius by setting("Round Radius", 2.0, 0.0..10.0, 0.1)
4242

4343
val backgroundTint by setting("Background Tint", Color.BLACK.setAlpha(0.4))
4444

45-
val titleBackgroundColor by setting("Title Background Color", Color.WHITE.setAlpha(0.4))
46-
val backgroundColor by setting("Background Color", Color.WHITE.setAlpha(0.25))
45+
val titleBackgroundColor by setting("Title Background Color", Color(40, 40, 40))
46+
val backgroundColor by setting("Background Color", titleBackgroundColor)
4747
val backgroundShade by setting("Background Shade", true)
4848

49-
val outline by setting("Outline", true)
49+
val outline by setting("Outline", false)
5050
val outlineWidth by setting("Outline Width", 10.0, 1.0..10.0, 0.1) { outline }
5151
val outlineColor by setting("Outline Color", Color.WHITE.setAlpha(0.6)) { outline }
5252
val outlineShade by setting("Outline Shade", true) { outline }

common/src/main/resources/assets/lambda/shaders/fragment/renderer/rect_filled.frag

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ in vec4 v_Color;
1919
out vec4 color;
2020

2121
#define SMOOTHING 0.25
22-
#define NOISE_GRANULARITY 0.005
22+
#define NOISE_GRANULARITY 0.004
2323

2424
vec4 noise() {
2525
// https://shader-tutorial.dev/advanced/color-banding-dithering/

0 commit comments

Comments
 (0)