Skip to content

Commit ca27cd4

Browse files
committed
feat(shale): minecraft component
1 parent 963fd40 commit ca27cd4

File tree

5 files changed

+86
-32
lines changed

5 files changed

+86
-32
lines changed

build-src/src/main/kotlin/moulconfig.leaf.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ dependencies {
1818
shadowInclude(Dependencies.LIB_NINE_PATCH)
1919
compileOnly(Dependencies.JB_ANNOTATIONS)
2020
compileOnly(Dependencies.JSPECIFY)
21+
"implementation"(project(":shale"))
22+
shadowInclude(project(":shale"))
2123
}
2224

2325
val shadowJar by tasks.named("shadowJar", ShadowJar::class) {

modern/templates/java/io/github/notenoughupdates/moulconfig/test/FabricMain.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import io.github.notenoughupdates.moulconfig.platform.MoulConfigPlatform
1010
import io.github.notenoughupdates.moulconfig.platform.MoulConfigScreenComponent
1111
import io.github.notenoughupdates.moulconfig.xml.Bind
1212
import io.github.notenoughupdates.moulconfig.xml.XMLUniverse
13+
import moe.nea.shale.render.minecraft.ShaleComponent
14+
import moe.nea.shale.util.ExampleTrees
1315
import net.fabricmc.api.ModInitializer
1416
import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal
1517
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback
@@ -35,6 +37,13 @@ class FabricMain : ModInitializer {
3537
}
3638
0
3739
})
40+
a.register(literal("shaleuitest").executes {
41+
MinecraftClient.getInstance().send {
42+
val tree = ExampleTrees.boxes
43+
ShaleComponent(tree).openScreen()
44+
}
45+
0
46+
})
3847
a.register(literal("moulconfigxml").executes {
3948
MinecraftClient.getInstance().send {
4049
val xmlUniverse =
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package moe.nea.shale.render.minecraft
2+
3+
import io.github.notenoughupdates.moulconfig.common.IMinecraft
4+
import io.github.notenoughupdates.moulconfig.gui.GuiComponent
5+
import io.github.notenoughupdates.moulconfig.gui.GuiImmediateContext
6+
import moe.nea.shale.layout.RootElement
7+
import moe.nea.shale.layout.Size
8+
import moe.nea.shale.layout.Sizing
9+
10+
class ShaleComponent(val tree: RootElement) : GuiComponent() {
11+
override fun getWidth(): Int {
12+
return 0
13+
}
14+
15+
override fun getHeight(): Int {
16+
return 0
17+
}
18+
19+
override fun render(context: GuiImmediateContext) {
20+
tree.sizing = Sizing.Fixed(Size(context.width, context.height))
21+
val context = MinecraftGraphicsContext(context.renderContext)
22+
tree.relayout(context)
23+
tree.render(context)
24+
}
25+
26+
fun openScreen() {
27+
IMinecraft.instance.openWrappedScreen(this)
28+
}
29+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package moe.nea.shale.util
2+
3+
import moe.nea.shale.dsl.box
4+
import moe.nea.shale.dsl.buildShaleLayout
5+
import moe.nea.shale.dsl.text
6+
import java.awt.Color
7+
8+
object ExampleTrees {
9+
val boxes = buildShaleLayout {
10+
box {
11+
ltr()
12+
padding(10)
13+
childGap(10)
14+
grow()
15+
box {
16+
ttb()
17+
background(Color.RED)
18+
box {
19+
background(Color.BLUE)
20+
text("Goodbye, World!") {
21+
color(Color.WHITE)
22+
}
23+
}
24+
grow()
25+
}
26+
box {
27+
background(Color.GREEN)
28+
grow()
29+
}
30+
box {
31+
background(Color.CYAN)
32+
fixed(200, 100)
33+
}
34+
box {
35+
background(Color.DARK_GRAY)
36+
padding(10)
37+
text("Hello, World!") {
38+
color(Color.WHITE)
39+
}
40+
}
41+
}
42+
}
43+
44+
}

shale/src/test/kotlin/moe/nea/shale/test/TestGui.kt

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,18 @@
11
package moe.nea.shale.test
22

3-
import moe.nea.shale.dsl.box
4-
import moe.nea.shale.dsl.buildShaleLayout
5-
import moe.nea.shale.dsl.text
63
import moe.nea.shale.layout.Size
74
import moe.nea.shale.layout.Sizing
85
import moe.nea.shale.render.awt.AwtGraphicsContext
6+
import moe.nea.shale.util.ExampleTrees
97
import java.awt.BorderLayout
10-
import java.awt.Color
118
import java.awt.Dimension
129
import java.awt.Graphics
1310
import javax.swing.JFrame
1411
import javax.swing.JPanel
1512
import javax.swing.SwingUtilities
1613

1714
class TestGui : JPanel() {
18-
val tree = buildShaleLayout {
19-
box {
20-
ltr()
21-
padding(10)
22-
childGap(10)
23-
grow()
24-
box {
25-
background(Color.RED)
26-
grow()
27-
}
28-
box {
29-
background(Color.GREEN)
30-
grow()
31-
}
32-
box {
33-
background(Color.CYAN)
34-
fixed(200, 100)
35-
}
36-
box {
37-
background(Color.DARK_GRAY)
38-
padding(10)
39-
text("Hello, World!") {
40-
color(Color.WHITE)
41-
}
42-
}
43-
}
44-
}
45-
15+
val tree = ExampleTrees.boxes
4616
override fun paintComponent(g: Graphics?) {
4717
super.paintComponent(g)
4818
tree.sizing = Sizing.Fixed(Size.coerced(width, height))

0 commit comments

Comments
 (0)