Libraryless. Click here for Pure Java version (3079L/18K).
1 | static int formLayouter1_yPlus = 5; // make higher (bug fixing) |
2 | static int formLayouter1_fixer2 = 0; |
3 | |
4 | static F1<Container, Dimension> formLayouter1() { |
5 | final int yplus = formLayouter1_yPlus, fixer2 = formLayouter1_fixer2; |
6 | ret func(Container parent) -> Dimension { |
7 | L<Component> l = getComponents(parent); |
8 | new BitSet bigOnes; |
9 | for i over l: |
10 | if (containsATextArea(l.get(i))) add(bigOnes, i); |
11 | |
12 | int nBigOnes = bigOnes.cardinality(); |
13 | int mandatoryHeight = totalPreferredHeight(listWithoutIndicesInBitSet(l, bigOnes)); |
14 | int gap = 4, outerSpacing = 5; |
15 | Dimension size = parent.getSize(); |
16 | int gapsAndMargins = outerSpacing*2-(l(l)-1)*gap; |
17 | int totalSpace = size.height-gapsAndMargins-fixer2; |
18 | int liberalSpace = totalSpace-mandatoryHeight; |
19 | double perBigOne = doubleRatio(liberalSpace, nBigOnes); |
20 | double y = outerSpacing; |
21 | for i over l: { |
22 | Component c = l.get(i); |
23 | bool big = contains(bigOnes, i); |
24 | double h = big ? perBigOne : c.getPreferredSize().height; |
25 | int actualY = iround(y); |
26 | c.setBounds(10, actualY, size.width-outerSpacing*2, iround(y+h)-actualY); |
27 | y += h+gap; |
28 | } |
29 | |
30 | // return preferred size |
31 | Dimension pref = componentsBoundingSize(parent, outerSpacing); |
32 | ifdef formLayouter1_debug |
33 | printVars_str formLayouter1(+pref, parentHeight := parent.getHeight()); |
34 | endifdef |
35 | if (parent.getHeight() <= 0) { // pre-showing - maybe we should always do this |
36 | int tph = totalPreferredHeight(l); |
37 | pref.height = tph+gapsAndMargins+yplus; |
38 | ifdef formLayouter1_debug |
39 | printVars_str formLayouter1(+pref, +tph, +gapsAndMargins, +yplus); |
40 | endifdef |
41 | } |
42 | ret pref; |
43 | }; |
44 | } |
download show line numbers debug dex old transpilations
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1014730 |
Snippet name: | formLayouter1 - splits available height among text areas |
Eternal ID of this version: | #1014730/14 |
Text MD5: | 4bf75c7ea071bcab7f7eecf2309e8103 |
Transpilation MD5: | deeb4d469c0724519c9032b78535d970 |
Author: | stefan |
Category: | javax / gui |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2021-03-28 18:36:01 |
Source code size: | 1742 bytes / 44 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 459 / 539 |
Version history: | 13 change(s) |
Referenced in: | [show references] |