Skip to content

Commit

Permalink
big batch of changes for #410
Browse files Browse the repository at this point in the history
* cassowary-ruby gem may be working correctly - it's hard to KNOW
  can use vfl_parser
* native cassowary (emeus) is not working - but now I have something
  to compare with.
  • Loading branch information
Cecil committed Nov 24, 2018
1 parent d739679 commit 943ba9d
Show file tree
Hide file tree
Showing 17 changed files with 853 additions and 503 deletions.
6 changes: 3 additions & 3 deletions Tests/layout/l3.rb → Tests/layout/cas1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def size(canvas, pass)
#@rl_stay = @solver.add_constraint(@right_limit, Strength::RequiredStrength)
#@solver.add_constraint(@rl_stay)
@solver.solve
self.finish
self.finish(nil)
end
end

Expand All @@ -114,7 +114,7 @@ def rules(arg)
$stderr.puts "callback rules #{arg}"
end

def finish()
def finish(arg)
@widgets.each_pair do |k, widget|
left = widget.left
top = widget.top
Expand Down Expand Up @@ -189,7 +189,7 @@ def method_missing(meth, *args, &block)
# string b3 is at the bottom ?
@ml.add_constraint(@ml.var('b3-top').cn_equal 100)

@lay.finish
@lay.finish(nil)
@p.text = @lay.inspect
end
end
Expand Down
33 changes: 33 additions & 0 deletions Tests/layout/cas2.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
require 'layout/cassowary'

Shoes.app width: 500, height: 400, resizeable: true do
stack do
para "Test vfl parser"
@cls = CassowaryLayout.new()
@lay = layout use: @cls, width: 450, height: 300 do
background cornsilk
para "OverConstrained", name: 'para1'
edit_line "one", name: 'el1'
button "two", name: 'but1'
button "three", name: "but2"
button "four", name: "but3"
end
@lay.start {
metrics = {
padding: 80.7
}
lines = [
"H:|-[para1(but1)]-[but1]-|",
"H:|-[el1(but2)]-[but2]-|",
"H:[but3(but2)]-|",
"V:|-[para1(el1)]-[el1]-|",
"V:|-[but1(but2,but3)]-[but2]-[but3]-|"
]
if @lay.vfl_parse lines: lines, views: @cls.contents, metrics: metrics
constraints = @lay.vfl_constraints
@lay.finish constraints
end
}
end
para "After layout"
end
31 changes: 31 additions & 0 deletions Tests/layout/cas3.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
require 'layout/cassowary'

Shoes.app width: 350, height: 400, resizeable: true do
stack do
para "Test vfl parser"
@cls = CassowaryLayout.new()
@lay = layout use: @cls, width: 300, height: 300 do
background cornsilk
edit_line "one", name: 'el1'
button "two", name: 'but1'
end
@lay.start {
metrics = {
padding: 8
}
lines = [
'[but1]-[el1]'
]
if false
cs = @cls.var('el1','start').cn_equal (@cls.var('but1','end'))
puts cs.inspect
@lay.finish([cs])
else
@lay.vfl_parse lines: lines, views: @cls.contents, metrics: metrics
constraints = @lay.vfl_constraints
@lay.finish constraints
end
}
end
para "After layout"
end
25 changes: 25 additions & 0 deletions Tests/layout/cas4.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require 'layout/cassowary'

Shoes.app width: 350, height: 400, resizeable: true do
stack do
para "Test vfl parser"
@cls = CassowaryLayout.new()
@lay = layout use: @cls, width: 300, height: 300 do
background cornsilk
edit_line "one", name: 'el1'
button "two", name: 'but1'
end
@lay.start {
metrics = {
padding: 25
}
lines = [
'V:|-[but1]-[el1]|'
]
@lay.vfl_parse lines: lines, views: @cls.contents, metrics: metrics
constraints = @lay.vfl_constraints
@lay.finish constraints
}
end
para "After layout"
end
89 changes: 89 additions & 0 deletions Tests/layout/grid.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Tests/layout/l4.rb - grid layout

class GridLayout

attr_accessor :ncol, :nrow, :colsz, :rowsz, :widgets, :hpad, :vpad

def initialize(attr = {})
@ncol = 0
@nrow = 0
@colsz = 0
@rowsz = 0
@widgets = []
@hpad = attr[:hpad] ? attr[:hpad] : 1
@vpad = attr[:vpad] ? attr[:vpad] : 1
end

def setup(canvas, attr)
end

def add(canvas, ele, attr)
col = attr[:col] ? attr[:col]-1 : 0
row = attr[:row] ? attr[:row]-1 : 0
rspan = attr[:rspan]
cspan = attr[:cspan]
@ncol = [@ncol, col + (cspan ? cspan : 1)].max
@nrow = [@nrow, row + (rspan ? rspan : 1)].max
widgets << {ele: ele, col: col, row: row, cspan: cspan, rspan: rspan}
end

