All Downloads are FREE. Search and download functionalities are using the official Maven repository.
Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
io.docops.asciidoc.buttons.RectangleCardRenderer.kt Maven / Gradle / Ivy
package io.docops.asciidoc.buttons
import io.docops.asciidoc.buttons.models.Button
import io.docops.asciidoc.buttons.theme.Theme
import io.docops.asciidoc.utils.escapeXml
class RectangleCardRenderer : ButtonMaker() {
private var spacer = 15
override fun makeButtons(buttons: MutableList>, theme: Theme): String {
//turn of legend as this does not support legend
theme.legendOn = false
val sb = StringBuilder(
makeSvgHead(
buttons = buttons,
heightFactor = 135,
defaultHeight = 110,
widthFactor = 300,
theme = theme
)
)
val styles = makeStyles(buttons, theme)
if(!theme.isPDF) {
sb.append(styles)
}
sb.append(makeDefs(buttons, theme))
sb.append("")
var row = 0
var column = 0
var count = 0
buttons.forEachIndexed { index, btns ->
btns.forEachIndexed { current, item ->
sb.append(createItem(button = item, row, column, theme, count++))
column++
}
row++
column = 0
}
sb.append(" ")
sb.append("")
return sb.toString()
}
private fun makeStyles(buttonList: MutableList>, theme: Theme): String {
val btnGrad = StringBuilder()
buttonList.forEach { buttons ->
buttons.forEach {
item -> theme.buttonTextColor(item)
btnGrad.append(theme.buildGradientStyle(item))
}
}
//language=html
var str = """
""".trimIndent()
return str
}
private fun createItem(button: Button, row: Int, column: Int, theme: Theme, itemIndex: Int): String {
var window = "_top"
if(theme.newWin) {
window = "_blank"
}
val rowHeight = 120
val itemHeight = (rowHeight * (row)) + 10 + (row * spacer)
val width = 293
val itemWidth = (column) * width + 10 + (spacer*column)
val contentBox = if(button.buttonImage!= null) {
makeButtonImage(button,x = itemWidth+12,y = itemHeight+15, itemIndex )
} else {
makeNumberedButtonImage(button, x = itemWidth+12,y = itemHeight+15, itemIndex, window)
}
//language=svg
return """
${button.title.escapeXml()}
${contentBox}
${makeLinks(itemWidth+15+105, itemHeight + 30, button, window)}
""".trimIndent()
}
private fun makeLinks(x: Int, y: Int, button: Button, window: String): String {
val sb = StringBuilder()
sb.append("""""".trimIndent())
var downBy = 16
button.links?.forEachIndexed { index, link ->
if(index > 0) {
downBy = 20
}
sb.append("""${link.label} """)
}
sb.append(" ")
return sb.toString()
}
private fun makeButtonImage(button: Button, x: Int, y: Int, itemIndex: Int): String {
button.buttonImage?.let {
return """
""".trimIndent()
}
return ""
}
private fun makeNumberedButtonImage(button: Button, x: Int, y: Int, itemIndex: Int, window: String) : String {
var disp = "${itemIndex+1}"
if(button.leadingZeroNumbersOn && itemIndex < 9) {
disp = "0${disp}"
}
return """
$disp
""".trimIndent()
}
private fun createDefs(buttons: MutableList>, theme: Theme): String {
return """ """
}
}