mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IJPL-178429 Custom row gaps are not applied for single row
GitOrigin-RevId: 792ea9b8429a76976b7de87c717688d52bb2cec6
This commit is contained in:
committed by
intellij-monorepo-bot
parent
471705cd8b
commit
5a71df9d9b
@@ -370,18 +370,22 @@ internal class PanelBuilder(val rows: List<RowImpl>, 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
|
||||
|
||||
@@ -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>(), Panel {
|
||||
internal class PanelImpl(
|
||||
private val dialogPanelConfig: DialogPanelConfig,
|
||||
var spacingConfiguration: SpacingConfiguration,
|
||||
private val parent: RowImpl?,
|
||||
) : CellBaseImpl<Panel>(), Panel {
|
||||
|
||||
val rows: List<RowImpl>
|
||||
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 {
|
||||
|
||||
@@ -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<CellBaseImpl<*>?> = 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
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user