Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

37
LINES

< > BotCompany Repo | #1022755 // StackLayouter - with choosable height per component

JavaX fragment (include)

1  
sclass StackLayouter extends F1<Container, Dimension> {
2  
  Map<Component, Int> heights = weakHashMap();
3  
  int gap = 5;
4  
  //int defaultHeight = 50;
5  
  int preferredWidth = 300;
6  
  bool maximizeIfSingleComponent = true;
7  
  
8  
  Dimension get(Container parent) {
9  
    L<Component> l = getComponents(parent);
10  
    Insets insets = unnullInsets(parent.getInsets());
11  
    Dimension size = parent.getSize();
12  
    ifdef StackLayouter_debug
13  
      print("StackLayouter: n=" + l(l) + ", insets=" + insets + ", size=" + size);
14  
    endifdef
15  
    int y = insets.top;
16  
    int width = size.width-insets.left-insets.right;
17  
    for (Component c : l) {
18  
      Int H;
19  
      if (maximizeIfSingleComponent && l(l) == 1) {
20  
        ifdef StackLayouter_debug
21  
          print("StackLayouter maximizing!");
22  
        endifdef
23  
        H = size.height-insets.bottom-y;
24  
      } else
25  
        H = heights.get(c);
26  
      int h = H != null ? H : c.getPreferredSize().height;
27  
      c.setBounds(insets.left, y, width, h);
28  
      y += h+gap;
29  
      ifdef StackLayouter_debug
30  
        print("StackLayouter: y=" + y + ", h=" + h);
31  
      endifdef
32  
    }
33  
    
34  
    // return preferred size (hm.)
35  
    ret new Dimension(preferredWidth, max(50 /* XXX */, y+insets.bottom-gap));
36  
  };
37  
}

Author comment

Began life as a copy of #1022754

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, cfunsshuasjs, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1022755
Snippet name: StackLayouter - with choosable height per component
Eternal ID of this version: #1022755/20
Text MD5: c126dab39c660edfbc0437f1f3760345
Author: stefan
Category: javax / gui
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-04-06 22:25:10
Source code size: 1255 bytes / 37 lines
Pitched / IR pitched: No / No
Views / Downloads: 244 / 716
Version history: 19 change(s)
Referenced in: [show references]