-
Notifications
You must be signed in to change notification settings - Fork 19
Line formattting
Cecil edited this page Jun 3, 2018
·
1 revision
I spent a few hours playing around and came up this user widget to format lines.
class Row < Shoes::Widget
attr_accessor :width, :align, :color, :back, :font, :size
def initialize(fmts)
@width = []
@align = []
@color = []
@back = []
@font = []
@size = []
fmts.each do |f|
@width << f[:width] || 100
@align << f[:align] || "left"
@color << f[:color] || black
@back << (f[:background] ? f[:background] : white)
@font << (f[:font] ? f[:font] : "Arial")
@size << f[:size] || 12
end
end
def create(values)
flow do
values.each_index do |i|
flow width: @width[i] do
background @back[i]
para values[i], align: @align[i], stroke: @color[i], font: @font[i], size: @size[i]
end
end
end
end
end
Shoes.app resizable: true do
@r = row [{width: 40, align: "right", color: green},
{width: 100, align: "left", color: black},
{width: 200, align: "center", color: blue},
{width: 50, background: lightpink}]
stack height: 200 ,width: 400, scroll: true do
@r.create ["1","foobar","really long string"]
@r.create ["2","not here","sort of a long string"]
@r.create ["x","hmm","nothing to see"]
@r.color[0] = red
@r.create ["error", 12.45, "foo"]
@r.color[0] = green
@r.back[1] = lightgrey
@r.font[2] = "Mono"
@r.size[2] = 10
@r.create [5, "oops, this overlows the field", "still working..."]
@r.back[1] = white
@r.create [6, 'a', 'b', 'c']
end
end
It's probably overkill and not powerful enough at the same time.