-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
Showing
17 changed files
with
853 additions
and
503 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.