Skip to content

Commit feb44e1

Browse files
committed
[gallery] use FontIcon in Gallery.
1 parent 97e43c5 commit feb44e1

File tree

12 files changed

+127
-143
lines changed

12 files changed

+127
-143
lines changed

gallery-processor/src/jvmMain/kotlin/com/konyaco/fluent/gallery/processor/ComponentProcessor.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ class ComponentProcessor(private val logger: KSPLogger, private val codeGenerato
162162
fileSpecBuilder.addImport(iconImportPrefix, this)
163163
"$iconPrefix.$this"
164164
},
165+
iconGlyph = componentGroupConfig.iconGlyph,
165166
content = componentGroupConfig.contentData,
166167
items = createItemsString(
167168
itemName,
@@ -259,11 +260,13 @@ class ComponentProcessor(private val logger: KSPLogger, private val codeGenerato
259260
var nameArg: KSValueArgument? = null
260261
var descriptionArg: KSValueArgument? = null
261262
var icon: String? = null
263+
var iconGlyph: Char? = null
262264
annotation.arguments.forEach {
263265
when (it.name?.asString()) {
264266
"name" -> nameArg = it
265267
"description" -> descriptionArg = it
266268
"icon" -> icon = (it.value as? String)?.ifBlank { null }
269+
"iconGlyph" -> iconGlyph = (it.value as? Char)?.takeIf { char -> char != 'A' }
267270
}
268271
}
269272
val description = descriptionArg?.value as? String ?: ""
@@ -312,6 +315,7 @@ class ComponentProcessor(private val logger: KSPLogger, private val codeGenerato
312315
fileSpec.addImport(iconImportPrefix, this)
313316
"$iconPrefix.$this"
314317
},
318+
iconGlyph = iconGlyph,
315319
items = null,
316320
getItem = { it }
317321
)
@@ -327,6 +331,7 @@ class ComponentProcessor(private val logger: KSPLogger, private val codeGenerato
327331
description: String,
328332
content: String?,
329333
icon: String?,
334+
iconGlyph: Char?,
330335
items: List<T>?,
331336
getItem: (T) -> String,
332337
) = CodeBlock.builder()
@@ -337,6 +342,7 @@ class ComponentProcessor(private val logger: KSPLogger, private val codeGenerato
337342
addStatement("description = %S,", description)
338343
addStatement("content = $content,")
339344
addStatement("icon = $icon,")
345+
addStatement("iconGlyph = ${iconGlyph?.let { "'$it'" }},")
340346
if (items != null) {
341347
createList("items = ", items, getItem)
342348
} else {
@@ -348,11 +354,13 @@ class ComponentProcessor(private val logger: KSPLogger, private val codeGenerato
348354

349355
private fun generateComponentGroupConfig(group: String): ComponentGroupConfig {
350356
var icon: String? = null
357+
var iconGlyph: Char? = null
351358
var contentData: String? = null
352359
componentGroups[group]?.let { (annotation) ->
353360
annotation.arguments.forEach {
354361
when (it.name?.asString()) {
355362
"icon" -> icon = (it.value as? String)?.ifBlank { null }
363+
"iconGlyph" -> iconGlyph = (it.value as? Char).takeIf { char -> char != 'A' }
356364
"generateScreen" -> if (it.value as? Boolean == true) {
357365
contentData = """
358366
{ ComponentIndexScreen(it) }
@@ -361,7 +369,7 @@ class ComponentProcessor(private val logger: KSPLogger, private val codeGenerato
361369
}
362370
}
363371
}
364-
return ComponentGroupConfig(icon, contentData)
372+
return ComponentGroupConfig(icon, iconGlyph, contentData)
365373
}
366374

367375
private fun PropertySpec.Builder.lazy(buildAction: CodeBlock.Builder.() -> Unit) = delegate(
@@ -395,6 +403,7 @@ class ComponentProcessor(private val logger: KSPLogger, private val codeGenerato
395403

396404
data class ComponentGroupConfig(
397405
val icon: String?,
406+
val iconGlyph: Char?,
398407
val contentData: String?
399408
)
400409
}

gallery/src/commonMain/kotlin/com/konyaco/fluent/gallery/App.kt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import com.konyaco.fluent.component.TextBoxButtonDefaults
4343
import com.konyaco.fluent.component.TextField
4444
import com.konyaco.fluent.gallery.component.ComponentItem
4545
import com.konyaco.fluent.gallery.component.ComponentNavigator
46+
import com.konyaco.fluent.gallery.component.FontIcon
4647
import com.konyaco.fluent.gallery.component.components
4748
import com.konyaco.fluent.gallery.component.rememberComponentNavigator
4849
import com.konyaco.fluent.gallery.component.flatMapComponents
@@ -214,7 +215,13 @@ private fun NavigationItem(
214215
onSelectedItemChanged(navItem)
215216
expandedItems.value = !expandedItems.value
216217
},
217-
icon = navItem.icon?.let { { Icon(it, navItem.name) } },
218+
icon = navItem.icon?.let { {
219+
if (navItem.iconGlyph != null) {
220+
FontIcon(navItem.iconGlyph, navItem.icon, navItem.name)
221+
} else {
222+
Icon(it, navItem.name)
223+
}
224+
} },
218225
content = { Text(navItem.name) },
219226
expandItems = expandedItems.value,
220227
items = navItem.items?.let {
@@ -235,4 +242,4 @@ private fun NavigationItem(
235242
)
236243
}
237244

238-
private val settingItem = ComponentItem("Settings", group = "", description = "", icon = Icons.Default.Settings) { SettingsScreen() }
245+
private val settingItem = ComponentItem("Settings", group = "", description = "", icon = Icons.Default.Settings, iconGlyph = '\uE713') { SettingsScreen() }

gallery/src/commonMain/kotlin/com/konyaco/fluent/gallery/annotation/Component.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package com.konyaco.fluent.gallery.annotation
44
annotation class Component(
55
val name: String = "",
66
val icon: String = "",
7+
val iconGlyph: Char = 'A',
78
val description: String = "",
89
val group: String = "_Auto",
910
val index: Int = -1,

gallery/src/commonMain/kotlin/com/konyaco/fluent/gallery/annotation/ComponentGroup.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.konyaco.fluent.gallery.annotation
33
@Target(AnnotationTarget.PROPERTY)
44
annotation class ComponentGroup(
55
val icon: String,
6+
val iconGlyph: Char = 'A',
67
val index: Int = Int.MAX_VALUE,
78
val generateScreen: Boolean = true,
89
val packageMap: String = ""

gallery/src/commonMain/kotlin/com/konyaco/fluent/gallery/component/ComponentGroupInfo.kt

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,54 +8,54 @@ object ComponentGroupInfo {
88

99
private const val screenPackage: String = "com.konyaco.fluent.gallery.screen"
1010

11-
@ComponentGroup("Ruler", index = 0, generateScreen = false, packageMap = "$screenPackage.design")
11+
@ComponentGroup("Ruler", iconGlyph = '\uEB3C', index = 0, generateScreen = false, packageMap = "$screenPackage.design")
1212
const val DesignGuidance = "Design guidance"
1313

14-
@ComponentGroup("Accessibility", generateScreen = false, index = 3)
14+
@ComponentGroup("Accessibility", iconGlyph = '\uE776', generateScreen = false, index = 3)
1515
const val Accessibility = "Design guidance/Accessibility"
1616

17-
@ComponentGroup("CheckboxChecked", index = 2, packageMap = "$screenPackage.basicinput")
17+
@ComponentGroup("CheckboxChecked", iconGlyph = '\uE73A', index = 2, packageMap = "$screenPackage.basicinput")
1818
const val BasicInput = "Basic input"
1919

20-
@ComponentGroup("Table", index = 3, packageMap = "$screenPackage.collections")
20+
@ComponentGroup("Table", iconGlyph = '\uE80A', index = 3, packageMap = "$screenPackage.collections")
2121
const val Collections = "Collections"
2222

23-
@ComponentGroup("CalendarClock", index = 4, packageMap = "$screenPackage.datetime")
23+
@ComponentGroup("CalendarClock", iconGlyph = '\uEC92', index = 4, packageMap = "$screenPackage.datetime")
2424
const val DateAndTime = "Date & time"
2525

26-
@ComponentGroup("Chat", index = 5, packageMap = "$screenPackage.dialogs")
26+
@ComponentGroup("Chat", iconGlyph = '\uE8BD', index = 5, packageMap = "$screenPackage.dialogs")
2727
const val DialogAndFlyout = "Dialog & flyouts"
2828

29-
@ComponentGroup("SlideLayout", index = 6)
29+
@ComponentGroup("SlideLayout", iconGlyph = '\uE8A1', index = 6)
3030
const val Layout = "Layout"
3131

32-
@ComponentGroup("VideoClip", index = 7)
32+
@ComponentGroup("VideoClip", iconGlyph = '\uE786', index = 7)
3333
const val Media = "Media"
3434

35-
@ComponentGroup("Save", index = 8)
35+
@ComponentGroup("Save", iconGlyph = '\uE74E', index = 8)
3636
const val MenusAndToolbars = "Menus & toolbars"
3737

38-
@ComponentGroup("Flash", index = 9)
38+
@ComponentGroup("Flash", iconGlyph = '\uE945', index = 9)
3939
const val Motion = "Motion"
4040

41-
@ComponentGroup("Navigation", index = 10, packageMap = "$screenPackage.navigation")
41+
@ComponentGroup("Navigation", iconGlyph = '\uE700', index = 10, packageMap = "$screenPackage.navigation")
4242
const val Navigation = "Navigation"
4343

44-
@ComponentGroup("ArrowSort", index = 11)
44+
@ComponentGroup("ArrowSort", iconGlyph = '\uE174', index = 11)
4545
const val Scrolling = "Scrolling"
4646

47-
@ComponentGroup("ChatMultiple", index = 12, packageMap = "$screenPackage.status")
47+
@ComponentGroup("ChatMultiple", iconGlyph = '\uE8F2', index = 12, packageMap = "$screenPackage.status")
4848
const val StatusAndInfo = "Status & info"
4949

50-
@ComponentGroup("Color", index = 13, packageMap = "$screenPackage.styles")
50+
@ComponentGroup("Color", iconGlyph = '\uE2B1', index = 13, packageMap = "$screenPackage.styles")
5151
const val Styles = "Styles"
5252

53-
@ComponentGroup("System", index = 14)
53+
@ComponentGroup("System", iconGlyph = '\uE770', index = 14)
5454
const val System = "System"
5555

56-
@ComponentGroup("TextFont", index = 15, packageMap = "$screenPackage.text")
56+
@ComponentGroup("TextFont", iconGlyph = '\uE8D2', index = 15, packageMap = "$screenPackage.text")
5757
const val Text = "Text"
5858

59-
@ComponentGroup("Window", index = 16)
59+
@ComponentGroup("Window", iconGlyph = '\uE7C4', index = 16)
6060
const val Windowing = "Windowing"
6161
}

gallery/src/commonMain/kotlin/com/konyaco/fluent/gallery/component/ComponentItem.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ class ComponentItem(
99
val description: String,
1010
val items: List<ComponentItem>? = null,
1111
val icon: ImageVector? = null,
12+
val iconGlyph: Char? = null,
1213
val content: (@Composable ComponentItem.(navigator: ComponentNavigator) -> Unit)?
1314
)

gallery/src/commonMain/kotlin/com/konyaco/fluent/gallery/component/CopyButton.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import androidx.compose.ui.Modifier
1111
import androidx.compose.ui.platform.LocalClipboardManager
1212
import androidx.compose.ui.text.AnnotatedString
1313
import com.konyaco.fluent.component.Button
14-
import com.konyaco.fluent.component.Icon
1514
import com.konyaco.fluent.icons.Icons
1615
import com.konyaco.fluent.icons.regular.Checkmark
1716
import com.konyaco.fluent.icons.regular.Copy
@@ -39,9 +38,9 @@ fun CopyButton(
3938
content = {
4039
AnimatedContent(isCopy) { target ->
4140
if (target) {
42-
Icon(Icons.Default.Checkmark, contentDescription = null)
41+
FontIcon('\uE73E', Icons.Default.Checkmark, contentDescription = null)
4342
} else {
44-
Icon(Icons.Default.Copy, contentDescription = null)
43+
FontIcon('\uE8C8', Icons.Default.Copy, contentDescription = null)
4544
}
4645
}
4746
},

gallery/src/commonMain/kotlin/com/konyaco/fluent/gallery/component/GalleryHeader.kt

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,11 @@ fun GalleryHeader(
9797
uriHandler.openUri(ProjectUrl.documentationOf(documentPath))
9898
},
9999
content = {
100-
Icon(
101-
Icons.Default.Document,
100+
FontIcon(
101+
glyph = '\uE8A5',
102+
vector = Icons.Default.Document,
102103
contentDescription = null,
103-
modifier = Modifier.size(18.dp)
104+
vectorSize = 18.dp
104105
)
105106
Text("Documentation")
106107
}
@@ -153,10 +154,11 @@ fun GalleryHeader(
153154
checked = themeButtonChecked,
154155
onCheckedChanged = onThemeButtonChanged,
155156
content = {
156-
Icon(
157-
Icons.Filled.BrightnessHigh,
157+
FontIcon(
158+
glyph = '\uE793',
159+
vector = Icons.Filled.BrightnessHigh,
158160
contentDescription = null,
159-
modifier = Modifier.size(18.dp)
161+
vectorSize = 18.dp
160162
)
161163
},
162164
iconOnly = true,
@@ -169,10 +171,11 @@ fun GalleryHeader(
169171
Button(
170172
onClick = { uriHandler.openUri(ProjectUrl.FEED_BACK) },
171173
content = {
172-
Icon(
173-
Icons.Default.PersonFeedback,
174+
FontIcon(
175+
glyph = '\uED15',
176+
vector = Icons.Default.PersonFeedback,
174177
contentDescription = null,
175-
modifier = Modifier.size(18.dp)
178+
vectorSize = 18.dp
176179
)
177180
},
178181
iconOnly = true,

gallery/src/commonMain/kotlin/com/konyaco/fluent/gallery/screen/AllSamplesScreen.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import com.konyaco.fluent.gallery.component.*
66
import com.konyaco.fluent.gallery.component._AllSamplesScreenComponent
77
import com.konyaco.fluent.gallery.component._HomeScreenComponent
88

9-
@Component(icon = "AppsList", index = 1, name = "All samples")
9+
@Component(icon = "AppsList", iconGlyph = '\uE71D', index = 1, name = "All samples")
1010
@Composable
1111
fun AllSamplesScreen(navigator: ComponentNavigator) {
1212
var allComponents by remember {

0 commit comments

Comments
 (0)