mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
ui: better paddings for DarculaCheckBoxUI
GitOrigin-RevId: ddcc457e116b7444b6dfb4ee63b32a3d24e70b5c
This commit is contained in:
committed by
intellij-monorepo-bot
parent
6173f273e0
commit
eaa13efbc7
+60
-5
@@ -6,6 +6,7 @@ import com.intellij.ide.ui.laf.darcula.DarculaUIUtil;
|
||||
import com.intellij.ui.ComponentUtil;
|
||||
import com.intellij.ui.scale.JBUIScale;
|
||||
import com.intellij.util.ui.*;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.plaf.ComponentUI;
|
||||
@@ -154,7 +155,8 @@ public class DarculaCheckBoxUI extends MetalCheckBoxUI {
|
||||
|
||||
@Override
|
||||
public Dimension getPreferredSize(JComponent c) {
|
||||
return updatePreferredSize(c, super.getPreferredSize(c));
|
||||
Dimension dimension = computeOurPreferredSize(c);
|
||||
return dimension != null ? dimension : super.getPreferredSize(c);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -162,11 +164,64 @@ public class DarculaCheckBoxUI extends MetalCheckBoxUI {
|
||||
return getPreferredSize(c);
|
||||
}
|
||||
|
||||
protected Dimension updatePreferredSize(JComponent c, Dimension size) {
|
||||
if (c.getBorder() instanceof DarculaCheckBoxBorder) {
|
||||
JBInsets.removeFrom(size, c.getInsets());
|
||||
protected Dimension computeOurPreferredSize(JComponent c) {
|
||||
return computeCheckboxPreferredSize(c, getDefaultIcon());
|
||||
}
|
||||
|
||||
/**
|
||||
* @See {@link javax.swing.plaf.basic.BasicRadioButtonUI#getPreferredSize}
|
||||
* The difference is that we do not include `DarculaCheckBoxBorder` insets to the icon size.
|
||||
*/
|
||||
@Nullable
|
||||
static Dimension computeCheckboxPreferredSize(JComponent c, Icon defaultIcon) {
|
||||
if (c.getComponentCount() > 0) {
|
||||
return null;
|
||||
}
|
||||
return size;
|
||||
|
||||
AbstractButton b = (AbstractButton)c;
|
||||
Rectangle prefViewRect = new Rectangle();
|
||||
Rectangle prefIconRect = new Rectangle();
|
||||
Rectangle prefTextRect = new Rectangle();
|
||||
|
||||
String text = b.getText();
|
||||
|
||||
Icon buttonIcon = b.getIcon();
|
||||
if (buttonIcon == null) {
|
||||
buttonIcon = defaultIcon;
|
||||
}
|
||||
|
||||
Font font = b.getFont();
|
||||
FontMetrics fm = b.getFontMetrics(font);
|
||||
|
||||
prefViewRect.x = prefViewRect.y = 0;
|
||||
prefViewRect.width = Short.MAX_VALUE;
|
||||
prefViewRect.height = Short.MAX_VALUE;
|
||||
prefIconRect.x = prefIconRect.y = prefIconRect.width = prefIconRect.height = 0;
|
||||
prefTextRect.x = prefTextRect.y = prefTextRect.width = prefTextRect.height = 0;
|
||||
|
||||
SwingUtilities.layoutCompoundLabel(
|
||||
c, fm, text, buttonIcon,
|
||||
b.getVerticalAlignment(), b.getHorizontalAlignment(),
|
||||
b.getVerticalTextPosition(), b.getHorizontalTextPosition(),
|
||||
prefViewRect, prefIconRect, prefTextRect,
|
||||
text == null ? 0 : b.getIconTextGap());
|
||||
|
||||
Insets insets = b.getInsets();
|
||||
if (!(b.getBorder() instanceof DarculaCheckBoxBorder)) {
|
||||
JBInsets.addTo(prefIconRect, insets);
|
||||
}
|
||||
JBInsets.addTo(prefTextRect, insets);
|
||||
|
||||
// find the union of the icon and text rects (from Rectangle.java)
|
||||
int x1 = Math.min(prefIconRect.x, prefTextRect.x);
|
||||
int x2 = Math.max(prefIconRect.x + prefIconRect.width,
|
||||
prefTextRect.x + prefTextRect.width);
|
||||
int y1 = Math.min(prefIconRect.y, prefTextRect.y);
|
||||
int y2 = Math.max(prefIconRect.y + prefIconRect.height,
|
||||
prefTextRect.y + prefTextRect.height);
|
||||
int width = x2 - x1;
|
||||
int height = y2 - y1;
|
||||
return new Dimension(width, height);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+5
-7
@@ -1,8 +1,8 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.ide.ui.laf.darcula.ui;
|
||||
|
||||
import com.intellij.ui.scale.JBUIScale;
|
||||
import com.intellij.ide.ui.laf.darcula.DarculaLaf;
|
||||
import com.intellij.ui.scale.JBUIScale;
|
||||
import com.intellij.util.ui.*;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -121,7 +121,8 @@ public class DarculaRadioButtonUI extends MetalRadioButtonUI {
|
||||
|
||||
@Override
|
||||
public Dimension getPreferredSize(JComponent c) {
|
||||
return updatePreferredSize(c, super.getPreferredSize(c));
|
||||
Dimension dimension = computeOurPreferredSize(c);
|
||||
return dimension != null ? dimension : super.getPreferredSize(c);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -129,11 +130,8 @@ public class DarculaRadioButtonUI extends MetalRadioButtonUI {
|
||||
return getPreferredSize(c);
|
||||
}
|
||||
|
||||
protected Dimension updatePreferredSize(JComponent c, Dimension size) {
|
||||
if (c.getBorder() instanceof DarculaRadioButtonBorder) {
|
||||
JBInsets.removeFrom(size, c.getInsets());
|
||||
}
|
||||
return size;
|
||||
protected Dimension computeOurPreferredSize(JComponent c) {
|
||||
return DarculaCheckBoxUI.computeCheckboxPreferredSize(c, getDefaultIcon());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -32,8 +32,8 @@ public class WinIntelliJCheckBoxUI extends DarculaCheckBoxUI {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Dimension updatePreferredSize(JComponent c, Dimension size) {
|
||||
return size;
|
||||
protected Dimension computeOurPreferredSize(JComponent c) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -23,8 +23,8 @@ public class WinIntelliJRadioButtonUI extends DarculaRadioButtonUI {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Dimension updatePreferredSize(JComponent c, Dimension size) {
|
||||
return size;
|
||||
protected Dimension computeOurPreferredSize(JComponent c) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings({"MethodOverridesStaticMethodOfSuperclass", "UnusedDeclaration"})
|
||||
|
||||
Reference in New Issue
Block a user