Browse Source

Slider+Settings: Allow sliders to have their baseline at the height of the track.

pull/245/head
weisj 4 years ago
parent
commit
a8d9408757
No known key found for this signature in database
GPG Key ID: 31124CB75461DA2A
  1. 2
      core/src/main/java/com/github/weisj/darklaf/layout/LayoutHelper.java
  2. 1
      core/src/main/java/com/github/weisj/darklaf/settings/ThemeSettingsUI.java
  3. 10
      core/src/main/java/com/github/weisj/darklaf/ui/slider/DarkSliderUI.java

2
core/src/main/java/com/github/weisj/darklaf/layout/LayoutHelper.java

@ -111,7 +111,7 @@ public final class LayoutHelper {
verticalLabelGroup.addComponent(lComp, p, p, p); verticalLabelGroup.addComponent(lComp, p, p, p);
verticalComponentGroup.addComponent(rComp, p, p, p); verticalComponentGroup.addComponent(rComp, p, p, p);
verticalGroup.addGroup(layout.createParallelGroup(GroupLayout.Alignment.CENTER) verticalGroup.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(lComp, p, p, p) .addComponent(lComp, p, p, p)
.addComponent(rComp, p, p, p)); .addComponent(rComp, p, p, p));
} }

1
core/src/main/java/com/github/weisj/darklaf/settings/ThemeSettingsUI.java

@ -325,6 +325,7 @@ public class ThemeSettingsUI {
return new Rectangle(0, 0, fontSlider.getWidth(), fontSlider.getHeight()); return new Rectangle(0, 0, fontSlider.getWidth(), fontSlider.getHeight());
}); });
fontSlider.putClientProperty(DarkSliderUI.KEY_INSTANT_SCROLL, true); fontSlider.putClientProperty(DarkSliderUI.KEY_INSTANT_SCROLL, true);
fontSlider.putClientProperty(DarkSliderUI.KEY_USE_TRACK_AS_BASELINE, true);
fontSlider.putClientProperty(ToolTipConstants.KEY_CONTEXT, context); fontSlider.putClientProperty(ToolTipConstants.KEY_CONTEXT, context);
fontSlider.putClientProperty(ToolTipConstants.KEY_STYLE, ToolTipConstants.VARIANT_BALLOON); fontSlider.putClientProperty(ToolTipConstants.KEY_STYLE, ToolTipConstants.VARIANT_BALLOON);
fontSlider.setToolTipText(String.valueOf(fontSlider.getValue())); fontSlider.setToolTipText(String.valueOf(fontSlider.getValue()));

10
core/src/main/java/com/github/weisj/darklaf/ui/slider/DarkSliderUI.java

@ -50,6 +50,7 @@ public class DarkSliderUI extends BasicSliderUI {
public static final String KEY_VARIANT = KEY_PREFIX + "variant"; public static final String KEY_VARIANT = KEY_PREFIX + "variant";
public static final String KEY_INSTANT_SCROLL = KEY_PREFIX + "instantScrollEnabled"; public static final String KEY_INSTANT_SCROLL = KEY_PREFIX + "instantScrollEnabled";
public static final String KEY_MANUAL_LABEL_ALIGN = KEY_PREFIX + "manualLabelAlign"; public static final String KEY_MANUAL_LABEL_ALIGN = KEY_PREFIX + "manualLabelAlign";
public static final String KEY_USE_TRACK_AS_BASELINE = KEY_PREFIX + "useTrackAsBaseline";
public static final String VARIANT_VOLUME = "volume"; public static final String VARIANT_VOLUME = "volume";
protected final Rectangle iconRect = new Rectangle(0, 0, 0, 0); protected final Rectangle iconRect = new Rectangle(0, 0, 0, 0);
@ -157,6 +158,15 @@ public class DarkSliderUI extends BasicSliderUI {
sliderListener = null; sliderListener = null;
} }
@Override
public int getBaseline(JComponent c, int width, int height) {
if (isHorizontal() && PropertyUtil.getBooleanProperty(c, KEY_USE_TRACK_AS_BASELINE)) {
return trackRect.y + trackRect.height / 2;
} else {
return super.getBaseline(c, width, height);
}
}
@Override @Override
protected void calculateGeometry() { protected void calculateGeometry() {
// Thumb size should be calculated before content rect. // Thumb size should be calculated before content rect.

Loading…
Cancel
Save