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

51
LINES

< > BotCompany Repo | #1030808 // formLayouter1b - also returns minimum size

JavaX fragment (include) [tags: use-pretranspiled]

Transpiled version (3091L) is out of date.

static int formLayouter1b_yPlus = 0; // make higher (bug fixing)
static int formLayouter1b_fixer2 = 0;

static F1<Container, Pair<Dimension>> formLayouter1b() {
  final int yplus = formLayouter1b_yPlus, fixer2 = formLayouter1b_fixer2;
  ret func(Container parent) -> Pair<Dimension> {
    L<Component> l = getComponents(parent);
    new BitSet bigOnes;
    for i over l:
      if (containsATextArea(l.get(i))) add(bigOnes, i);
      
    int nBigOnes = bigOnes.cardinality();
    int mandatoryHeight = totalPreferredHeight(listWithoutIndicesInBitSet(l, bigOnes));
    int gap = 4, outerSpacing = 5;
    Dimension size = parent.getSize();
    int gapsAndMargins = outerSpacing*2-(l(l)-1)*gap;
    int totalSpace = size.height-gapsAndMargins-fixer2;
    int liberalSpace = totalSpace-mandatoryHeight;
    double perBigOne = doubleRatio(liberalSpace, nBigOnes);
    double y = outerSpacing;
    for i over l: {
      Component c = l.get(i);
      bool big = contains(bigOnes, i);
      double h = big ? perBigOne : c.getPreferredSize().height;
      int actualY = iround(y);
      c.setBounds(10, actualY, size.width-outerSpacing*2, iround(y+h)-actualY);
      y += h+gap;
    }
    
    // return preferred size
    Dimension pref = componentsBoundingSize(parent, outerSpacing);
    ifdef formLayouter1_debug
      printVars_str formLayouter1b(+pref, parentHeight := parent.getHeight());
    endifdef
    if (parent.getHeight() <= 0) { // pre-showing - maybe we should always do this
      int tph = totalPreferredHeight(l);
      pref.height = tph/*+gapsAndMargins*/-outerSpacing*2;
      ifdef formLayouter1_debug
        printVars_str formLayouter1b(+pref, +tph, +gapsAndMargins, +yplus);
      endifdef
    }
    
    int tmh = totalMinimumHeight(l);
    Dimension min = new(100, tmh/*+gapsAndMargins*/-outerSpacing*2);
    ifdef formLayouter1_debug
      printVars_str formLayouter1b(+tmh, +gapsAndMargins, +yplus, +min);
    endifdef

    ret pair(pref, min);
  };
}

Author comment

Began life as a copy of #1014730

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt

No comments. add comment

Snippet ID: #1030808
Snippet name: formLayouter1b - also returns minimum size
Eternal ID of this version: #1030808/6
Text MD5: d9c82b322253fd0a3c1b0f841f23180f
Author: stefan
Category: javax / gui
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-03-29 14:06:35
Source code size: 2020 bytes / 51 lines
Pitched / IR pitched: No / No
Views / Downloads: 182 / 274
Version history: 5 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)