Skip to content

Commit

Permalink
create ComponentScope for dsl-safe component addition in panel and te…
Browse files Browse the repository at this point in the history
…xtbox dsl.

End of file line added to all files in dsl.component directory lacking it.
  • Loading branch information
lesbiangunshow committed Apr 19, 2021
1 parent 6354fc1 commit a1a9a0e
Show file tree
Hide file tree
Showing 23 changed files with 150 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ fun checkBox(
labelAlignment: DefaultCheckBox.CheckBoxAlignment = DefaultCheckBox.CheckBoxAlignment.RIGHT,
init: CheckBoxBuilder.() -> Unit
): CheckBox =
CheckBoxBuilder(labelAlignment = labelAlignment).apply(init).build()
CheckBoxBuilder(labelAlignment = labelAlignment).apply(init).build()
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ import org.hexworks.zircon.api.builder.component.ColorThemeBuilder
import org.hexworks.zircon.api.component.ColorTheme

fun colorTheme(init: ColorThemeBuilder.() -> Unit): ColorTheme =
ColorThemeBuilder().apply(init).build()
ColorThemeBuilder().apply(init).build()
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
package org.hexworks.zircon.api.dsl.component

import org.hexworks.zircon.api.builder.component.*
import org.hexworks.zircon.api.component.*
import org.hexworks.zircon.api.component.modal.Modal
import org.hexworks.zircon.api.component.modal.ModalResult
import org.hexworks.zircon.api.data.Position
import org.hexworks.zircon.internal.component.impl.DefaultCheckBox

