Skip to content

Instantly share code, notes, and snippets.

@TheBizzle
Forked from qiemem/gist:64f789287fee65d46c5b
Created September 26, 2014 21:41
Show Gist options
  • Select an option

  • Save TheBizzle/0035a7c6f242a616b12e to your computer and use it in GitHub Desktop.

Select an option

Save TheBizzle/0035a7c6f242a616b12e to your computer and use it in GitHub Desktop.
def compile[T, W <: Widget](model: CompiledModel)(widget: W): CompiledWidget[W] = {
def compileCmd(code: String) = model.compileCommand(sanitizeSource(code))
def compileRep(code: String) = model.compileReporter(sanitizeSource(code))
def compilePen(pen: Pen) = CompiledPen(pen, compileCmd(pen.setupCode), compileCmd(pen.updateCode))
widget match {
case v: View => CompiledView(v)
case b: Button => CompiledButton(b, compileCmd(b.source))
case p: Plot => CompiledPlot(p, compileCmd(p.setupCode), compileCmd(p.updateCode), p.pens map compilePen)
case p: Pen => compilePen(p)
case t: TextBox => CompiledTextBox(t)
case s: Slider => CompiledSlider(s, compileRep(s.min), compileRep(s.max), compileRep(s.step))
case s: Switch => CompiledSwitch(s)
case m: Monitor => CompiledMonitor(m, compileRep(s"precision ( ${m.source} ) ${m.precision}"))
case c: Chooser => CompiledChooser(c)
case i: InputBox[T] => CompiledInputBox[T](i)
case o: Output => CompiledOutput(o)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment