UI DSL: API for explicitly specifying the indent of subrows of the given row

GitOrigin-RevId: 4ddcd3218d2ce3625b43e1413f49db6ac7f81343
This commit is contained in:
Dmitry Jemerov
2019-11-22 18:37:27 +00:00
committed by intellij-monorepo-bot
parent 0884a17c1a
commit 79f6204fc4
6 changed files with 88 additions and 1 deletions
@@ -92,6 +92,12 @@ abstract class Row : Cell(), RowBuilder {
abstract var subRowsVisible: Boolean
/**
* Indent for child rows of this row, expressed in steps (multiples of [SpacingConfiguration.indentLevel]). Replaces indent
* calculated from row nesting.
*/
abstract var subRowIndent: Int
protected abstract val builder: LayoutBuilderImpl
/**
@@ -16,6 +16,7 @@ internal class ShowcaseUiDslAction : DumbAwareAction() {
tabs.presentation.setAlphabeticalMode(false)
tabs.addTab(TabInfo(secondColumnSmallerPanel()).setText("Second Column Smaller"))
tabs.addTab(TabInfo(rowWithIndent()).setText("Row with Indent"))
val dialog = dialog("UI DSL Showcase", tabs.component)
Disposer.register(dialog.disposable, disposable)
@@ -140,6 +140,8 @@ internal class MigLayoutRow(private val parent: MigLayoutRow?,
}
}
override var subRowIndent: Int = -1
internal val isLabeledIncludingSubRows: Boolean
get() = labeled || (subRows?.any { it.isLabeledIncludingSubRows } ?: false)
@@ -160,7 +162,7 @@ internal class MigLayoutRow(private val parent: MigLayoutRow?,
val row = MigLayoutRow(this, builder,
labeled = label != null,
noGrid = noGrid,
indent = indent + computeChildRowIndent(isSeparated))
indent = if (subRowIndent >= 0) subRowIndent * spacing.indentLevel else indent + computeChildRowIndent(isSeparated))
if (isSeparated) {
val separatorRow = MigLayoutRow(this, builder, indent = indent, noGrid = true)
@@ -308,3 +308,25 @@ fun separatorAndComment() : JPanel {
}
}
}
fun rowWithIndent(): JPanel {
return panel {
row("Zero") {
subRowIndent = 0
row("Bar 0") {
}
}
row("One") {
subRowIndent = 1
row("Bar 1") {
}
}
row("Two") {
subRowIndent = 2
row("Bar 2") {
}
}
}
}
@@ -0,0 +1,51 @@
layoutConstraints:
fillX: true
gridGapX:
min: &id001 {horizontal: true, unit: 0, value: 0.0}
preferred: *id001
gridGapY:
min: &id002 {horizontal: false, value: 10.0}
preferred: *id002
hideMode: 2
insets:
- {horizontal: false, unit: 0, value: 0.0}
- {horizontal: true, unit: 0, value: 0.0}
- {horizontal: false, unit: 0, value: 0.0}
- {horizontal: true, unit: 0, value: 0.0}
rowConstraints:
constraints:
- align: &id003 {horizontal: false, unit: -1, value: 0.0}
- align: *id003
- align: *id003
- align: *id003
- align: *id003
- align: *id003
count: 6
columnConstraints:
constraints:
- gapAfter:
max: &id004 {horizontal: true, value: 6.0}
min: *id004
preferred: *id004
grow: 0.0
- {}
count: 2
componentConstrains:
Zero [label]: {spanX: INF, wrap: true}
Bar 0 [label]: {spanX: INF, wrap: true}
One [label]: {spanX: INF, wrap: true}
Bar 1 [label]:
horizontal:
gapBefore:
min: &id005 {horizontal: true, value: 24.0}
preferred: *id005
spanX: INF
wrap: true
Two [label]: {spanX: INF, wrap: true}
Bar 2 [label]:
horizontal:
gapBefore:
min: &id006 {horizontal: true, value: 48.0}
preferred: *id006
spanX: INF
wrap: true
@@ -113,5 +113,10 @@ abstract class UiDslTest {
}
}
@Test
fun subRowsIndent() {
doTest { rowWithIndent() }
}
protected abstract fun doTest(panelCreator: () -> JPanel)
}