Wizard: fix UI layout

This commit is contained in:
Ilya Kirillov
2020-03-24 23:30:33 +03:00
parent 2d9dc2994b
commit 670a98c8bf
11 changed files with 37 additions and 23 deletions
@@ -70,7 +70,8 @@ abstract class DynamicComponent(private val context: Context) : Component() {
}
abstract class TitledComponent(context: Context) : DynamicComponent(context) {
open val needCentering: Boolean = true
open val forceLabelCenteringOffset: Int? = null
open val additionalComponentPadding: Int = 0
open val maximumWidth: Int? = null
abstract val title: String?
open fun shouldBeShow(): Boolean = true
@@ -38,6 +38,7 @@ class BuildSystemTypeSettingComponent(
BuildSystemPlugin::type.reference,
context
), Disposable {
override val forceLabelCenteringOffset: Int? = 2
private val buttons = setting.type.values.map(::BuildSystemChooseButton)
override val component = panel {
row {
@@ -10,7 +10,6 @@ import com.intellij.ui.TitledSeparator
import com.intellij.ui.layout.panel
import com.intellij.util.ui.JBUI
import com.intellij.util.ui.components.BorderLayoutPanel
import org.jetbrains.kotlin.idea.framework.KotlinModuleBuilder
import org.jetbrains.kotlin.tools.projectWizard.core.Context
import org.jetbrains.kotlin.tools.projectWizard.core.entity.path
import org.jetbrains.kotlin.tools.projectWizard.core.entity.settings.SettingReference
@@ -43,7 +42,9 @@ class FirstWizardStepComponent(ideWizard: IdeWizard) : WizardStepComponent(ideWi
class ProjectSettingsComponent(ideWizard: IdeWizard) : DynamicComponent(ideWizard.context) {
private val context = ideWizard.context
private val projectTemplateComponent = ProjectTemplateSettingComponent(context).asSubComponent()
private val buildSystemSetting = BuildSystemTypeSettingComponent(context).asSubComponent()
private val buildSystemSetting = BuildSystemTypeSettingComponent(context).asSubComponent().apply {
component.addBorder(JBUI.Borders.empty(0, /*left&right*/4))
}
private val buildSystemAdditionalSettingsComponent = BuildSystemAdditionalSettingsComponent(ideWizard).asSubComponent()
private val nameAndLocationComponent = TitledComponentsList(
@@ -66,7 +67,7 @@ class ProjectSettingsComponent(ideWizard: IdeWizard) : DynamicComponent(ideWizar
row {
buildSystemAdditionalSettingsComponent.component(growX)
}
}
}.addBorder(JBUI.Borders.emptyRight(UIConstants.PADDING))
}
private var locationWasUpdatedByHand: Boolean = false
@@ -234,10 +235,10 @@ class ProjectPreviewComponent(context: Context) : DynamicComponent(context) {
).asSubComponent()
override val component: JComponent = borderPanel {
border = JBUI.Borders.empty(10)
addToTop(label("Preview", bold = true).addBorder(JBUI.Borders.emptyBottom(5)))
addToCenter(modulesEditorComponent.component)
}.addBorder(JBUI.Borders.customLine(JBColor.border(), 0, /*left*/1, 0, 0))
}.addBorder(JBUI.Borders.empty(UIConstants.PADDING, /*left*/UIConstants.PADDING * 2, UIConstants.PADDING, UIConstants.PADDING))
.addBorder(JBUI.Borders.customLine(JBColor.border(), 0, /*left*/1, 0, 0))
override fun onValueUpdated(reference: SettingReference<*, *>?) {
super.onValueUpdated(reference)
@@ -24,7 +24,7 @@ class ProjectTemplateSettingComponent(
context
) {
override val validationIndicator: ValidationIndicator? get() = null
override val needCentering: Boolean = false
override val forceLabelCenteringOffset: Int? = 4
private val templateDescriptionComponent = TemplateDescriptionComponent().asSubComponent()
private val list = ImmutableSingleSelectableListWithIcon(
@@ -64,9 +64,9 @@ class ProjectTemplateSettingComponent(
}
class TemplateDescriptionComponent : Component() {
private val descriptionLabel = label("").apply {
private val descriptionLabel = label("") {
fontColor = UIUtil.FontColor.BRIGHTER
preferredSize = Dimension(preferredSize.width, 55)
preferredSize = Dimension(preferredSize.width, 45)
verticalAlignment = SwingConstants.TOP
}
@@ -23,7 +23,8 @@ class ModuleDependenciesComponent(
) : TitledComponent(context) {
override val title: String = "Module dependencies"
private val dependenciesList = ModuleDependenciesList()
override val needCentering: Boolean = false
override val forceLabelCenteringOffset: Int? = 4
override val additionalComponentPadding: Int = 1
override val maximumWidth: Int = 500
private val toolbarDecorator: ToolbarDecorator = ToolbarDecorator.createDecorator(dependenciesList).apply {
@@ -127,7 +127,7 @@ private class ModuleTemplateComponent(
onTemplateChanged()
}.asSubComponent()
override val needCentering: Boolean = false
override val forceLabelCenteringOffset: Int? = 4
private val templateDescriptionLabel = label("") {
fontColor = UIUtil.FontColor.BRIGHTER
addBorder(JBUI.Borders.empty(4, 4))
@@ -53,7 +53,7 @@ class ProjectStructureEditorComponent(
).asSubComponent()
override val component = borderPanel {
addToCenter(moduleSettingComponent.component)
addToCenter(moduleSettingComponent.component.addBorder(JBUI.Borders.empty(UIConstants.PADDING)))
}
}
@@ -11,6 +11,8 @@ import org.jetbrains.kotlin.tools.projectWizard.plugins.kotlin.KotlinPlugin
import org.jetbrains.kotlin.tools.projectWizard.plugins.kotlin.ProjectKind
import org.jetbrains.kotlin.tools.projectWizard.settings.DisplayableSettingItem
import org.jetbrains.kotlin.tools.projectWizard.settings.buildsystem.Module
import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.UIConstants
import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.addBorder
import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.customPanel
import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.setting.SettingComponent
import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.setting.ValidationIndicator
@@ -44,7 +46,9 @@ class ModulesEditorComponent(
)?.showInCenterOf(component)
}
).apply {
border = JBUI.Borders.emptyRight(10)
if (editable) {
border = JBUI.Borders.emptyRight(10)
}
}
private val model = TargetsModel(tree, ::value, context, uiEditorUsagesStats)
@@ -53,20 +53,21 @@ open class TitledComponentsList(
TitledComponentData(
label.also { add(it) }.constraints(),
component.component.also { add(it) }.constraints(),
component.needCentering,
component.forceLabelCenteringOffset,
component.additionalComponentPadding,
component.maximumWidth
)
}
fun TitledComponentData.centerConstraint() =
if (needCentering) component.height * .5f - label.height * .5f
else 4.asSpring()
if (forceCenteringOffset == null) component.height * .5f - label.height * .5f
else forceCenteringOffset.asSpring()
val labelWidth = componentsWithLabels.fold(componentsWithLabels.first().label.width) { spring, row ->
Spring.max(spring, row.label.width)
}
componentsWithLabels.forEach { (label, component, _, componentMaxWidth) ->
componentsWithLabels.forEach { (label, component, _, _, componentMaxWidth) ->
label.width = labelWidth
val maxWidth = componentMaxWidth ?: globalMaxWidth
if (maxWidth == null) {
@@ -85,7 +86,7 @@ open class TitledComponentsList(
component.x = label[SpringLayout.EAST] + xGap
if (lastComponent != null && lastLabel != null) {
val constraint = lastComponent[SpringLayout.SOUTH] + yGap
val constraint = lastComponent[SpringLayout.SOUTH] + yGap + data.additionalComponentGap
label.y = constraint + data.centerConstraint()
component.y = constraint
} else {
@@ -106,15 +107,16 @@ open class TitledComponentsList(
private const val xGap = 5
private const val yGapSmall = 6
private const val yGapBig = 12
private const val xPanelPadding = 16
private const val yPanelPadding = 16
private const val xPanelPadding = UIConstants.PADDING
private const val yPanelPadding = UIConstants.PADDING
}
private data class TitledComponentData(
val label: SpringLayout.Constraints,
val component: SpringLayout.Constraints,
val needCentering: Boolean,
val maximumWidth: Int?,
val forceCenteringOffset: Int?,
val additionalComponentGap: Int,
val maximumWidth: Int?
)
}
@@ -149,3 +149,7 @@ val DisplayableSettingItem.fullTextHtml
append("</span>")
}
}.asHtml()
object UIConstants {
const val PADDING = 8
}
@@ -44,7 +44,7 @@ class RealNativeTargetConfigurator private constructor(
object NativeForCurrentSystemTarget : NativeTargetConfigurator, SingleCoexistenceTargetConfigurator {
override val moduleType = ModuleType.native
override val id = "nativeForCurrentSystem"
override val text = "For Current System"
override val text = "Your system"
override fun Reader.createTargetIrs(