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