% $Id: windowlayoutexamples.erl,v 1.2 2013/11/06 13:44:18 leavens Exp leavens $ -module(windowlayoutexamples). -export([addToSize/2,doubleSize/1,totalWidth/1]). -include("window.hrl"). -import(lists,[map/2,sum/1,max/1]). -spec addToSize(N::integer(),WL::windowlayout:windowlayout()) -> windowlayout:windowlayout(). % adds N to both the width and height of each window in WL. addToSize(N, #window{wname = Name, width = W, height = H}) -> #window{wname = Name, width = W+N, height = H+N}; addToSize(N, {horizontal, WLs}) -> {horizontal, map(fun (W) -> addToSize(N,W) end, WLs)}; addToSize(N, {vertical, WLs}) -> {vertical, map(fun (W) -> addToSize(N,W) end, WLs)}. -spec doubleSize(WL::windowlayout:windowlayout()) -> windowlayout:windowlayout(). % doubles the width and height of each window in WL. doubleSize(#window{wname = N, width = W, height = H}) -> #window{wname = N, width = 2*W, height = 2*H}; doubleSize({horizontal, WLs}) -> {horizontal, map(fun doubleSize/1, WLs)}; doubleSize({vertical, WLs}) -> {vertical, map(fun doubleSize/1, WLs)}. -spec totalWidth(WL::windowlayout:windowlayout()) -> integer(). % returns the width of WL. totalWidth(#window{wname = _N, width = W, height = _H}) -> W; totalWidth({horizontal, WLs}) -> sum(map(fun totalWidth/1, WLs)); totalWidth({vertical,[]}) -> %% max doesn't work on empty lists 0; %% so this special case is needed :-( totalWidth({vertical, WLs}) -> {vertical, max(map(fun totalWidth/1, WLs))}.