DEADSOFTWARE

Holmes UI: more FlexBox fixes
[d2df-sdl.git] / src / gx / gh_ui_common.pas
1 (* Copyright (C) DooM 2D:Forever Developers
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *)
16 {$INCLUDE ../shared/a_modes.inc}
17 unit gh_ui_common;
19 interface
22 // ////////////////////////////////////////////////////////////////////////// //
23 type
24 TLaySize = record
25 public
26 w, h: Integer;
28 private
29 function getIdx (idx: Integer): Integer; inline;
30 procedure setIdx (idx, v: Integer); inline;
32 public
33 constructor Create (aw, ah: Integer);
35 function toString (): AnsiString;
37 function equals (constref a: TLaySize): Boolean; inline;
38 public
39 property item[idx: Integer]: Integer read getIdx write setIdx; default;
40 end;
42 TLayPos = record
43 public
44 x, y: Integer;
46 private
47 function getIdx (idx: Integer): Integer; inline;
48 procedure setIdx (idx, v: Integer); inline;
50 public
51 constructor Create (ax, ay: Integer);
53 function toString (): AnsiString;
55 function equals (constref a: TLayPos): Boolean; inline;
57 public
58 property item[idx: Integer]: Integer read getIdx write setIdx; default;
59 end;
61 TLayMargins = record
62 public
63 top, right, bottom, left: Integer;
65 public
66 constructor Create (atop, aright, abottom, aleft: Integer);
68 function toString (): AnsiString;
70 function horiz (): Integer; inline;
71 function vert (): Integer; inline;
72 end;
76 implementation
78 uses
79 utils;
82 // ////////////////////////////////////////////////////////////////////////// //
83 constructor TLaySize.Create (aw, ah: Integer); begin w := aw; h := ah; end;
84 function TLaySize.getIdx (idx: Integer): Integer; inline; begin if (idx = 0) then result := w else if (idx = 1) then result := h else result := -1; end;
85 procedure TLaySize.setIdx (idx, v: Integer); inline; begin if (idx = 0) then w := v else if (idx = 1) then h := v; end;
86 function TLaySize.toString (): AnsiString; begin result := formatstrf('[%d,%d]', [w, h]); end;
87 function TLaySize.equals (constref a: TLaySize): Boolean; inline; begin result := (w = a.w) and (h = a.h); end;
89 constructor TLayPos.Create (ax, ay: Integer); begin x := ax; y := ay; end;
90 function TLayPos.getIdx (idx: Integer): Integer; inline; begin if (idx = 0) then result := x else if (idx = 1) then result := y else result := -1; end;
91 procedure TLayPos.setIdx (idx, v: Integer); inline; begin if (idx = 0) then x := v else if (idx = 1) then y := v; end;
92 function TLayPos.toString (): AnsiString; begin result := formatstrf('(%d,%d)', [x, y]); end;
93 function TLayPos.equals (constref a: TLayPos): Boolean; inline; begin result := (x = a.x) and (y = a.y); end;
95 constructor TLayMargins.Create (atop, aright, abottom, aleft: Integer);
96 begin
97 if (atop < 0) then atop := 0;
98 if (aright < 0) then aright := 0;
99 if (abottom < 0) then abottom := 0;
100 if (aleft < 0) then aleft := 0;
101 left := aleft;
102 right := aright;
103 top := atop;
104 bottom := abottom;
105 end;
106 function TLayMargins.toString (): AnsiString; begin result := formatstrf('(%s,%s,%s,%s)', [top, right, bottom, left]); end;
107 function TLayMargins.horiz (): Integer; inline; begin result := left+right; end;
108 function TLayMargins.vert (): Integer; inline; begin result := top+bottom; end;
111 end.