Cassowary.d

ketmar via Digitalmars-d-announce digitalmars-d-announce at puremagic.com
Thu Aug 7 15:40:40 PDT 2014


a small update for parser: it is now possible to parse so-called 
"scripts" (only from 'string' type for now). sample script can 
look like this one, which centers two buttons inside the panel, 
keepeng equal button sizes:

===[cutline]===
var(stay)
   panel.left = 0,
   panel.top = 0,
   panel.width = 80,
   panel.height = 20;


// this is just a simple constants,
// use 'define' to avoid introducing new vars
define
   button.hpadding = 4,
   button.defheight = 10+6; // simple math


var
   bt0.left, // default is 0
   bt0.top,
   <stay> bt0.width = 30,
   <stay> bt0.height = button.defheight;
     // oh, yeah, this will be calculated in-place


var
   bt1.left,
   bt1.top,
   bt1.width,
   bt1.height;


// some useful macros
define
   panel.right = (panel.left+panel.width),
   panel.bottom = (panel.top+panel.height),

   bt0.right = (bt0.left+bt0.width),
   bt0.bottom = (bt0.top+bt0.height),

   bt1.right = (bt1.left+bt1.width),
   bt1.bottom = (bt1.top+bt1.height);


// button-button placement and sizes
// default strength is <required>
bt1.left >= bt0.right+button.hpadding; // buttons padding
bt1.height == bt0.height; // same height
bt1.width == bt0.width; // same width
bt1.top == bt0.top; // same vertical position


// button-panel placement (this should center buttons)
// horizontal
bt0.left-panel.left == panel.right-bt1.right;
// vertical
bt0.top-panel.top == panel.bottom-bt0.bottom;


// print values (for debug mode)
print panel.left;
print panel.top;
print panel.width;
print panel.height;

print bt0.left;
print bt0.top;
print bt0.width;
print bt0.height;

print bt1.left;
print bt1.top;
print bt1.width;
print bt1.height;
===[cutline]===

there is no support for any kind of 'autobinding' variables to 
class/struct properties yet, and parser code is awful. but the 
whole thing is slowly growing…

anyway, it's really fun to play with various layout scripts. try 
it yourself!


More information about the Digitalmars-d-announce mailing list