Example #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);
   }
 }
Example #2
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);
    }