Skip to content

Commit

Permalink
PictureStack: callback-based item style
Browse files Browse the repository at this point in the history
  • Loading branch information
ogheorghies committed Jul 23, 2015
1 parent a76353f commit 15bc536
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
30 changes: 27 additions & 3 deletions manual/fig/test_picture_stack.mp
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ beginfig(4);
endfig;

beginfig(5);
vardef joinFunction= enddef;
PictureStack.custom("itemA", "item B long", "C")
("joinFunction");
vardef joinCallback= enddef;
PictureStack.custom("A.A", "B__________B", "C-----C")
("joinCallback");

drawObject(custom);
endfig;
Expand Down Expand Up @@ -103,4 +103,28 @@ beginfig(6);
drawObjects(customA, customB);
endfig;

beginfig(7);
save stackX;
save stylePA, stylePB;
save stylePictureStack;

PictureInfoCopy.stylePA(iPict);
stylePA.borderColor := green;
stylePA.boxed := 1;

PictureInfoCopy.stylePB(iPict);
stylePB.borderColor := red;
stylePB.boxed := 1;

PictureStackInfoCopy.stylePictureStack(iStack);

def styleSelector(expr i)= if i mod 2 = 0: stylePA else: stylePB fi enddef;

stylePictureStack.itemStyleCallback := "styleSelector";

EPictureStack.stackX(stylePictureStack)("a","b","c","d","e")("vcenter");

drawObjects(stackX);
endfig;

end
2 changes: 1 addition & 1 deletion manual/test-suite.tex
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ \subsection{Util library}
\metaumltests{group}{2}

\subsubsection{PictureStack tests}
\metaumltests{picture_stack}{3}
\metaumltests{picture_stack}{7}

\subsubsection{Positioning tests}
\metaumltests{positioning}{6}
Expand Down
12 changes: 11 additions & 1 deletion src/util_picture_stack.mp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ vardef PictureStackInfo@#(expr marginLeft, marginRight, marginTop, marginBottom)
var(numeric) boxed;
var(color) borderColor;
var(numeric) spacing;
var(string) itemStyleCallback;

Margins@#(marginLeft, marginRight, marginTop, marginBottom);

Expand All @@ -43,12 +44,15 @@ vardef PictureStackInfo@#(expr marginLeft, marginRight, marginTop, marginBottom)
@#boxed := 0;
@#borderColor := green;

@#itemStyleCallback := "";

PictureInfoCopy.@#iPict(_pictInfo);
enddef;

vardef PictureStackInfoCopy@#(text src)=
PictureStackInfo@#(src.left, src.right, src.top, src.bottom)(src.spacing)(src.iPict);

@#itemStyleCallback := src.itemStyleCallback;
@#boxed := src.boxed;
@#borderColor := src.borderColor;
enddef;
Expand All @@ -75,9 +79,15 @@ vardef EPictureStack@#(text pictStackInfo)(text thePictures)(text how)=
@#joinMethod := l;
endfor;

show "@#info.itemStyleCallback", @#info.itemStyleCallback;

@#nItems := 0;
for p=thePictures:
EPicture.@#pict[@#nItems](@#info.iPict)(p);
if (@#info.itemStyleCallback <> ""):
EPicture.@#pict[@#nItems](scantokens (@#info.itemStyleCallback)(@#nItems))(p);
else:
EPicture.@#pict[@#nItems](@#info.iPict)(p);
fi;
@#nItems := @#nItems + 1;
endfor;

Expand Down

0 comments on commit 15bc536

Please sign in to comment.