class ComponentScope {
private lateinit var component: Component

fun button(init: ButtonBuilder.() -> Unit) {
component = ButtonBuilder().apply(init).build()
}

fun checkBox(
labelAlignment: DefaultCheckBox.CheckBoxAlignment = DefaultCheckBox.CheckBoxAlignment.RIGHT,
init: CheckBoxBuilder.() -> Unit
) {
component = CheckBoxBuilder(labelAlignment = labelAlignment).apply(init).build()
}

fun hBox(init: HBoxBuilder.() -> Unit) {
component = HBoxBuilder().apply(init).build()
}

fun header(init: HeaderBuilder.() -> Unit) {
component = HeaderBuilder().apply(init).build()
}

fun horizontalNumberInput(
width: Int,
init: HorizontalNumberInputBuilder.() -> Unit
) {
component = HorizontalNumberInputBuilder(width).apply(init).build()
}

fun horizontalScrollBar(
minValue: Int = 0,
maxValue: Int = 100,
init: HorizontalScrollBarBuilder.() -> Unit
) {
component = HorizontalScrollBarBuilder(minValue, maxValue).apply(init).build()
}

fun horizontalSlider(init: HorizontalSliderBuilder.() -> Unit) {
component = HorizontalSliderBuilder().apply(init).build()
}

fun icon(init: IconBuilder.() -> Unit) {
component = IconBuilder().apply(init).build()
}

fun label(init: LabelBuilder.() -> Unit) {
component = LabelBuilder().apply(init).build()
}

fun listItem(init: ListItemBuilder.() -> Unit) {
component = ListItemBuilder().apply(init).build()
}

fun logArea(init: LogAreaBuilder.() -> Unit) {
component = LogAreaBuilder().apply(init).build()
}

fun <T : ModalResult> modal(init: ModalBuilder<T>.() -> Unit) {
component = ModalBuilder<T>().apply(init).build()
}

fun panel() {
PanelBuilder().build()
}

fun paragraph(init: ParagraphBuilder.() -> Unit) {
component = ParagraphBuilder().apply(init).build()
}

fun progressBar(init: ProgressBarBuilder.() -> Unit) {
component = ProgressBarBuilder().apply(init).build()
}

fun radioButton(init: RadioButtonBuilder.() -> Unit) {
component = RadioButtonBuilder().apply(init).build()
}

fun textArea(init: TextAreaBuilder.() -> Unit) {
TextAreaBuilder().apply(init).build()
}

fun textBox(
initialContentWidth: Int,
nextPosition: Position = Position.defaultPosition(),
components: MutableList<Component> = mutableListOf(),
init: TextBoxBuilder.() -> Unit
) {
component = TextBoxBuilder(initialContentWidth, nextPosition, components).apply(init).build()
}

fun toggleButton(init: ToggleButtonBuilder.() -> Unit) {
ToggleButtonBuilder().apply(init).build()
}

fun vBox(init: VBoxBuilder.() -> Unit) {
component = VBoxBuilder().apply(init).build()
}

fun verticalNumberInput(height: Int, init: VerticalNumberInputBuilder.() -> Unit) {
component = VerticalNumberInputBuilder(height).apply(init).build()
}

fun verticalScrollBar(
minValue: Int = 0,
maxValue: Int = 100,
init: VerticalScrollBarBuilder.() -> Unit
) {
component = VerticalScrollBarBuilder(minValue, maxValue).apply(init).build()
}

fun verticalSlider(init: VerticalSliderBuilder.() -> Unit) {
component = VerticalSliderBuilder().apply(init).build()
}

fun build(): Component = component
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ import org.hexworks.zircon.api.builder.component.HBoxBuilder
import org.hexworks.zircon.api.component.HBox

fun hBox(init: HBoxBuilder.() -> Unit): HBox =
HBoxBuilder().apply(init).build()
HBoxBuilder().apply(init).build()
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ import org.hexworks.zircon.api.builder.component.HeaderBuilder
import org.hexworks.zircon.api.component.Header

fun header(init: HeaderBuilder.() -> Unit): Header =
HeaderBuilder().apply(init).build()
HeaderBuilder().apply(init).build()
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ fun horizontalScrollBar(
maxValue: Int = 100,
init: HorizontalScrollBarBuilder.() -> Unit
): ScrollBar =
HorizontalScrollBarBuilder(minValue, maxValue).apply(init).build()
HorizontalScrollBarBuilder(minValue, maxValue).apply(init).build()
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ import org.hexworks.zircon.api.builder.component.HorizontalSliderBuilder
import org.hexworks.zircon.api.component.Slider

fun horizontalSlider(init: HorizontalSliderBuilder.() -> Unit): Slider =
HorizontalSliderBuilder().apply(init).build()
HorizontalSliderBuilder().apply(init).build()
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ fun icon(init: IconBuilder.() -> Unit): Icon =
fun IconBuilder.iconTile(init: TileBuilder.() -> Unit) =
withIcon(
TileBuilder().apply(init).build()
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ import org.hexworks.zircon.api.builder.component.LabelBuilder
import org.hexworks.zircon.api.component.Label

fun label(init: LabelBuilder.() -> Unit): Label =
LabelBuilder().apply(init).build()
LabelBuilder().apply(init).build()
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ import org.hexworks.zircon.api.builder.component.ListItemBuilder
import org.hexworks.zircon.api.component.ListItem

fun listItem(init: ListItemBuilder.() -> Unit): ListItem =
ListItemBuilder().apply(init).build()
ListItemBuilder().apply(init).build()
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ import org.hexworks.zircon.api.builder.component.LogAreaBuilder
import org.hexworks.zircon.api.component.LogArea

fun logArea(init: LogAreaBuilder.() -> Unit): LogArea =
LogAreaBuilder().apply(init).build()
LogAreaBuilder().apply(init).build()
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import org.hexworks.zircon.api.component.modal.ModalResult
fun <T : ModalResult> modal(init: ModalBuilder<T>.() -> Unit): Modal<T> =
ModalBuilder<T>().apply(init).build()

fun <T : ModalResult> ModalBuilder<T>.component(init: () -> Component) {
fun <T : ModalResult> ModalBuilder<T>.component(init: ComponentScope.() -> Unit) {
withComponent(
init()
ComponentScope().apply(init).build()
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ import org.hexworks.zircon.api.component.Panel

fun panel(): Panel =
PanelBuilder().build()

Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ import org.hexworks.zircon.api.builder.component.ParagraphBuilder
import org.hexworks.zircon.api.component.Paragraph

fun paragraph(init: ParagraphBuilder.() -> Unit): Paragraph =
ParagraphBuilder().apply(init).build()
ParagraphBuilder().apply(init).build()
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ import org.hexworks.zircon.api.builder.component.RadioButtonBuilder
import org.hexworks.zircon.api.component.RadioButton

fun radioButton(init: RadioButtonBuilder.() -> Unit): RadioButton =
RadioButtonBuilder().apply(init).build()
RadioButtonBuilder().apply(init).build()
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ import org.hexworks.zircon.api.builder.component.RadioButtonGroupBuilder
import org.hexworks.zircon.api.component.RadioButtonGroup

fun radioButtonGroup(init: RadioButtonGroupBuilder.() -> Unit): RadioButtonGroup =
RadioButtonGroupBuilder().apply(init).build()
RadioButtonGroupBuilder().apply(init).build()
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ import org.hexworks.zircon.api.builder.component.TextAreaBuilder
import org.hexworks.zircon.api.component.TextArea

fun textArea(init: TextAreaBuilder.() -> Unit): TextArea =
TextAreaBuilder().apply(init).build()
TextAreaBuilder().apply(init).build()
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,7 @@ fun textBox(
fun TextBoxBuilder.paragraph(withNewLine: Boolean = true, init: ParagraphBuilder.() -> Unit) =
addParagraph(ParagraphBuilder().apply(init).build(), withNewLine)

fun TextBoxBuilder.inlineComponent(init: () -> Component) =
addInlineComponent(init())
fun TextBoxBuilder.inlineComponent(init: ComponentScope.() -> Unit) =
addInlineComponent(
ComponentScope().apply(init).build()
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ import org.hexworks.zircon.api.builder.component.ToggleButtonBuilder
import org.hexworks.zircon.api.component.ToggleButton

fun toggleButton(init: ToggleButtonBuilder.() -> Unit): ToggleButton =
ToggleButtonBuilder().apply(init).build()
ToggleButtonBuilder().apply(init).build()
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ import org.hexworks.zircon.api.builder.component.VBoxBuilder
import org.hexworks.zircon.api.component.VBox

fun vBox(init: VBoxBuilder.() -> Unit): VBox =
VBoxBuilder().apply(init).build()
VBoxBuilder().apply(init).build()
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ import org.hexworks.zircon.api.builder.component.VerticalNumberInputBuilder
import org.hexworks.zircon.api.component.NumberInput

fun verticalNumberInput(height: Int, init: VerticalNumberInputBuilder.() -> Unit): NumberInput =
VerticalNumberInputBuilder(height).apply(init).build()
VerticalNumberInputBuilder(height).apply(init).build()
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ fun verticalScrollBar(
maxValue: Int = 100,
init: VerticalScrollBarBuilder.() -> Unit
): ScrollBar =
VerticalScrollBarBuilder(minValue, maxValue).apply(init).build()
VerticalScrollBarBuilder(minValue, maxValue).apply(init).build()
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ import org.hexworks.zircon.api.builder.component.VerticalSliderBuilder
import org.hexworks.zircon.api.component.Slider

fun verticalSlider(init: VerticalSliderBuilder.() -> Unit): Slider =
VerticalSliderBuilder().apply(init).build()
VerticalSliderBuilder().apply(init).build()

0 comments on commit a1a9a0e

Please sign in to comment.