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

53
LINES

< > BotCompany Repo | #1015090 // makeNiceButtons

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

Libraryless. Compilation Failed (12727L/78K).

// params = text, image, action, text, image, action, ...
//   or TextImageAction...
//   or a list of above stuff
static <A extends DynamicStack> A makeNiceButtons_usingStack(A stack, O... params) {
  params = flattenArray2(params);
  for (int i = 0; i < l(params); ) {
    TextImageAction tia = null;
    if (params[i] instanceof TextImageAction) {
      tia = (TextImageAction) params[i];
      i++;
    } else {
      tia = TextImageAction(
        str(get(params, i)),
        str(get(params, i+1)),
        get(params, i+2));
      i += 3;
    }
    
    final TextImageAction _tia = tia;
    O action = tia.action;
    fS buttonDesc = action == null
      ? "actionless button " + sfu(_tia)
      : "button " + sfu(cloneWithoutField(_tia, 'action))
        + " with action " + trim(simpleSpaces(newLinesToSpaces(shorten(str(tia.action), 40))));
    action = r {
      appendToLocalMechLog("User actions", "User clicked on " + buttonDesc);
      callF(_tia.action);
    };
    JButton b = jImageAndTextButton(tia.imageID, tia.text, action);
    if (nempty(tia.toolTip)) setToolTip(b, tia.toolTip);
    componentPopupMenu(b, tia.popupMenuMaker);
    resizeImageButtonToMax(b, niceButtons_maxImageSize());
    setVerticalTextPosition(JButton.TOP, setFontSize(15, makeBold(b)));
    setVerticalAlignment(JButton.TOP, b);
    setMargin(10, b);
    
    onMouseEnter(b, r {
      appendToLocalMechLog("Mouse hovers", "Mouse hovered over " + buttonDesc)
    });
    onMouseExit(b, r {
      appendToLocalMechLog("Mouse hovers", "Mouse no longer hovers over " + buttonDesc)
    });

    metaSet(b, TextImageAction.class, tia);
    stack.addComponent(b);
  }
  
  ret stack;
}

static DynamicHStack makeNiceButtons(O... params) {
  ret makeNiceButtons_usingStack((DynamicHStack) dynamicHStack().spacing(20), params);
}

Author comment

Began life as a copy of #1015039

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: #1015090
Snippet name: makeNiceButtons
Eternal ID of this version: #1015090/23
Text MD5: f3ee986c87471f0c0435c018f4b6a4aa
Transpilation MD5: 42bfacbaec4980b63f557b8c662f15f9
Author: stefan
Category: javax / a.i. / gui
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-02-12 22:08:38
Source code size: 1868 bytes / 53 lines
Pitched / IR pitched: No / No
Views / Downloads: 502 / 596
Version history: 22 change(s)
Referenced in: [show references]