Revert "[ui] Fix incorrect usages of JBUI#getInt"

Found that `List.rowHeight` and `Tree.rowHeight` values are already scaled in UIDefaults. So, the usages I changed were correct.
Also, it seems that we can't assume that `JBUI#getInt` always returns unscaled values, because some values in UIDefaults are scaled.

This reverts commit ae91971b88e62f2314904ad8090d3679421435d7.

GitOrigin-RevId: f9f1884e50d92aaa2cc81c5e735adf38f3fcf12e
This commit is contained in:
Konstantin Hudyakov
2023-10-25 11:22:38 +03:00
committed by intellij-monorepo-bot
parent 6955e9b72d
commit 063aa39a30
13 changed files with 18 additions and 28 deletions

View File

@@ -33,7 +33,6 @@ import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.wm.IdeFocusManager;
import com.intellij.ui.dsl.listCellRenderer.BuilderKt;
import com.intellij.util.containers.JBIterable;
import com.intellij.util.ui.JBDimension;
import com.intellij.util.ui.JBUI;
import com.intellij.vcs.CompareWithLocalDialog;
import org.jetbrains.annotations.Nls;
@@ -105,7 +104,7 @@ public abstract class DvcsCompareWithAction<T extends Repository> extends DumbAw
.setAutoselectOnMouseMove(true)
.setNamerForFiltering(o -> o)
.setRenderer(BuilderKt.textListCellRenderer((@NlsSafe var name) -> name))
.withFixedRendererSize(new JBDimension(350, JBUI.CurrentTheme.List.rowHeight())) // do not freeze on huge lists
.withFixedRendererSize(new Dimension(JBUI.scale(350), JBUI.CurrentTheme.List.rowHeight())) // do not freeze on huge lists
.createPopup();
}

View File

@@ -92,7 +92,7 @@ public final class ShowUsagesTable extends JBTable implements DataProvider {
public int getRowHeight() {
if (ExperimentalUI.isNewUI()) {
Insets innerInsets = JBUI.CurrentTheme.Popup.Selection.innerInsets();
return JBUI.scale(JBUI.CurrentTheme.List.rowHeight()) + innerInsets.top + innerInsets.bottom;
return JBUI.CurrentTheme.List.rowHeight() + innerInsets.top + innerInsets.bottom;
}
return super.getRowHeight() + 2 * ShowUsagesTableCellRenderer.MARGIN;

View File

@@ -104,7 +104,8 @@ public class CreateWithTemplatesDialogPanel extends NewItemWithTemplatesPopupPan
}
};
wrapper.setBackground(JBUI.CurrentTheme.Popup.BACKGROUND);
wrapper.setBorder(JBUI.Borders.emptyTop(JBUI.CurrentTheme.NewClassDialog.fieldsSeparatorWidth()));
//noinspection UseDPIAwareBorders
wrapper.setBorder(new EmptyBorder(JBUI.CurrentTheme.NewClassDialog.fieldsSeparatorWidth(), 0, 0, 0));
wrapper.add(delegate, BorderLayout.CENTER);
return wrapper;
}

View File

