Skip to content

Commit

Permalink
Merge PR #856: Table: rounded selection
Browse files Browse the repository at this point in the history
  • Loading branch information
DevCharly committed Jul 15, 2024
2 parents 72a4c00 + 127dd6a commit cba203b
Show file tree
Hide file tree
Showing 12 changed files with 762 additions and 57 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ FlatLaf Change Log

#### New features and improvements

- Table: Support rounded selection. (PR #856)
- Button and ToggleButton: Added border colors for pressed and selected states.
(issue #848)
- Label: Support painting background with rounded corners. (issue #842)
Expand Down
16 changes: 12 additions & 4 deletions flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatListUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,7 @@ protected void paintCell( Graphics g, int row, Rectangle rowBounds, ListCellRend
(rendererComponent instanceof DefaultListCellRenderer ||
rendererComponent instanceof BasicComboBoxRenderer) &&
(selectionArc > 0 ||
(selectionInsets != null &&
(selectionInsets.top != 0 || selectionInsets.left != 0 || selectionInsets.bottom != 0 || selectionInsets.right != 0))) )
(selectionInsets != null && !FlatUIUtils.isInsetsEmpty( selectionInsets ))) )
{
// Because selection painting is done in the cell renderer, it would be
// necessary to require a FlatLaf specific renderer to implement rounded selection.
Expand Down Expand Up @@ -374,7 +373,15 @@ public void fillRect( int x, int y, int width, int height ) {
rendererPane.paintComponent( g, rendererComponent, list, cx, rowBounds.y, cw, rowBounds.height, true );
}

/** @since 3 */
/**
* Paints (rounded) cell selection.
* Supports {@link #selectionArc} and {@link #selectionInsets}.
* <p>
* <b>Note:</b> This method is only invoked if either selection arc
* is greater than zero or if selection insets are not empty.
*
* @since 3
*/
protected void paintCellSelection( Graphics g, int row, int x, int y, int width, int height ) {
float arcTopLeft, arcTopRight, arcBottomLeft, arcBottomRight;
arcTopLeft = arcTopRight = arcBottomLeft = arcBottomRight = UIScale.scale( selectionArc / 2f );
Expand Down Expand Up @@ -440,7 +447,8 @@ private boolean useUnitedRoundedSelection( boolean vertical, boolean horizontal
* Paints a cell selection at the given coordinates.
* The selection color must be set on the graphics context.
* <p>
* This method is intended for use in custom cell renderers.
* This method is intended for use in custom cell renderers
* to support {@link #selectionArc} and {@link #selectionInsets}.
*
* @since 3
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,28 @@ public Color getLineColor() {
return super.getLineColor();
}

@Override
public int getArc() {
if( c != null ) {
Integer selectionArc = getStyleFromTableUI( c, ui -> ui.selectionArc );
if( selectionArc != null )
return selectionArc;
}
return super.getArc();
}

@Override
public void paintBorder( Component c, Graphics g, int x, int y, int width, int height ) {
if( c != null ) {
Insets selectionInsets = getStyleFromTableUI( c, ui -> ui.selectionInsets );
if( selectionInsets != null ) {
x += selectionInsets.left;
y += selectionInsets.top;
width -= selectionInsets.left + selectionInsets.right;
height -= selectionInsets.top + selectionInsets.bottom;
}
}

this.c = c;
super.paintBorder( c, g, x, y, width, height );
this.c = null;
Expand Down
Loading

0 comments on commit cba203b

Please sign in to comment.