-
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
130 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.github.stivais.ui | ||
|
||
import com.github.stivais.ui.color.Color | ||
import com.github.stivais.ui.constraints.px | ||
import com.github.stivais.ui.constraints.size | ||
import com.github.stivais.ui.elements.block | ||
import com.github.stivais.ui.elements.column | ||
import com.github.stivais.ui.elements.text | ||
import com.github.stivais.ui.events.onClick | ||
import me.odinmain.utils.skyblock.modMessage | ||
|
||
fun basic() = UI { | ||
column { | ||
repeat(5) { | ||
block( | ||
constraints = size(100.px, 100.px), | ||
color = Color.RGB(255, 0, 0) | ||
) { | ||
text(text = "$it") | ||
onClick(0) { | ||
modMessage("Clicked block $it") | ||
true | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
odinmain/src/main/kotlin/com/github/stivais/ui/elements/dsl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,78 @@ | ||
package com.github.stivais.ui.elements | ||
|
||
import com.github.stivais.ui.color.Color | ||
import com.github.stivais.ui.constraints.Constraints | ||
import com.github.stivais.ui.constraints.Measurement | ||
import com.github.stivais.ui.constraints.copyParent | ||
import com.github.stivais.ui.constraints.percent | ||
import com.github.stivais.ui.elements.impl.* | ||
import com.github.stivais.ui.events.onClick | ||
import com.github.stivais.ui.events.onMouseEnterExit | ||
import com.github.stivais.ui.utils.animate | ||
import com.github.stivais.ui.utils.seconds | ||
|
||
fun Element.button( | ||
constraints: Constraints? = null, | ||
offColor: Color = Color.RGB(38, 38, 38), | ||
onColor: Color = Color.RGB(50, 150, 220), | ||
on: Boolean = false, | ||
radii: FloatArray? = null, | ||
dsl: Block.() -> Unit | ||
): Block { | ||
val mainColor = Color.Animated(offColor, onColor, on) | ||
val hoverColor = Color.Animated(Color.TRANSPARENT, Color.RGB(255, 255, 255, 0.05f)) | ||
|
||
return block(constraints, mainColor, radii) { | ||
block(copyParent(), color = hoverColor, radius = radii) { | ||
onMouseEnterExit { | ||
hoverColor.animate(0.25.seconds) | ||
true | ||
} | ||
} | ||
onClick(0) { | ||
mainColor.animate(0.15.seconds) | ||
false | ||
} | ||
dsl() | ||
} | ||
} | ||
|
||
fun Element.column(constraints: Constraints? = null, block: Column.() -> Unit = {}): Column { | ||
val column = Column(constraints) | ||
addElement(column) | ||
column.block() | ||
return column | ||
} | ||
|
||
// todo: improve outline color | ||
fun Element.block( | ||
constraints: Constraints? = null, | ||
color: Color, | ||
radius: FloatArray? = null, | ||
block: Block.() -> Unit = {} | ||
): Block { | ||
val block = if (radius != null) RoundedBlock(constraints, color, radius) else Block(constraints, color) | ||
addElement(block) | ||
block.block() | ||
return block | ||
} | ||
|
||
fun Element.text( | ||
text: String, | ||
at: Constraints? = null, | ||
size: Measurement = 50.percent, | ||
color: Color = Color.WHITE, | ||
block: Text.() -> Unit = {} | ||
): Text { | ||
val text = Text(text, color, at, size) | ||
addElement(text) | ||
text.block() | ||
return text | ||
} | ||
|
||
fun Element.group(constraints: Constraints? = null, block: Group.() -> Unit = {}): Group { | ||
val column = Group(constraints) | ||
addElement(column) | ||
column.block() | ||
return column | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters