Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- object Indented {
- var space = ""
- }
- class Indenter {
- val result = new StringBuffer()
- def doIndent() = { Indented.space = Indented.space + " " }
- def unIndent() = { Indented.space = Indented.space.substring(2) }
- def iprintln(a:Any) = result append (Indented.space + a + "\n")
- def println(a:Any) = result append (a + "\n")
- override def toString = result.toString
- }
- object TextStyle extends Enumeration {
- type TextStyle = Value;
- val bold, italic, regular = Value;
- }
- object HAlign extends Enumeration {
- type HAlign = Value;
- val left, center, right = Value;
- }
- object VAlign extends Enumeration {
- type VAlign = Value;
- val top, middle, bottom = Value;
- }
- // Note reversed order!! BBGGRR
- class Color(hexa:String) {
- assume(hexa.length == 8 && hexa.startsWith("0x"), "Invalid Color Format " + hexa)
- val blue = hexa.substring(2,4).toInt
- val green = hexa.substring(4,6).toInt
- val red = hexa.substring(6,8).toInt
- override def toString = "rgb("+red+","+green+","+blue+")"
- }
- case class Font(face:String,size:Int,style:TextStyle.TextStyle)
- /* TODO: currently we don't support conditional sizes and this *may* require
- * changes. Anyway, when traversing the AST simply make sure that the
- * Expr is a Dim */
- trait Expr
- trait DirectExpr extends Expr /* Anything but conditions */
- case class Literal[T](value:T) extends DirectExpr
- case class Var(id:String) extends DirectExpr
- case class PropVar(loc:String, id:String) extends DirectExpr
- case class Sum(add:List[DirectExpr], sub:List[DirectExpr]) extends DirectExpr
- case class Prod(mul:List[DirectExpr], div:List[DirectExpr]) extends DirectExpr
- case class Conj(elems:List[DirectExpr]) extends DirectExpr
- case class Disnj(elems:List[DirectExpr]) extends DirectExpr
- case class Comp(left:DirectExpr,right:DirectExpr) extends DirectExpr
- case class Cond(conds:List[(Expr,Expr)], otherwise:Expr) extends Expr
- /**
- * None = Automatic size
- * Some(DirectExpr) = Custom size
- */
- trait Widget {
- def kind(): String
- def properties(): Map[String,Expr]
- def width(): Option[DirectExpr]
- def height(): Option[DirectExpr]
- def hasChildren (): Boolean
- def getChildren (): Iterable[Widget]
- }
- abstract class WidgetImp(k:String, w:Option[DirectExpr],h:Option[DirectExpr],p:Map[String,Expr],hc:Boolean,gc:Iterable[Widget]) extends Widget {
- def kind = k
- def properties = p
- def width = w
- def height = h
- def hasChildren = hc
- def getChildren = gc
- override def toString(): String = {
- var i = new Indenter();
- i.iprintln("Widget of type: " + k)
- i.iprintln("It's dimensions are: " + width + "x" + height)
- i.iprintln("It's properties are:")
- i.doIndent()
- p.keys map { key => i.iprintln(key + " = " + p(key))}
- i.unIndent()
- if (hc) {
- i.iprintln ("It has the following children: ")
- i.doIndent()
- gc map { child => i.println(child)}
- i.unIndent()
- }
- return i.toString
- }
- }
- /* An atomic widget is either one of the built in widgets, or one which was defined
- * as a "subprogram" somewhere else
- * Note that for the empty widget, we will use the empty string as it's kind
- */
- class AtomicWidget(k:String, w:Option[DirectExpr],h:Option[DirectExpr],p:Map[String,Expr]) extends
- WidgetImp(k,w,h,p,false,List())
- class HVContainer(ws:List[Widget], isVertical:Boolean) extends
- WidgetImp(if (isVertical) "---" else "|", None, None, Map(), true, ws)
- class OneContainer(ws:Widget, w:Option[DirectExpr], h:Option[DirectExpr], p:Map[String,Expr]) extends
- WidgetImp("@", w, h, p, true, List(ws))
Advertisement
Add Comment
Please, Sign In to add comment