aboutsummaryrefslogtreecommitdiff
path: root/examples/showcase/src/main/kotlin/com/example/LayoutsTab.kt
blob: f25da4fed29d5ca653a77dff83b8c0de9acc6e9c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
package com.example

import pl.treksoft.kvision.core.Background
import pl.treksoft.kvision.core.COLOR
import pl.treksoft.kvision.core.Container
import pl.treksoft.kvision.core.CssSize
import pl.treksoft.kvision.html.ALIGN
import pl.treksoft.kvision.html.TAG
import pl.treksoft.kvision.html.Tag
import pl.treksoft.kvision.panel.*
import pl.treksoft.kvision.utils.perc
import pl.treksoft.kvision.utils.px

class LayoutsTab : SimplePanel() {
    init {
        this.marginTop = 10.px()
        this.minHeight = 400.px()
        val panel = VPanel(spacing = 5)
        addHPanel(panel)
        addVPanel(panel)
        addFlexPanel1(panel)
        addFlexPanel2(panel)
        addFlexPanel3(panel)
        addFlexPanel4(panel)
        addFlexPanel5(panel)
        addGridPanel1(panel)
        addGridPanel2(panel)
        addRespGridPanel(panel)
        addDockPanel(panel)
        this.add(panel)
    }

    private fun addHPanel(panel: Container) {
        panel.add(Tag(TAG.H4, "Horizontal layout"))
        val hpanel = HPanel(spacing = 5)
        hpanel.add(getDiv("1", 100))
        hpanel.add(getDiv("2", 150))
        hpanel.add(getDiv("3", 200))
        panel.add(hpanel)
    }

    private fun addVPanel(panel: Container) {
        panel.add(Tag(TAG.H4, "Vertical layout"))
        val vpanel = VPanel(spacing = 5)
        vpanel.add(getDiv("1", 100))
        vpanel.add(getDiv("2", 150))
        vpanel.add(getDiv("3", 200))
        panel.add(vpanel)
    }

    private fun addFlexPanel1(panel: Container) {
        panel.add(Tag(TAG.H4, "CSS flexbox layouts"))
        val flexpanel = FlexPanel(
            FLEXDIR.ROW, FLEXWRAP.WRAP, FLEXJUSTIFY.FLEXEND, FLEXALIGNITEMS.CENTER,
            spacing = 5
        )
        flexpanel.add(getDiv("1", 100))
        flexpanel.add(getDiv("2", 150))
        flexpanel.add(getDiv("3", 200))
        panel.add(flexpanel)
    }

    private fun addFlexPanel2(panel: Container) {
        val flexpanel = FlexPanel(
            FLEXDIR.ROW, FLEXWRAP.WRAP, FLEXJUSTIFY.SPACEBETWEEN, FLEXALIGNITEMS.CENTER,
            spacing = 5
        )
        flexpanel.add(getDiv("1", 100))
        flexpanel.add(getDiv("2", 150))
        flexpanel.add(getDiv("3", 200))
        panel.add(flexpanel)
    }

    private fun addFlexPanel3(panel: Container) {
        val flexpanel = FlexPanel(
            FLEXDIR.ROW, FLEXWRAP.WRAP, FLEXJUSTIFY.CENTER, FLEXALIGNITEMS.CENTER,
            spacing = 5
        )
        flexpanel.add(getDiv("1", 100))
        flexpanel.add(getDiv("2", 150))
        flexpanel.add(getDiv("3", 200))
        panel.add(flexpanel)
    }

    private fun addFlexPanel4(panel: Container) {
        val flexpanel = FlexPanel(
            FLEXDIR.ROW, FLEXWRAP.WRAP, FLEXJUSTIFY.FLEXSTART, FLEXALIGNITEMS.CENTER,
            spacing = 5
        )
        flexpanel.add(getDiv("1", 100), order = 3)
        flexpanel.add(getDiv("2", 150), order = 1)
        flexpanel.add(getDiv("3", 200), order = 2)
        panel.add(flexpanel)
    }

    private fun addFlexPanel5(panel: Container) {
        val flexpanel = FlexPanel(
            FLEXDIR.COLUMN, FLEXWRAP.WRAP, FLEXJUSTIFY.FLEXSTART, FLEXALIGNITEMS.FLEXEND,
            spacing = 5
        )
        flexpanel.add(getDiv("1", 100), order = 3)
        flexpanel.add(getDiv("2", 150), order = 1)
        flexpanel.add(getDiv("3", 200), order = 2)
        panel.add(flexpanel)
    }

    private fun addGridPanel1(panel: Container) {
        panel.add(Tag(TAG.H4, "CSS grid layouts"))
        val gridpanel = GridPanel(columnGap = 5, rowGap = 5, justifyItems = GRIDJUSTIFY.CENTER)
        gridpanel.background = Background(COLOR.KHAKI)
        gridpanel.add(getDiv("1,1", 100), 1, 1)
        gridpanel.add(getDiv("1,2", 100), 1, 2)
        gridpanel.add(getDiv("2,1", 100), 2, 1)
        gridpanel.add(getDiv("2,2", 100), 2, 2)
        panel.add(gridpanel)
    }

    private fun addGridPanel2(panel: Container) {
        val gridpanel = GridPanel(columnGap = 5, rowGap = 5, justifyItems = GRIDJUSTIFY.CENTER)
        gridpanel.background = Background(COLOR.CORNFLOWERBLUE)
        gridpanel.add(getDiv("1,1", 150), 1, 1)
        gridpanel.add(getDiv("2,2", 150), 2, 2)
        gridpanel.add(getDiv("3,3", 150), 3, 3)
        panel.add(gridpanel)
    }

    private fun addRespGridPanel(panel: Container) {
        panel.add(Tag(TAG.H4, "Responsive grid layout"))
        val gridpanel = ResponsiveGridPanel()
        gridpanel.background = Background(COLOR.SILVER)
        gridpanel.add(getDiv("1,1", 150), 1, 1)
        gridpanel.add(getDiv("3,1", 150), 3, 1)
        gridpanel.add(getDiv("2,2", 150), 2, 2)
        gridpanel.add(getDiv("3,3", 150), 3, 3)
        panel.add(gridpanel)
    }

    private fun addDockPanel(panel: Container) {
        panel.add(Tag(TAG.H4, "Dock layout"))
        val dockpanel = DockPanel()
        dockpanel.background = Background(COLOR.YELLOW)
        dockpanel.add(getDiv("CENTER", 150), SIDE.CENTER)
        dockpanel.add(getDiv("LEFT", 150), SIDE.LEFT)
        dockpanel.add(getDiv("RIGHT", 150), SIDE.RIGHT)
        dockpanel.add(getDiv("UP", 150).apply { marginBottom = 10.px() }, SIDE.UP)
        dockpanel.add(getDiv("DOWN", 150).apply { marginTop = 10.px() }, SIDE.DOWN)
        panel.add(dockpanel)
    }


    private fun getDiv(value: String, size: Int): Tag {
        return Tag(TAG.DIV, value).apply {
            paddingTop = ((size / 2) - 10).px()
            align = ALIGN.CENTER
            background = Background(COLOR.GREEN)
            width = size.px()
            height = size.px()
        }
    }
}