Componency
A library for creating user interfaces, developed from scratch to work in any environment. Based on a declarative programming approach, making the UI creation process simple and intuitive.
Inspiration and Concept
Componency draws ideas from several projects:
- Elementa's design
- Figma's naming conventions
- Ktor's DSL approach
This library combines best practices from these projects, offering a convenient solution for building interfaces.
Usage Features
The library is primarily focused on Kotlin but also supports working with Java. All examples in the documentation are presented in Kotlin, but the functionality is available for Java developers as well.
Project Setup
Adding Repository
For Groovy (.gradle):
maven {
name = "Deftu Snapshots"
url = "https://maven.deftu.dev/snapshots"
}
For Kotlin (.gradle.kts):
maven(url = "https://maven.deftu.dev/snapshots") {
name = "Deftu Snapshots"
}
Adding Dependency
For Groovy (.gradle):
modImplementation "dev.deftu:componency:<version>"
For Kotlin (.gradle.kts):
implementation("dev.deftu:componency:<version>")
Basic Operation
Creating Engine
To use the library, you need to create a Componency engine that provides interaction with the rendering system:
package com.example
import dev.deftu.componency.engine.Engine
import dev.deftu.componency.engine.InputEngine
import dev.deftu.componency.engine.RenderEngine
import java.awt.Color
class MyEngine : Engine {
override val inputEngine: InputEngine by lazy {
MyInputEngine()
}
override val renderEngine: RenderEngine by lazy {
MyRenderEngine()
}
}
class MyInputEngine : InputEngine {
override val mouseX: Float = 0f
override val mouseY: Float = 0f
}
class MyRenderEngine : RenderEngine {
override val viewportWidth: Int = 0
override val viewportHeight: Int = 0
override val animationFps: Int = 144 // Recommended no more than 300
override fun startFrame() {
// Start frame rendering (apply transformations, etc.)
}
override fun endFrame() {
// End frame rendering (apply transformations, etc.)
}
override fun fill(x1: Float, y1: Float, x2: Float, y2: Float, color: Color, radius: Float) {
// Fill rectangle with color and specified radius
}
}
Creating User Interface
After setting up the engine, you can start creating UI:
object Main {
@JvmStatic
fun main(args: Array<String>) {
val engine = MyEngine()
val ui = MyUI(engine)
// In the rendering loop, simply call ui.render() to display the interface
ui.render() // (This is a placeholder for your actual rendering loop)
}
}
class MyUI(engine: Engine) {
// Typically, a frame is used as the root component
private val frame = FrameComponent().configure {
// In Componency, properties are defined in their own scope during configuration
// Most commonly used properties have extensions for convenient access
properties {
width = 100.percent
height = 100.percent
}
}.makeRoot(engine) // Make the frame the root component of the UI by passing it the engine
private val box = RectangleComponent().configure {
properties {
x = 25.percent
y = 25.percent
width = 50.percent
height = 50.percent
color = Color.RED.asProperty
}
}.attachTo(frame) // Add rectangle as child element of frame
// Here you can add additional components to the frame or rectangle
// Provide external method for rendering our frame
fun render() {
frame.handleRender()
}
}
Additional Examples
For more complex examples, you can check out the basic examples in the corresponding directory (Java, Kotlin).
An implementation example for LWJGL3 is also available.
Usage in Minecraft
Modern Minecraft Versions (1.16.5 and above)
To use in modern Minecraft versions, simply add the dependency to the build script.
For Groovy (.gradle):
modImplementation "dev.deftu:componency-minecraft-<minecraft version>-<mod loader>:<version>"
For Kotlin (.gradle.kts):
implementation("dev.deftu:componency-minecraft-<minecraft version>-<mod loader>:<version>")
Legacy Minecraft Versions (1.12.2 and 1.8.9)
For legacy versions, additional setup is required using a dependency management tweaker that ensures loading of the latest library version and forces the use of LWJGL 3.
For Groovy (.gradle):
dependencies {
modImplementation "dev.deftu:componency-minecraft-<minecraft version>-<mod loader>:<version>"
modImplementation "dev.deftu:componency-minecraft-tweaker-<minecraft version>-<mod loader>:<version>"
}
jar {
manifest {
attributes(
"TweakClass": "dev.deftu.componency.minecraft.tweaker.ComponencyTweaker"
)
}
}
For Kotlin (.gradle.kts):
dependencies {
implementation("dev.deftu:componency-minecraft-<minecraft version>-<mod loader>:<version>")
implementation("dev.deftu:componency-minecraft-tweaker-<minecraft version>-<mod loader>:<version>")
}
tasks.jar {
manifest {
attributes(
"TweakClass" to "dev.deftu.componency.minecraft.tweaker.ComponencyTweaker"
)
}
}
Acknowledgments
- nea89o / HypixelDev - dependency management tweaker for Forge 1.8.9 & 1.12.2
- nextdayy / xtrm / Polyfrost - inspiration for engine setup and LWJGL 3 loader for legacy Minecraft versions
In Development
- Debugger
The project is distributed under LGPL-3.0 license