-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMaterial3DebugLayouts.kt
192 lines (178 loc) · 5.37 KB
/
Material3DebugLayouts.kt
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/*
* Copyright (c) 2024, the pixnews-debuglayout project authors and contributors.
* Please see the AUTHORS file for details.
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
package ru.pixnews.debuglayout
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import ru.pixnews.debuglayout.LargeLayoutRegions.EXPANDED
import ru.pixnews.debuglayout.LargeLayoutRegions.OFF
import ru.pixnews.debuglayout.LargeLayoutRegions.ON
import ru.pixnews.debuglayout.rowcolumn.RowsColumnsCount
import ru.pixnews.debuglayout.rowcolumn.asRowColumnCount
/**
* 4dp baseline grid to help align text
*/
public fun DebugLayout.rowsText4Px(offset: Dp = 0.dp): Unit = rowsFromTop(
rows = RowsColumnsCount.Auto,
offset = offset,
height = 1.dp,
gutter = 3.dp,
color = DebugLayoutDefaults.colorGuidelines.copy(alpha = 0.05f),
)
/**
* 56dp area at the top
*/
public fun DebugLayout.rowTopToolbarArea(height: Dp = 56.dp): Unit = rowsFromTop(
rows = 1.asRowColumnCount,
height = height,
color = DebugLayoutDefaults.colorSecondary,
)
/**
* 56dp area at the bottom
*/
public fun DebugLayout.rowBottomNavigationBarArea(height: Dp = 56.dp): Unit = rowsFromBottom(
rows = 1.asRowColumnCount,
height = height,
color = DebugLayoutDefaults.colorTertiary,
)
/**
* Material 3, 0-599dp screen, 4 columns layout grid with 16dp gutters and margins
*/
public fun DebugLayout.extraSmallScreen4Columns(drawLayoutRegions: Boolean = false) {
columnsStretch(
columns = 4,
margin = 16.dp,
gutter = 16.dp,
color = DebugLayoutDefaults.colorPrimary,
)
if (drawLayoutRegions) {
rowTopToolbarArea()
rowBottomNavigationBarArea()
}
}
/**
* Material 3, Extra-small screen (0-599dp), 3 columns layout grid with 16dp margins and gutters
*/
public fun DebugLayout.extraSmallScreen3Columns(drawLayoutRegions: Boolean = false) {
columnsStretch(
columns = 3,
margin = 16.dp,
gutter = 16.dp,
color = DebugLayoutDefaults.colorPrimary,
)
if (drawLayoutRegions) {
rowTopToolbarArea()
rowBottomNavigationBarArea()
}
}
/**
* Material 3, Small screen (600-904dp), 8 columns layout grid with 32dp margins and gutters
*/
public fun DebugLayout.smallScreen8Columns(drawLayoutRegions: Boolean = false) {
if (!drawLayoutRegions) {
columnsStretch(
columns = 8,
margin = 32.dp,
gutter = 32.dp,
color = DebugLayoutDefaults.colorPrimary,
)
} else {
columnsFromRight(
columns = 8.asRowColumnCount,
columnWidth = 46.dp,
offset = 32.dp,
color = DebugLayoutDefaults.colorPrimary,
)
columnsFromLeft(
columns = 1.asRowColumnCount,
columnWidth = 72.dp,
offset = 0.dp,
color = DebugLayoutDefaults.colorTertiary,
)
rowTopToolbarArea()
}
}
/**
* Material 3, Medium screen (905-1239dp), 12 columns layout grid with 24dp margins and gutters
*/
public fun DebugLayout.mediumScreen12Columns(drawLayoutRegions: Boolean = false) {
if (!drawLayoutRegions) {
columnsStretch(
columns = 12,
margin = 24.dp,
gutter = 24.dp,
color = DebugLayoutDefaults.colorPrimary,
)
} else {
columnsFromRight(
columns = 12.asRowColumnCount,
columnWidth = 52.dp,
offset = 32.dp,
color = DebugLayoutDefaults.colorPrimary,
)
columnsFromLeft(
columns = 1.asRowColumnCount,
columnWidth = 72.dp,
offset = 0.dp,
color = DebugLayoutDefaults.colorTertiary,
)
rowTopToolbarArea()
}
}
/**
* Material 3, Medium screen (1240-1439dp), 12 columns layout grid with 24dp gutters and large margins
*/
public fun DebugLayout.mediumLaptopScreen12Columns(drawLayoutRegions: Boolean = false) {
columnsStretch(
columns = 12,
margin = 200.dp,
gutter = 24.dp,
color = DebugLayoutDefaults.colorPrimary,
)
if (drawLayoutRegions) {
columnsFromLeft(
columns = 1.asRowColumnCount,
columnWidth = 72.dp,
offset = 0.dp,
color = DebugLayoutDefaults.colorTertiary,
)
rowTopToolbarArea()
}
}
public enum class LargeLayoutRegions {
OFF, ON, EXPANDED
}
/**
* Material 3, Large screen (1440+dp), 12 columns layout grid with 24dp gutters
*/
public fun DebugLayout.largeScreen12Columns(layoutRegions: LargeLayoutRegions = LargeLayoutRegions.OFF) {
columnsFromCenter(
columns = 12.asRowColumnCount,
columnWidth = 72.dp,
gutter = 24.dp,
color = DebugLayoutDefaults.colorPrimary,
)
when (layoutRegions) {
OFF -> Unit
ON -> {
columnsFromLeft(
columns = 1.asRowColumnCount,
columnWidth = 72.dp,
offset = 0.dp,
color = DebugLayoutDefaults.colorTertiary,
)
rowTopToolbarArea()
}
EXPANDED -> {
columnsFromLeft(
columns = 1.asRowColumnCount,
columnWidth = 256.dp,
offset = 0.dp,
color = DebugLayoutDefaults.colorTertiary,
)
rowTopToolbarArea()
}
}
}