All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.woojiahao.style.utility.Border.kt Maven / Gradle / Ivy

package com.github.woojiahao.style.utility

import com.github.woojiahao.style.utility.Border.BorderStyle.*
import com.github.woojiahao.utility.cssColor
import java.awt.Color

data class Border(
  var borderWidth: Measurement = 0.0.px,
  var borderStyle: BorderStyle = NONE,
  var borderColor: Color? = Color.BLACK
) {

  enum class BorderStyle {
    DOTTED,
    DASHED,
    SOLID,
    DOUBLE,
    GROOVE,
    RIDGE,
    INSET,
    OUTSET,
    NONE,
    HIDDEN
  }

  fun clear() = set(0.0.px, NONE, Color.BLACK)

  private fun set(
    borderWidth: Measurement,
    borderStyle: BorderStyle,
    borderColor: Color?
  ) {
    this.borderWidth = borderWidth
    this.borderStyle = borderStyle
    this.borderColor = borderColor
  }

  override fun toString() = "$borderWidth ${borderStyle.name.toLowerCase()} ${borderColor?.cssColor()}"
}

infix fun Measurement.dotted(color: Color?) = Border(this, DOTTED, color)

infix fun Measurement.dashed(color: Color?) = Border(this, DASHED, color)

infix fun Measurement.solid(color: Color?) = Border(this, SOLID, color)

infix fun Measurement.double(color: Color?) = Border(this, DOUBLE, color)

infix fun Measurement.groove(color: Color?) = Border(this, GROOVE, color)

infix fun Measurement.ridge(color: Color?) = Border(this, RIDGE, color)

infix fun Measurement.inset(color: Color?) = Border(this, INSET, color)

infix fun Measurement.outset(color: Color?) = Border(this, OUTSET, color)

infix fun Measurement.none(color: Color?) = Border(this, NONE, color)

infix fun Measurement.hidden(color: Color?) = Border(this, HIDDEN, color)




© 2015 - 2024 Weber Informatics LLC | Privacy Policy