1. private package Widgets.Layouts is 
  2.  
  3.     -- Centers the widget with the given size within the parent. 
  4.     type Layout_Center is new Layout with private; 
  5.  
  6.     -- Creates a Layout_Center. If 'width' or 'height' is 0 then the widget's 
  7.     -- minimum width or height, respectively, will be used. 
  8.     -- 
  9.     --           width 
  10.     --       +----------+ 
  11.     -- +----------------------+ 
  12.     -- |                      | 
  13.     -- |     +----------+     | + 
  14.     -- |     |          |     | | height 
  15.     -- |     +----------+     | + 
  16.     -- |                      | 
  17.     -- +----------------------+ 
  18.     function Create_Layout_Center( width, height : Natural ) return A_Layout; 
  19.     pragma Postcondition( Create_Layout_Center'Result /= null ); 
  20.  
  21.     ---------------------------------------------------------------------------- 
  22.  
  23.     -- Centers the widget with the given width horizontally within the parent. 
  24.     -- Top and bottom are distances relative to the top and bottom edges of the 
  25.     -- parent. 
  26.     -- 
  27.     --           width 
  28.     --     +---------------+ 
  29.     -- +-----------------------+ +      + 
  30.     -- |                       | | top  | -bottom 
  31.     -- |                       | |      | 
  32.     -- |   +---------------+   | +      | + 
  33.     -- |   |               |   |        | | 
  34.     -- |   +---------------+   | +      + | 
  35.     -- |                       | |        | -top 
  36.     -- |                       | | bottom | 
  37.     -- |                       | |        | 
  38.     -- +-----------------------+ +        + 
  39.     type Layout_CenterH is new Layout with private; 
  40.  
  41.     -- Creates a Layout_CenterH. If 'top' < 0 then the widget's top will be 
  42.     -- offset from the bottom of its container instead of the top. 
  43.     -- If 'bottom' < 0 then the widget's bottom will be offset from the top of 
  44.     -- its container, instead of the the bottom. 
  45.     function Create_Layout_CenterH( width       : Natural; 
  46.                                     top, bottom : Integer ) return A_Layout; 
  47.     pragma Precondition( top >=0 or else bottom >= 0 ); 
  48.     pragma Postcondition( Create_Layout_CenterH'Result /= null ); 
  49.  
  50.     ---------------------------------------------------------------------------- 
  51.  
  52.     -- Centers the widget with the given width horizontally within the parent, 
  53.     -- using absolute vertical positioning. 
  54.     -- 
  55.     --           width 
  56.     --     +---------------+ 
  57.     -- +-----------------------+ +     + 
  58.     -- |                       | | y1  | 
  59.     -- |   +---------------+   | +     | y2 
  60.     -- |   |               |   |       | 
  61.     -- |   +---------------+   |       + 
  62.     -- |                       | 
  63.     -- |                       | 
  64.     -- +-----------------------+ 
  65.     type Layout_CenterHY is new Layout with private; 
  66.  
  67.     -- Creates a Layout_CenterHY. If 'width' is 0 the widget's minimum width 
  68.     -- will be used. 'y1' is an absolute value within the parent's content 
  69.     -- region for the top of the widget and 'y2' is the absolute location of the 
  70.     -- bottom of the widget. If 'y1' or 'y2' is negative, then part of the 
  71.     -- widget will lie outside of its container's content region. 
  72.     function Create_Layout_CenterHY( width  : Natural; 
  73.                                      y1, y2 : Integer ) return A_Layout; 
  74.     pragma Precondition( y2 >= y1 ); 
  75.     pragma Postcondition( Create_Layout_CenterHY'Result /= null ); 
  76.  
  77.     ---------------------------------------------------------------------------- 
  78.  
  79.     -- Positions the widget using offsets from the parent's edges; left, top, 
  80.     -- right, and bottom. 
  81.     -- 
  82.     --              -left 
  83.     --        +----------------+ 
  84.     --      -right 
  85.     -- +--------------+ 
  86.     --   left           right 
  87.     -- +------+       +--------+ 
  88.     -- +-----------------------+ +         + 
  89.     -- |                       | | top     | -bottom 
  90.     -- |      +-------+        | +         | + 
  91.     -- |      |       |        |           | | 
  92.     -- |      +-------+        | +         + | 
  93.     -- |                       | | bottom    | -top 
  94.     -- |                       | |           | 
  95.     -- +-----------------------+ +           + 
  96.     type Layout_LTRB is new Layout with private; 
  97.  
  98.     -- Creates a Layout_LTRB. 'left', 'top', 'right', and 'bottom' are distances 
  99.     -- from the container's corresponding edge. If the value is negative, the 
  100.     -- distance will be relative to the opposite side. For example, if 'top' is 
  101.     -- negative then the widget's top will be offset from the container's bottom 
  102.     -- edge. 
  103.     function Create_Layout_LTRB( left, top, right, bottom : Integer ) return A_Layout; 
  104.     pragma Precondition( left >= 0 or else right >= 0 ); 
  105.     pragma Precondition( top >= 0 or else bottom >= 0 ); 
  106.     pragma Postcondition( Create_Layout_LTRB'Result /= null ); 
  107.  
  108.     ---------------------------------------------------------------------------- 
  109.  
  110.     -- Positions the widget using offsets from the parent's top left and sized 
  111.     -- using the given width and height. 
  112.     -- 
  113.     --          width 
  114.     --   left +-------+  -left 
  115.     -- +------+       +--------+ 
  116.     -- +-----------------------+ + 
  117.     -- |                       | | top 
  118.     -- |      +-------+        | + + 
  119.     -- |      |       |        |   | height 
  120.     -- |      +-------+        | + + 
  121.     -- |                       | | 
  122.     -- |                       | | -top 
  123.     -- +-----------------------+ + 
  124.     type Layout_LTWH is new Layout with private; 
  125.  
  126.     -- Creates a Layout_LTWH. 'left' and 'top' are offsets from the container's 
  127.     -- corresponding edge. Negative values for 'top' and 'left' are retreated as 
  128.     -- relative to the bottom and right, respectively. If 'width' or 'height' is 
  129.     -- 0 then the widget's minimum width or height, respectively, will be used. 
  130.     -- For example, a negative value for 'top' indicates the offset of the 
  131.     -- bottom of the widget from its container's bottom. 
  132.     function Create_Layout_LTWH( left, top     : Integer; 
  133.                                  width, height : Natural ) return A_Layout; 
  134.     pragma Postcondition( Create_Layout_LTWH'Result /= null ); 
  135.  
  136.     ---------------------------------------------------------------------------- 
  137.  
  138.     -- Positions the widget's top left corner using offsets from the container's 
  139.     -- top left, and sized using the given width and height. This layout is 
  140.     -- identical to Layout_LTWH for non-negative offsets. 
  141.     -- 
  142.     --          width 
  143.     --     x  +-------+ 
  144.     -- +------+ 
  145.     -- +-----------------------+ + 
  146.     -- |                       | | y 
  147.     -- |      +-------+        | + + 
  148.     -- |      |       |        |   | height 
  149.     -- |      +-------+        |   + 
  150.     -- |                       | 
  151.     -- |                       | 
  152.     -- +-----------------------+ 
  153.     type Layout_XYWH is new Layout with private; 
  154.  
  155.     -- Creates a Layout_XYWH. 'x' and 'y' are the absolute position of the top 
  156.     -- left corner of the widget, relative to the top left corner of the 
  157.     -- container. For negative values of 'x' or 'y', the widget will partially 
  158.     -- lie outside the content region of its container. If 'width' or 'height' 
  159.     -- is 0 then the widget's minimum width or height, respectively, will be 
  160.     -- used. 
  161.     function Create_Layout_XYWH( x, y          : Integer; 
  162.                                  width, height : Natural ) return A_Layout; 
  163.     pragma Postcondition( Create_Layout_XYWH'Result /= null ); 
  164.  
  165.     ---------------------------------------------------------------------------- 
  166.  
  167.     -- Deletes the Layout. 
  168.     procedure Delete( this : in out A_Layout ); 
  169.     pragma Postcondition( this = null ); 
  170.  
  171. private 
  172.  
  173.     type Layout_Center is new Layout with 
  174.         record 
  175.             width, 
  176.             height : Natural := 0; 
  177.         end record; 
  178.     type A_Layout_Center is access all Layout_Center'Class; 
  179.  
  180.     procedure Apply( this : access Layout_Center; widget : not null A_Widget ); 
  181.  
  182.     procedure Construct( this   : access Layout_Center; 
  183.                          width, 
  184.                          height : Natural ); 
  185.  
  186.     ---------------------------------------------------------------------------- 
  187.  
  188.     type Layout_CenterH is new Layout with 
  189.         record 
  190.             width  : Natural := 0; 
  191.             top, 
  192.             bottom : Integer := 0; 
  193.         end record; 
  194.     type A_Layout_CenterH is access all Layout_CenterH'Class; 
  195.  
  196.     procedure Apply( this : access Layout_CenterH; widget : not null A_Widget ); 
  197.  
  198.     procedure Construct( this   : access Layout_CenterH; 
  199.                          width  : Natural; 
  200.                          top, 
  201.                          bottom : Integer ); 
  202.     pragma Precondition( top >=0 or else bottom >= 0 ); 
  203.  
  204.     ---------------------------------------------------------------------------- 
  205.  
  206.     type Layout_CenterHY is new Layout with 
  207.         record 
  208.             width  : Natural := 0; 
  209.             y1, y2 : Integer := 0; 
  210.         end record; 
  211.     type A_Layout_CenterHY is access all Layout_CenterHY'Class; 
  212.  
  213.     procedure Apply( this : access Layout_CenterHY; widget : not null A_Widget ); 
  214.  
  215.     procedure Construct( this   : access Layout_CenterHY; 
  216.                          width  : Natural; 
  217.                          y1, y2 : Integer ); 
  218.  
  219.     ---------------------------------------------------------------------------- 
  220.  
  221.     type Layout_LTRB is new Layout with 
  222.         record 
  223.             left, 
  224.             top, 
  225.             right, 
  226.             bottom : Integer := 0; 
  227.         end record; 
  228.     type A_Layout_LTRB is access all Layout_LTRB'Class; 
  229.  
  230.     procedure Apply( this : access Layout_LTRB; widget : not null A_Widget ); 
  231.  
  232.     procedure Construct( this   : access Layout_LTRB; 
  233.                          left, 
  234.                          top, 
  235.                          right, 
  236.                          bottom : Integer ); 
  237.     pragma Precondition( left >= 0 or else right >= 0 ); 
  238.     pragma Precondition( top >= 0 or else bottom >= 0 ); 
  239.  
  240.     ---------------------------------------------------------------------------- 
  241.  
  242.     type Layout_LTWH is new Layout with 
  243.         record 
  244.             left, 
  245.             top    : Integer := 0; 
  246.             width, 
  247.             height : Natural := 0; 
  248.         end record; 
  249.     type A_Layout_LTWH is access all Layout_LTWH'Class; 
  250.  
  251.     procedure Apply( this : access Layout_LTWH; widget : not null A_Widget ); 
  252.  
  253.     procedure Construct( this   : access Layout_LTWH; 
  254.                          left, 
  255.                          top    : Integer; 
  256.                          width, 
  257.                          height : Natural ); 
  258.  
  259.     ---------------------------------------------------------------------------- 
  260.  
  261.     type Layout_XYWH is new Layout with 
  262.         record 
  263.             x, y   : Integer := 0; 
  264.             width, 
  265.             height : Natural := 0; 
  266.         end record; 
  267.     type A_Layout_XYWH is access all Layout_XYWH'Class; 
  268.  
  269.     procedure Apply( this : access Layout_XYWH; widget : not null A_Widget ); 
  270.  
  271.     procedure Construct( this   : access Layout_XYWH; 
  272.                          x, y   : Integer; 
  273.                          width, 
  274.                          height : Natural ); 
  275.  
  276. end Widgets.Layouts;