Beispiel #1
0
 @Override
 public TerminalPosition getCursorLocation(ComboBox<V> comboBox) {
   if (comboBox.isDropDownFocused()) {
     return new TerminalPosition(comboBox.getSize().getColumns() - 1, 0);
   } else {
     int textInputPosition = comboBox.getTextInputPosition();
     int textInputColumn =
         CJKUtils.getColumnWidth(comboBox.getText().substring(0, textInputPosition));
     return new TerminalPosition(textInputColumn - textVisibleLeftPosition, 0);
   }
 }
Beispiel #2
0
 @Override
 public TerminalSize getPreferredSize(final ComboBox<V> comboBox) {
   TerminalSize size =
       TerminalSize.ONE.withColumns(
           (comboBox.getItemCount() == 0 ? CJKUtils.getColumnWidth(comboBox.getText()) : 0) + 2);
   synchronized (comboBox) {
     for (int i = 0; i < comboBox.getItemCount(); i++) {
       V item = comboBox.getItem(i);
       size =
           size.max(
               new TerminalSize(
                   CJKUtils.getColumnWidth(item.toString()) + 2 + 1,
                   1)); // +1 to add a single column of space
     }
   }
   return size;
 }
Beispiel #3
0
    @Override
    public void drawComponent(TextGUIGraphics graphics, ComboBox<V> comboBox) {
      graphics.setForegroundColor(TextColor.ANSI.WHITE);
      graphics.setBackgroundColor(TextColor.ANSI.BLUE);
      if (comboBox.isFocused()) {
        graphics.setForegroundColor(TextColor.ANSI.YELLOW);
        graphics.enableModifiers(SGR.BOLD);
      }
      graphics.fill(' ');
      int editableArea =
          graphics.getSize().getColumns() - 2; // This is exclusing the 'drop-down arrow'
      int textInputPosition = comboBox.getTextInputPosition();
      int columnsToInputPosition =
          CJKUtils.getColumnWidth(comboBox.getText().substring(0, textInputPosition));
      if (columnsToInputPosition < textVisibleLeftPosition) {
        textVisibleLeftPosition = columnsToInputPosition;
      }
      if (columnsToInputPosition - textVisibleLeftPosition >= editableArea) {
        textVisibleLeftPosition = columnsToInputPosition - editableArea + 1;
      }
      if (columnsToInputPosition - textVisibleLeftPosition + 1 == editableArea
          && comboBox.getText().length() > textInputPosition
          && CJKUtils.isCharCJK(comboBox.getText().charAt(textInputPosition))) {
        textVisibleLeftPosition++;
      }

      String textToDraw =
          CJKUtils.fitString(comboBox.getText(), textVisibleLeftPosition, editableArea);
      graphics.putString(0, 0, textToDraw);
      if (comboBox.isFocused()) {
        graphics.disableModifiers(SGR.BOLD);
      }
      graphics.setForegroundColor(TextColor.ANSI.BLACK);
      graphics.setBackgroundColor(TextColor.ANSI.WHITE);
      graphics.putString(editableArea, 0, "|" + Symbols.ARROW_DOWN);
    }