Skip to content

Commit 6b90464

Browse files
optimize: RatioBtn
1 parent 6ea96a4 commit 6b90464

1 file changed

Lines changed: 67 additions & 62 deletions

File tree

  • composeApp/src/commonMain/kotlin/com/corner/ui/scene

composeApp/src/commonMain/kotlin/com/corner/ui/scene/ChooseItem.kt

Lines changed: 67 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -33,73 +33,78 @@ fun RatioBtn(
3333
tag: () -> Pair<Boolean, String> = { false to "" },
3434
enableTooltip: Boolean = true
3535
) {
36-
TooltipArea(
37-
tooltip = {
38-
// composable tooltip content
39-
Surface(
40-
modifier = Modifier.shadow(4.dp),
41-
color = MaterialTheme.colorScheme.surface,
36+
if (enableTooltip) {
37+
TooltipArea(
38+
tooltip = {
39+
// composable tooltip content
40+
Surface(
41+
modifier = Modifier.shadow(4.dp),
42+
color = MaterialTheme.colorScheme.surface,
43+
shape = RoundedCornerShape(4.dp)
44+
) {
45+
Text(
46+
text = text,
47+
modifier = Modifier.padding(10.dp),
48+
color = MaterialTheme.colorScheme.onSurface,
49+
)
50+
}
51+
}, delayMillis = 600
52+
) {
53+
ratioBtnContent(modifier, selected, onClick, loading, text, tag)
54+
}
55+
} else {
56+
ratioBtnContent(modifier, selected, onClick, loading, text, tag)
57+
}
58+
}
59+
60+
@Composable
61+
private fun ratioBtnContent(
62+
modifier: Modifier,
63+
selected: Boolean,
64+
onClick: () -> Unit,
65+
loading: Boolean,
66+
text: String,
67+
tag: () -> Pair<Boolean, String>
68+
) {
69+
Surface(
70+
border = BorderStroke(1.dp, Color.Gray.copy(0.6F)),
71+
shape = RoundedCornerShape(6.dp),
72+
modifier = modifier.shadow(1.dp).background(
73+
if (selected) MaterialTheme.colorScheme.secondary else Color.Transparent,
4274
shape = RoundedCornerShape(4.dp)
43-
) {
44-
Text(
45-
text = if(enableTooltip) "" else text,
46-
modifier = Modifier.padding(10.dp),
47-
color = MaterialTheme.colorScheme.onSurface,
48-
)
49-
}
50-
},
51-
delayMillis = 600
75+
).clickable(
76+
onClick = { onClick() }, enabled = !loading
77+
),
5278
) {
53-
Surface(
54-
border = BorderStroke(1.dp, Color.Gray.copy(0.6F)),
55-
shape = RoundedCornerShape(6.dp),
56-
modifier = modifier
57-
.shadow(1.dp)
58-
.background(
59-
if (selected) MaterialTheme.colorScheme.secondary else Color.Transparent,
60-
shape = RoundedCornerShape(4.dp)
79+
Box() {
80+
Text(
81+
text,
82+
modifier = Modifier.background(if (selected) MaterialTheme.colorScheme.secondary else Color.Transparent)
83+
.fillMaxWidth().padding(vertical = 8.dp, horizontal = 10.dp),
84+
color = if (selected) MaterialTheme.colorScheme.onSecondary else Color.White,
85+
maxLines = 1,
86+
overflow = TextOverflow.Ellipsis,
87+
textAlign = TextAlign.Center
88+
)
89+
if (loading) {
90+
CircularProgressIndicator(
91+
modifier = Modifier.align(Alignment.CenterStart).padding(1.dp),
92+
color = Color.White,
93+
trackColor = Color.Gray
6194
)
62-
.clickable(
63-
onClick = { onClick() },
64-
enabled = !loading
65-
),
66-
) {
67-
Box() {
95+
}
96+
97+
val tags = remember { tag() }
98+
if (tags.first) {
6899
Text(
69-
text,
70-
modifier = Modifier.background(if (selected) MaterialTheme.colorScheme.secondary else Color.Transparent)
71-
.fillMaxWidth()
72-
.padding(vertical = 8.dp, horizontal = 10.dp),
73-
color = if (selected) MaterialTheme.colorScheme.onSecondary else Color.White,
74-
maxLines = 1,
75-
overflow = TextOverflow.Ellipsis,
76-
textAlign = TextAlign.Center
100+
tags.second,
101+
Modifier.background(
102+
if (selected) MaterialTheme.colorScheme.onSecondary else MaterialTheme.colorScheme.secondary /*if (selected) Color.Blue.copy(0.5f) else MaterialTheme.colorScheme.onSecondary*/,
103+
shape = RoundedCornerShape(0.dp, 6.dp, 0.dp, 6.dp)
104+
).align(Alignment.TopEnd).border(1.dp, Color.Gray).padding(3.dp),
105+
maxLines = 1, overflow = TextOverflow.Ellipsis,
106+
color = if (selected) Color.White else MaterialTheme.colorScheme.onSecondary, /*if(selected) Color.Black else Color.White*/
77107
)
78-
if (loading) {
79-
CircularProgressIndicator(
80-
modifier = Modifier
81-
.align(Alignment.CenterStart)
82-
.padding(1.dp),
83-
color = Color.White,
84-
trackColor = Color.Gray
85-
)
86-
}
87-
88-
val tags = remember { tag() }
89-
if (tags.first) {
90-
Text(
91-
tags.second,
92-
Modifier.background(
93-
if (selected) MaterialTheme.colorScheme.onSecondary else MaterialTheme.colorScheme.secondary /*if (selected) Color.Blue.copy(0.5f) else MaterialTheme.colorScheme.onSecondary*/,
94-
shape = RoundedCornerShape(0.dp, 6.dp, 0.dp, 6.dp)
95-
)
96-
.align(Alignment.TopEnd)
97-
.border(1.dp, Color.Gray)
98-
.padding(3.dp),
99-
maxLines = 1, overflow = TextOverflow.Ellipsis,
100-
color = if (selected) Color.White else MaterialTheme.colorScheme.onSecondary, /*if(selected) Color.Black else Color.White*/
101-
)
102-
}
103108
}
104109
}
105110
}

0 commit comments

Comments
 (0)