M
Michael Neumann
On Fri, 22 Oct 2004 07:36:12 +0900,
Who does all of this drawing? It looks like some unknown power is doing
(and knowing) way too much.
The component! For example the button component has to draw itself onto
the screen, for which it needs a canvas.
Well, my example above was not good choosen. Better would have been:
class Button < Component
# this one is called from 'outside'
def draw_on(canvas)
draw_frame(canvas)
draw_inner(canvas)
end
private
# helper method
def draw_frame(canvas)
if @pressed
canvas.color = :lightgray
canvas.line(x, y, x+w, y)
canvas.line(x+w, y, x+w, y+h)
...
else
...
end
end
# helper method
def draw_inner(canvas)
canvas.text(@caption)
end
end
Of course the canvas implements the drawing primitives.
Now think the same for the Web and Html generation.
If I were the renderer, I'd have a headache from all the knowledge that
you must have stuffed into my poor brain There must be a better way
to do this.
Hm, but somewhere you have to implement how the component looks like, no?
The above is equivalent to:
cgi.table {
cgi.tr {
cgi.td { ... } +
cgi.td { ... }
}
}
But in a more imperatively fashion, similar as for drawing a GUI on the
canvas, where you don't do this ('+'):
canvas.box(...) {
canvas.line(1, 1, 10, 10) +
canvas.line(...) +
...
}
Regards,
Michael