From 670a98c8bf7d3725fa168e7472af3713286b3232 Mon Sep 17 00:00:00 2001 From: Ilya Kirillov Date: Tue, 24 Mar 2020 23:30:33 +0300 Subject: [PATCH] Wizard: fix UI layout --- .../projectWizard/wizard/ui/Component.kt | 3 ++- .../BuildSystemTypeSettingComponent.kt | 1 + .../ui/firstStep/FirstWizardStepComponent.kt | 11 +++++----- .../ProjectTemplateSettingComponent.kt | 6 +++--- .../secondStep/ModuleDependenciesComponent.kt | 3 ++- .../ui/secondStep/ModuleSettingsComponent.kt | 2 +- .../secondStep/SecondStepWizardComponent.kt | 2 +- .../modulesEditor/ModulesEditorComponent.kt | 6 +++++- .../wizard/ui/setting/TitledComponentsList.kt | 20 ++++++++++--------- .../tools/projectWizard/wizard/ui/ui.kt | 4 ++++ .../NativeTargetConfigurator.kt | 2 +- 11 files changed, 37 insertions(+), 23 deletions(-) diff --git a/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/Component.kt b/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/Component.kt index cb5539cd9ce..6a45f855c9e 100644 --- a/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/Component.kt +++ b/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/Component.kt @@ -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 diff --git a/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/firstStep/BuildSystemTypeSettingComponent.kt b/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/firstStep/BuildSystemTypeSettingComponent.kt index 5a5b4360896..8728fc3b8d8 100644 --- a/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/firstStep/BuildSystemTypeSettingComponent.kt +++ b/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/firstStep/BuildSystemTypeSettingComponent.kt @@ -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 { diff --git a/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/firstStep/FirstWizardStepComponent.kt b/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/firstStep/FirstWizardStepComponent.kt index 3522dfa138f..410be138ea5 100644 --- a/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/firstStep/FirstWizardStepComponent.kt +++ b/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/firstStep/FirstWizardStepComponent.kt @@ -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) diff --git a/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/firstStep/ProjectTemplateSettingComponent.kt b/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/firstStep/ProjectTemplateSettingComponent.kt index f01b4c130c8..b23ab4a2eb6 100644 --- a/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/firstStep/ProjectTemplateSettingComponent.kt +++ b/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/firstStep/ProjectTemplateSettingComponent.kt @@ -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 } diff --git a/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/secondStep/ModuleDependenciesComponent.kt b/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/secondStep/ModuleDependenciesComponent.kt index 866cb80b10a..55c275cf59f 100644 --- a/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/secondStep/ModuleDependenciesComponent.kt +++ b/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/secondStep/ModuleDependenciesComponent.kt @@ -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 { diff --git a/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/secondStep/ModuleSettingsComponent.kt b/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/secondStep/ModuleSettingsComponent.kt index f0ccc3c523d..47cffb8865c 100644 --- a/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/secondStep/ModuleSettingsComponent.kt +++ b/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/secondStep/ModuleSettingsComponent.kt @@ -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)) diff --git a/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/secondStep/SecondStepWizardComponent.kt b/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/secondStep/SecondStepWizardComponent.kt index 3deda8cb26b..d4bf18efeb7 100644 --- a/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/secondStep/SecondStepWizardComponent.kt +++ b/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/secondStep/SecondStepWizardComponent.kt @@ -53,7 +53,7 @@ class ProjectStructureEditorComponent( ).asSubComponent() override val component = borderPanel { - addToCenter(moduleSettingComponent.component) + addToCenter(moduleSettingComponent.component.addBorder(JBUI.Borders.empty(UIConstants.PADDING))) } } diff --git a/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/secondStep/modulesEditor/ModulesEditorComponent.kt b/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/secondStep/modulesEditor/ModulesEditorComponent.kt index 840991f4a1a..64767d893ee 100644 --- a/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/secondStep/modulesEditor/ModulesEditorComponent.kt +++ b/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/secondStep/modulesEditor/ModulesEditorComponent.kt @@ -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) diff --git a/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/setting/TitledComponentsList.kt b/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/setting/TitledComponentsList.kt index b9eb7e5be40..cd6566722f1 100644 --- a/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/setting/TitledComponentsList.kt +++ b/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/setting/TitledComponentsList.kt @@ -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? ) } diff --git a/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/ui.kt b/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/ui.kt index 5a87c7627a4..9e467c822af 100644 --- a/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/ui.kt +++ b/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/ui.kt @@ -149,3 +149,7 @@ val DisplayableSettingItem.fullTextHtml append("") } }.asHtml() + +object UIConstants { + const val PADDING = 8 +} \ No newline at end of file diff --git a/libraries/tools/new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/moduleConfigurators/NativeTargetConfigurator.kt b/libraries/tools/new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/moduleConfigurators/NativeTargetConfigurator.kt index 957416330b6..0a883bbcdb9 100644 --- a/libraries/tools/new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/moduleConfigurators/NativeTargetConfigurator.kt +++ b/libraries/tools/new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/moduleConfigurators/NativeTargetConfigurator.kt @@ -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(