@@ -2178,6 +2178,32 @@ internal open class Measurer : BasicMeasure.Measurer, DesignInfoProvider {
2178
2178
2179
2179
private var designElements = arrayListOf<DesignElement >()
2180
2180
2181
+
2182
+ private fun getColor (str : String? , defaultColor : Color = Color .Black ) : Color {
2183
+ if (str != null && str.startsWith(' #' )) {
2184
+ var str2 = str.substring(1 )
2185
+ if (str2.length == 6 ) {
2186
+ str2 = " FF$str2 "
2187
+ }
2188
+ try {
2189
+ return Color (java.lang.Long .parseLong(str2, 16 ).toInt())
2190
+ } catch (e: Exception ) {
2191
+ return defaultColor
2192
+ }
2193
+ }
2194
+ return defaultColor
2195
+ }
2196
+
2197
+ private fun getTextStyle (params : HashMap <String , String >) : TextStyle {
2198
+ val fontSizeString = params[" size" ]
2199
+ var fontSize = TextUnit .Unspecified
2200
+ if (fontSizeString != null ) {
2201
+ fontSize = fontSizeString.toFloat().sp
2202
+ }
2203
+ var textColor = getColor(params[" color" ])
2204
+ return TextStyle (fontSize = fontSize, color = textColor)
2205
+ }
2206
+
2181
2207
@Composable
2182
2208
fun createDesignElements () {
2183
2209
for (element in designElements) {
@@ -2189,29 +2215,28 @@ internal open class Measurer : BasicMeasure.Measurer, DesignInfoProvider {
2189
2215
when (element.type) {
2190
2216
" button" -> {
2191
2217
val text = element.params[" text" ] ? : " text"
2192
- var style = TextStyle .Default
2193
- val fontSizeString = element.params[" size" ]
2194
- if (fontSizeString != null ) {
2195
- val fontSize = fontSizeString.toFloat().sp
2196
- style = TextStyle (fontSize = fontSize)
2197
- }
2218
+ val colorBackground = getColor(element.params[" backgroundColor" ], Color .LightGray )
2198
2219
BasicText (modifier = Modifier
2199
2220
.layoutId(id)
2200
2221
.clip(RoundedCornerShape (20 ))
2201
- .background(Color . LightGray )
2222
+ .background(colorBackground )
2202
2223
.padding(8 .dp),
2203
- text = text, style = style)
2224
+ text = text, style = getTextStyle(element.params))
2225
+ }
2226
+ " box" -> {
2227
+ val text = element.params[" text" ] ? : " "
2228
+ val colorBackground = getColor(element.params[" backgroundColor" ], Color .LightGray )
2229
+ Box (modifier = Modifier .layoutId(id).background(colorBackground)) {
2230
+ BasicText (
2231
+ modifier = Modifier .padding(8 .dp),
2232
+ text = text, style = getTextStyle(element.params)
2233
+ )
2234
+ }
2204
2235
}
2205
2236
" text" -> {
2206
2237
val text = element.params[" text" ] ? : " text"
2207
- var style = TextStyle .Default
2208
- val fontSizeString = element.params[" size" ]
2209
- if (fontSizeString != null ) {
2210
- val fontSize = fontSizeString.toFloat().sp
2211
- style = TextStyle (fontSize = fontSize)
2212
- }
2213
2238
BasicText (modifier = Modifier .layoutId(id),
2214
- text = text, style = style )
2239
+ text = text, style = getTextStyle(element.params) )
2215
2240
}
2216
2241
" textfield" -> {
2217
2242
val text = element.params[" text" ] ? : " text"
0 commit comments