def remove
end

def clear
end

def size (canvas, pass)
return if pass == 0
@rowsz = (canvas.height / @nrow).to_i
@colsz = (canvas.width / @ncol).to_i
@widgets.each do |entry|
x = entry[:col] * @colsz + @hpad
y = entry[:row] * @rowsz + @vpad
widget = entry[:ele]
widget.move(x, y)
if entry[:cspan]
w = entry[:cspan] * @colsz - @hpad
if widget.width != w
widget.style width: w
end
end
if entry[:rspan]
h = entry[:rspan] * @rowsz - @vpad
if widget.height != h
widget.style height: h
end
end
end
end

def finish
end

end

Shoes.app width: 400, height: 400 do
stack do
para "Before Grid"
grid = GridLayout.new vpad: 5, hpad: 3
@lay = layout use: grid, width: 300, height: 305 do
background aliceblue
button "one", col: 1, row: 1, cspan: 2, rspan: 1
button "two", col: 3, row: 1, cspan: 2, rspan: 2
para "Long String of characters", col: 2, row: 5, cspan: 2
button "three", col: 2, row: 3, cspan: 1
svg "#{DIR}/samples/good/paris.svg", width: 10, height: 10, col: 3, row: 3, rspan: 2,
cspan: 3
image "http://shoesrb.com/img/shoes-icon.png", row: 5, col: 4, cspan: 2, rspan: 2
edit_line "foobar", row: 7, col: 1, cspan: 2
end
flow do
button "+" do
@lay.style width: (@lay.width * 1.1).to_i
end
button "-" do
@lay.style width: (@lay.width * 0.9).to_i
end
end
end
end
66 changes: 0 additions & 66 deletions Tests/layout/vfl2.rb

This file was deleted.

32 changes: 14 additions & 18 deletions Tests/layout/vfl3.rb
Original file line number Diff line number Diff line change
@@ -1,34 +1,30 @@


Shoes.app width: 350, height: 400, resizeable: true do
stack do
para "Vfl layout"
para "Test vfl parser"

@lay = layout use: :Vfl, width: 300, height: 300 do
para "OverConstrained", name: 'para1'
edit_line "one", name: 'el1'
button "two", name: 'but1'
button "three", name: "but2"
button "four", name: "but3"
end
@lay.start {
metrics = {
'padding' => 10
padding: 8
}
lines = [
"H:|-[para1(but1)]-[but1]-|",
"H:|-[el1(but2)]-[but2]-|",
"H:[but3(but2)]-|",
"V:|-[para1(el1)]-[el1]-|",
"V:|-[but1(but2,but3)]-[but2]-[but3]-|"
'|[but1]-[el1]|'
]
if @lay.vfl_parse lines: lines, metrics: metrics
constraints = @lay.vfl_constraints #true # true produces hash
# display purposes only?
#constraints.each { |c| $stderr.puts c.inspect }
#@lay.vfl_append constraints[10]
if false
cs = @cls.var('el1','start').cn_equal (@cls.var('but1','width'))
puts cs.inspect
@lay.finish([cs])
else
@lay.vfl_parse lines: lines, views: @cls.contents, metrics: metrics
constraints = @lay.vfl_constraints
@lay.finish constraints
end
}
end
#cs = Shoes::Constraint.new 'but1','width', 'eq', 'but3', 'width', 1, 8.0, 1001001000
#para "#{cs.inspect}"
end
para "After layout"
end
34 changes: 34 additions & 0 deletions Tests/layout/vfl4.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

Shoes.app width: 350, height: 400, resizeable: true do
stack do
para "Vfl layout"
@lay = layout use: :Vfl, width: 300, height: 300 do
para "OverConstrained", name: 'para1'
edit_line "one", name: 'el1'
button "two", name: 'but1'
button "three", name: "but2"
button "four", name: "but3"
end
@lay.start {
metrics = {
'padding' => 10
}
lines = [
"H:|-[para1(but1)]-[but1]-|",
"H:|-[el1(but2)]-[but2]-|",
"H:[but3(but2)]-|",
"V:|-[para1(el1)]-[el1]-|",
"V:|-[but1(but2,but3)]-[but2]-[but3]-|"
]
if @lay.vfl_parse lines: lines, metrics: metrics
constraints = @lay.vfl_constraints #true # true produces hash
# display purposes only?
#constraints.each { |c| $stderr.puts c.inspect }
#@lay.vfl_append constraints[10]
@lay.finish constraints
end
}
end
#cs = Shoes::Constraint.new 'but1','width', 'eq', 'but3', 'width', 1, 8.0, 1001001000
#para "#{cs.inspect}"
end
Loading

0 comments on commit 943ba9d

Please sign in to comment.