Skip to content

Commit

Permalink
Added a constructor to ImageModel.kt
Browse files Browse the repository at this point in the history
Added an Image element to the UI framework
  • Loading branch information
Dominic Dolan committed Jul 15, 2020
1 parent 5cf90a0 commit 88c5e90
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
package com.mechanica.engine.models

import com.mechanica.engine.shader.qualifiers.Attribute

class ImageModel(image: Image, vararg inputs: Bindable)
: Model(image, *inputs) {

constructor(image: Image)
: this(image,
Attribute.location(0).vec3().createUnitQuad(),
Attribute.location(1).vec2().createInvertedUnitQuad()
)

var image: Image
get() = inputs[0] as Image
set(value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.mechanica.engine.ui.elements

import com.dubulduke.ui.layout.EditLayout
import com.dubulduke.ui.layout.Layout
import com.mechanica.engine.models.Image
import com.mechanica.engine.text.Font
import com.mechanica.engine.text.Text

Expand All @@ -17,6 +18,11 @@ fun DrawerElement.text(string: String, layout: EditLayout.(p: Layout, s: Layout)
text.copyStyle(this.style)
}

fun DrawerElement.image(image: Image, layout: EditLayout.(p: Layout, s: Layout) -> Unit = {_, _ -> }) {
val element = addChildRenderer { ImageElementRenderer(image) }
element.layout.edit(layout)
}

inline fun DrawerElement.listItem(height: Double = 1.0, block: DrawerElement.() -> Unit) {
val listItem = addChildElement { BoxElement(context) }
listItem.layout.add(listLayout)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.dubulduke.ui.UIContext
import com.dubulduke.ui.render.ElementRenderer
import com.dubulduke.ui.render.RenderDescription
import com.mechanica.engine.drawer.Drawer
import com.mechanica.engine.models.Image
import com.mechanica.engine.text.Text
import com.mechanica.engine.ui.Events
import com.mechanica.engine.ui.style.Style
Expand Down Expand Up @@ -40,35 +41,18 @@ class TextElementRenderer(private var text: Text) : ElementDrawer {
override fun RenderDescription<Style>.draw(draw: Drawer) {
draw.ui.color(style.textColor).origin.relative(0.0, 1.0).text(text, style.fontSize, x, y)
}
//
// private fun getText(): Text {
// val text = text
// val font = font
// val newText = when {
// text == null -> createText(string)
// font != null && text.font !== font -> createText(string)
// text.string != string -> {
// text.string = string
// text
// }
// else -> text
// }
// this.text = newText
// return newText
// }
//
// private fun createText(string: String): Text {
// val font = this.font
// val text = if (font != null) {
// Text(string, font)
// } else {
// Text(string)
// }
// this.text = text
// return text
// }

override fun createElement(context: UIContext<Style, Events>): DrawerElement {
return TextElement(context, this)
}
}

class ImageElementRenderer(private val image: Image): ElementDrawer {
override fun createElement(context: UIContext<Style, Events>): DrawerElement {
return DrawerElement(context, this)
}

override fun RenderDescription<Style>.draw(draw: Drawer) {
draw.ui.image(image, x, y + height, width, -height)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class Style {
var text: String = ""
var fontSize: Double = 1.0
var font: Font? = null
var radius: Double = 0.0

fun add(styleSetter: StyleSetter) {
styleSetter.set(this)
Expand Down

0 comments on commit 88c5e90

Please sign in to comment.