From 5a71df9d9b4f1156dbc586dca2f2425a00e8e70f Mon Sep 17 00:00:00 2001 From: Pavel Porvatov Date: Sun, 23 Feb 2025 21:55:42 +0100 Subject: [PATCH] IJPL-178429 Custom row gaps are not applied for single row GitOrigin-RevId: 792ea9b8429a76976b7de87c717688d52bb2cec6 --- .../ui/dsl/builder/impl/PanelBuilder.kt | 8 +++-- .../intellij/ui/dsl/builder/impl/PanelImpl.kt | 31 ++++++++++--------- .../intellij/ui/dsl/builder/impl/RowImpl.kt | 17 ++++------ .../intellij/ui/dsl/builder/BuilderTest.kt | 28 +++++++++++++++++ 4 files changed, 57 insertions(+), 27 deletions(-) create mode 100644 platform/platform-tests/testSrc/com/intellij/ui/dsl/builder/BuilderTest.kt diff --git a/platform/platform-impl/src/com/intellij/ui/dsl/builder/impl/PanelBuilder.kt b/platform/platform-impl/src/com/intellij/ui/dsl/builder/impl/PanelBuilder.kt index 916bdb3be5ed..c72c8a79a6c1 100644 --- a/platform/platform-impl/src/com/intellij/ui/dsl/builder/impl/PanelBuilder.kt +++ b/platform/platform-impl/src/com/intellij/ui/dsl/builder/impl/PanelBuilder.kt @@ -370,18 +370,22 @@ internal class PanelBuilder(val rows: List, private val dialogPanelConf } private fun getRowGaps(row: RowImpl, first: Boolean, last: Boolean): UnscaledGapsY { + row.customGaps?.let { + return it + } + val top = when (row.topGap) { TopGap.NONE -> 0 TopGap.SMALL -> spacingConfiguration.verticalSmallGap TopGap.MEDIUM -> spacingConfiguration.verticalMediumGap - null -> if (first) 0 else row.internalTopGap + null -> if (first) 0 else row.internalGaps.top } val bottom = when (row.bottomGap) { BottomGap.NONE -> 0 BottomGap.SMALL -> spacingConfiguration.verticalSmallGap BottomGap.MEDIUM -> spacingConfiguration.verticalMediumGap - null -> if (last) 0 else row.internalBottomGap + null -> if (last) 0 else row.internalGaps.bottom } return if (top > 0 || bottom > 0) UnscaledGapsY(top = top, bottom = bottom) else UnscaledGapsY.EMPTY diff --git a/platform/platform-impl/src/com/intellij/ui/dsl/builder/impl/PanelImpl.kt b/platform/platform-impl/src/com/intellij/ui/dsl/builder/impl/PanelImpl.kt index 03fa504066d9..3bbfd7dd2ca9 100644 --- a/platform/platform-impl/src/com/intellij/ui/dsl/builder/impl/PanelImpl.kt +++ b/platform/platform-impl/src/com/intellij/ui/dsl/builder/impl/PanelImpl.kt @@ -16,9 +16,11 @@ import javax.swing.JComponent import javax.swing.JLabel @ApiStatus.Internal -internal class PanelImpl(private val dialogPanelConfig: DialogPanelConfig, - var spacingConfiguration: SpacingConfiguration, - private val parent: RowImpl?) : CellBaseImpl(), Panel { +internal class PanelImpl( + private val dialogPanelConfig: DialogPanelConfig, + var spacingConfiguration: SpacingConfiguration, + private val parent: RowImpl?, +) : CellBaseImpl(), Panel { val rows: List get() = _rows @@ -48,7 +50,8 @@ internal class PanelImpl(private val dialogPanelConfig: DialogPanelConfig, val result: RowImpl if (label == null) { result = RowImpl(dialogPanelConfig, panelContext, this, RowLayout.INDEPENDENT) - } else { + } + else { label.putClientProperty(DslComponentProperty.ROW_LABEL, true) result = RowImpl(dialogPanelConfig, panelContext, this, RowLayout.LABEL_ALIGNED) result.cell(label) @@ -170,14 +173,15 @@ internal class PanelImpl(private val dialogPanelConfig: DialogPanelConfig, } }.align(AlignY.FILL) } - result.internalTopGap = spacingConfiguration.verticalMediumGap - result.internalBottomGap = spacingConfiguration.verticalMediumGap + result.internalGaps = UnscaledGapsY(top = spacingConfiguration.verticalMediumGap, bottom = spacingConfiguration.verticalMediumGap) return result } - override fun groupRowsRange(title: String?, indent: Boolean, topGroupGap: Boolean?, bottomGroupGap: Boolean?, - init: Panel.() -> Unit): RowsRangeImpl { + override fun groupRowsRange( + title: String?, indent: Boolean, topGroupGap: Boolean?, bottomGroupGap: Boolean?, + init: Panel.() -> Unit, + ): RowsRangeImpl { val result = createRowRange() createSeparatorRow(title) if (indent) { @@ -205,8 +209,7 @@ internal class PanelImpl(private val dialogPanelConfig: DialogPanelConfig, } result.expanded = false - result.internalTopGap = spacingConfiguration.verticalMediumGap - result.internalBottomGap = spacingConfiguration.verticalMediumGap + result.internalGaps = UnscaledGapsY(top = spacingConfiguration.verticalMediumGap, bottom = spacingConfiguration.verticalMediumGap) _rows.add(result) return result @@ -223,7 +226,7 @@ internal class PanelImpl(private val dialogPanelConfig: DialogPanelConfig, label(title) .applyToComponent { putClientProperty(DslComponentProperty.VERTICAL_COMPONENT_GAP, VerticalComponentGap(bottom = false)) } } - row.internalBottomGap = spacingConfiguration.buttonGroupHeaderBottomGap + row.internalGaps = UnscaledGapsY(bottom = spacingConfiguration.buttonGroupHeaderBottomGap) } if (indent) { @@ -395,7 +398,7 @@ internal class PanelImpl(private val dialogPanelConfig: DialogPanelConfig, private fun setTopGroupGap(row: RowImpl, topGap: Boolean?) { if (topGap == null) { - row.internalTopGap = spacingConfiguration.verticalMediumGap + row.internalGaps = row.internalGaps.copy(top = spacingConfiguration.verticalMediumGap) } else { row.topGap(if (topGap) TopGap.MEDIUM else TopGap.NONE) @@ -404,7 +407,7 @@ internal class PanelImpl(private val dialogPanelConfig: DialogPanelConfig, private fun setBottomGroupGap(row: RowImpl, bottomGap: Boolean?) { if (bottomGap == null) { - row.internalBottomGap = spacingConfiguration.verticalMediumGap + row.internalGaps = row.internalGaps.copy(bottom = spacingConfiguration.verticalMediumGap) } else { row.bottomGap(if (bottomGap) BottomGap.MEDIUM else BottomGap.NONE) @@ -422,7 +425,7 @@ internal data class PanelContext( /** * Number of [SpacingConfiguration.horizontalIndent] indents before each row in the panel */ - val indentCount: Int = 0 + val indentCount: Int = 0, ) private fun Panel.createSeparatorRow(@NlsContexts.Separator title: String?): Row { diff --git a/platform/platform-impl/src/com/intellij/ui/dsl/builder/impl/RowImpl.kt b/platform/platform-impl/src/com/intellij/ui/dsl/builder/impl/RowImpl.kt index 2bac7796c531..135a88ef6e04 100644 --- a/platform/platform-impl/src/com/intellij/ui/dsl/builder/impl/RowImpl.kt +++ b/platform/platform-impl/src/com/intellij/ui/dsl/builder/impl/RowImpl.kt @@ -58,18 +58,16 @@ internal open class RowImpl(private val dialogPanelConfig: DialogPanelConfig, var topGap: TopGap? = null private set - /** - * Used if topGap is not set, skipped for first row - */ - var internalTopGap: Int = 0 - var bottomGap: BottomGap? = null private set /** - * Used if bottomGap is not set, skipped for last row + * Top is used if topGap is not set, skipped for first row + * Bottom is used if bottomGap is not set, skipped for last row */ - var internalBottomGap: Int = 0 + var internalGaps: UnscaledGapsY = UnscaledGapsY.EMPTY + + var customGaps: UnscaledGapsY? = null val cells: MutableList?> = mutableListOf() @@ -387,10 +385,7 @@ internal open class RowImpl(private val dialogPanelConfig: DialogPanelConfig, } override fun customize(customRowGaps: UnscaledGapsY): Row { - internalTopGap = customRowGaps.top - internalBottomGap = customRowGaps.bottom - topGap = null - bottomGap = null + customGaps = customRowGaps return this } diff --git a/platform/platform-tests/testSrc/com/intellij/ui/dsl/builder/BuilderTest.kt b/platform/platform-tests/testSrc/com/intellij/ui/dsl/builder/BuilderTest.kt new file mode 100644 index 000000000000..6015ee89905c --- /dev/null +++ b/platform/platform-tests/testSrc/com/intellij/ui/dsl/builder/BuilderTest.kt @@ -0,0 +1,28 @@ +// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +package com.intellij.ui.dsl.builder + +import com.intellij.testFramework.TestApplicationManager +import com.intellij.ui.dsl.gridLayout.UnscaledGapsY +import com.intellij.ui.scale.JBUIScale +import org.junit.Before +import org.junit.Test +import kotlin.test.assertTrue + +class BuilderTest { + + @Before + fun before() { + TestApplicationManager.getInstance() + } + + @Test + fun testRowCustomize() { + val panel = panel { + row { + label("Label") + }.customize(UnscaledGapsY(top = 50, bottom = 50)) + } + + assertTrue(panel.preferredSize.height > JBUIScale.scale(100), "Row customize is ignored") + } +} \ No newline at end of file