@@ -253,7 +253,7 @@ public final class PopupUtil {
public static void configListRendererFixedHeight(SelectablePanel selectablePanel) {
configListRendererFlexibleHeight(selectablePanel);
selectablePanel.setPreferredHeight(JBUI.scale(JBUI.CurrentTheme.List.rowHeight()));
selectablePanel.setPreferredHeight(JBUI.CurrentTheme.List.rowHeight());
}
public static void configListRendererFlexibleHeight(SelectablePanel selectablePanel) {

View File

@@ -79,7 +79,7 @@ abstract class GroupedComboBoxRenderer<T>(val combo: ComboBox<T>? = null) : Grou
override fun getPreferredSize(): Dimension {
return super.getPreferredSize().let {
if (maxWidth > 0) it.width = maxWidth
it.height = JBUI.scale(JBUI.CurrentTheme.List.rowHeight())
it.height = JBUI.CurrentTheme.List.rowHeight()
if (!ExperimentalUI.isNewUI()) {
val insets = ComboBoxPopup.COMBO_ITEM_BORDER.borderInsets
it.height += insets.bottom + insets.top

View File

@@ -207,7 +207,7 @@ internal class LcrRowImpl<T>(private val renderer: LcrRow<T>.() -> Unit) : LcrRo
selectionInsets = JBInsets.create(0, 12)
border = JBUI.Borders.empty(0, 20)
}
preferredHeight = JBUI.scale(JBUI.CurrentTheme.List.rowHeight())
preferredHeight = JBUI.CurrentTheme.List.rowHeight()
background = list.background
selectionColor = selectionBg

View File

@@ -70,7 +70,7 @@ public class IdeaMenuUI extends BasicMenuUI {
JBInsets outerInsets = IdeaPopupMenuUI.isPartOfPopupMenu(c)
? JBUI.CurrentTheme.PopupMenu.Selection.outerInsets()
: JBUI.CurrentTheme.Menu.Selection.outerInsets();
return new Dimension(preferredSize.width, JBUI.scale(JBUI.CurrentTheme.List.rowHeight()) + outerInsets.height());
return new Dimension(preferredSize.width, JBUI.CurrentTheme.List.rowHeight() + outerInsets.height());
}
return preferredSize;

View File

@@ -118,7 +118,7 @@ public class PopupListElementRenderer<E> extends GroupedItemsListRenderer<E> {
public Dimension getPreferredSize() {
Dimension size = super.getPreferredSize();
if (ExperimentalUI.isNewUI()) {
size.height = JBUI.scale(JBUI.CurrentTheme.List.rowHeight());
size.height = JBUI.CurrentTheme.List.rowHeight();
}
return size;
}

View File

@@ -354,7 +354,7 @@ public class TreePopupImpl extends WizardPopup implements TreePopup, NextStepHan
public @NotNull Dimension getPreferredSize() {
Dimension size = super.getPreferredSize();
if (ExperimentalUI.isNewUI()) {
size.height = JBUI.scale(JBUI.CurrentTheme.Tree.rowHeight());
size.height = JBUI.CurrentTheme.Tree.rowHeight();
}
return size;
}

View File

@@ -22,7 +22,7 @@ class DefaultTreeLayoutCache(
private val autoExpandHandler: (TreePath) -> Unit,
) : AbstractLayoutCache() {
constructor(autoExpandHandler: (TreePath) -> Unit) : this(JBUI.scale(JBUI.CurrentTheme.Tree.rowHeight()), autoExpandHandler)
constructor(autoExpandHandler: (TreePath) -> Unit) : this(JBUI.CurrentTheme.Tree.rowHeight(), autoExpandHandler)
private var root: Node? = null
private val rows = NodeList(onUpdate = {

View File

@@ -1282,7 +1282,7 @@ public final class JBUI {
}
public static int fontSizeOffset() {
return getInt("CompletionPopup.Advertiser.fontSizeOffset", Math.round(CurrentTheme.Advertiser.FONT_SIZE_OFFSET.getUnscaled()));
return getInt("CompletionPopup.Advertiser.fontSizeOffset", CurrentTheme.Advertiser.FONT_SIZE_OFFSET.get());
}
public static @NotNull Border border() {
@@ -1923,7 +1923,7 @@ public final class JBUI {
}
public static int fieldsSeparatorWidth() {
return getInt("NewClass.separatorWidth", 10);
return getInt("NewClass.separatorWidth", JBUIScale.scale(10));
}
}
@@ -1986,9 +1986,8 @@ public final class JBUI {
return selected ? Selection.foreground(focused) : FOREGROUND;
}
/** @return <b>unscaled</b> value */
static int rowHeight() {
int defaultHeight = 24;
int defaultHeight = JBUIScale.scale(24);
int result = getInt("List.rowHeight", defaultHeight);
// Linux doesn't support rowHeight now, use default value. See IDEA-234112
return result <= 0 ? defaultHeight : result;
@@ -2107,7 +2106,6 @@ public final class JBUI {
return selected ? Selection.foreground(focused) : FOREGROUND;
}
/** @return <b>unscaled</b> value */
static int rowHeight() {
int defaultHeight = defaultRowHeight();
int result = getInt(rowHeightKey(), defaultHeight);
@@ -2120,7 +2118,7 @@ public final class JBUI {
}
static int defaultRowHeight() {
return 24;
return JBUIScale.scale(24);
}
final class Selection {
@@ -2271,19 +2269,11 @@ public final class JBUI {
}
}
/**
* @param defaultValue must be <b>unscaled</b>
* @return <b>unscaled</b> value of {@code propertyName} if it is specified, otherwise the {@code defaultValue}
*/
public static int getInt(@NonNls @NotNull String propertyName, int defaultValue) {
Object value = UIManager.get(propertyName);
return value instanceof Integer ? (Integer)value : defaultValue;
}
/**
* @param defaultValue must be <b>unscaled</b>
* @return <b>unscaled</b> value of {@code propertyName} if it is specified, otherwise the {@code defaultValue}
*/
public static float getFloat(@NonNls @NotNull String propertyName, float defaultValue) {
Object value = UIManager.get(propertyName);
if (value instanceof Float) return (Float)value;

View File

@@ -723,7 +723,7 @@ class GitBranchesTreePopup(project: Project, step: GitBranchesTreePopupStep, par
internal val POPUP_KEY = DataKey.create<GitBranchesTreePopup>("GIT_BRANCHES_TREE_POPUP")
internal val treeRowHeight: Int
get() = if (isNewUI) JBUI.scale(JBUI.CurrentTheme.List.rowHeight()) else JBUIScale.scale(22)
get() = if (isNewUI) JBUI.CurrentTheme.List.rowHeight() else JBUIScale.scale(22)
/**
* @param selectedRepository - Selected repository:

View File

@@ -176,8 +176,8 @@ internal class PackagesTable(
setShowGrid(false)
rowHeight = JBUI.getInt(
"PackageSearch.PackagesList.rowHeight",
JBUI.getInt("List.rowHeight", if (PackageSearchUI.isNewUI) 24 else 20)
).scaled()
JBUI.getInt("List.rowHeight", if (PackageSearchUI.isNewUI) 24.scaled() else 20.scaled())
)
setExpandableItemsEnabled(false)
selectionModel.selectionMode = ListSelectionModel.SINGLE_SELECTION