mirror of
https://github.com/BetterAndroid/FlexiUI.git
synced 2025-09-07 19:14:12 +08:00
refactor: separate colors from style
This commit is contained in:
@@ -28,14 +28,23 @@ import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import com.highcapable.flexiui.component.DesktopContextMenu
|
||||
import com.highcapable.flexiui.component.DesktopContextMenuRepresentation
|
||||
import com.highcapable.flexiui.component.LocalContextMenuColors
|
||||
import com.highcapable.flexiui.component.LocalContextMenuStyle
|
||||
import com.highcapable.flexiui.component.defaultContextMenuColors
|
||||
import com.highcapable.flexiui.component.defaultContextMenuStyle
|
||||
|
||||
@Composable
|
||||
internal actual fun FlexiThemeContent(content: @Composable () -> Unit) {
|
||||
CompositionLocalProvider(LocalContextMenuStyle provides defaultContextMenuStyle()) {
|
||||
CompositionLocalProvider(
|
||||
LocalContextMenuColors provides defaultContextMenuColors(),
|
||||
LocalContextMenuStyle provides defaultContextMenuStyle()
|
||||
) {
|
||||
CompositionLocalProvider(
|
||||
LocalContextMenuRepresentation provides DesktopContextMenuRepresentation(DesktopContextMenu.style),
|
||||
LocalContextMenuRepresentation provides
|
||||
DesktopContextMenuRepresentation(
|
||||
colors = DesktopContextMenu.colors,
|
||||
style = DesktopContextMenu.style
|
||||
),
|
||||
content = content
|
||||
)
|
||||
}
|
||||
|
@@ -69,14 +69,21 @@ import com.highcapable.flexiui.utils.orElse
|
||||
import java.awt.event.KeyEvent
|
||||
|
||||
@Immutable
|
||||
data class ContextMenuStyle(
|
||||
data class ContextMenuColors(
|
||||
val contentColor: Color,
|
||||
val borderColor: Color,
|
||||
val borderColor: Color
|
||||
)
|
||||
|
||||
@Immutable
|
||||
data class ContextMenuStyle(
|
||||
val contentStyle: AreaBoxStyle?,
|
||||
val borderStyle: AreaBoxStyle?
|
||||
)
|
||||
|
||||
internal class DesktopContextMenuRepresentation(private val style: ContextMenuStyle) : ContextMenuRepresentation {
|
||||
internal class DesktopContextMenuRepresentation(
|
||||
private val colors: ContextMenuColors,
|
||||
private val style: ContextMenuStyle
|
||||
) : ContextMenuRepresentation {
|
||||
@OptIn(ExperimentalComposeUiApi::class)
|
||||
@Composable
|
||||
override fun Representation(state: ContextMenuState, items: () -> List<ContextMenuItem>) {
|
||||
@@ -112,7 +119,7 @@ internal class DesktopContextMenuRepresentation(private val style: ContextMenuSt
|
||||
modifier = Modifier
|
||||
.width(IntrinsicSize.Max)
|
||||
.verticalScroll(rememberScrollState()),
|
||||
color = style.borderColor,
|
||||
color = colors.borderColor,
|
||||
style = borderStyle
|
||||
) {
|
||||
items().forEach { item ->
|
||||
@@ -122,7 +129,7 @@ internal class DesktopContextMenuRepresentation(private val style: ContextMenuSt
|
||||
state.status = ContextMenuState.Status.Closed
|
||||
item.onClick()
|
||||
}
|
||||
) { Text(text = item.label, color = style.contentColor) }
|
||||
) { Text(text = item.label, color = colors.contentColor) }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -166,26 +173,40 @@ private fun Modifier.onHover(onHover: (Boolean) -> Unit) = pointerInput(Unit) {
|
||||
}
|
||||
|
||||
object DesktopContextMenu {
|
||||
val colors: ContextMenuColors
|
||||
@Composable
|
||||
@ReadOnlyComposable
|
||||
get() = LocalContextMenuColors.current
|
||||
val style: ContextMenuStyle
|
||||
@Composable
|
||||
@ReadOnlyComposable
|
||||
get() = LocalContextMenuStyle.current
|
||||
}
|
||||
|
||||
val LocalContextMenuColors = compositionLocalOf {
|
||||
ContextMenuColors(
|
||||
borderColor = Color.Unspecified,
|
||||
contentColor = Color.Unspecified
|
||||
)
|
||||
}
|
||||
|
||||
val LocalContextMenuStyle = compositionLocalOf {
|
||||
ContextMenuStyle(
|
||||
borderColor = Color.Unspecified,
|
||||
contentColor = Color.Unspecified,
|
||||
contentStyle = null,
|
||||
borderStyle = null
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
@ReadOnlyComposable
|
||||
internal fun defaultContextMenuColors() = ContextMenuColors(
|
||||
contentColor = LocalContextMenuColors.current.contentColor.orElse() ?: LocalColors.current.textPrimary,
|
||||
borderColor = LocalContextMenuColors.current.borderColor.orElse() ?: AreaBox.color
|
||||
)
|
||||
|
||||
@Composable
|
||||
@ReadOnlyComposable
|
||||
internal fun defaultContextMenuStyle() = ContextMenuStyle(
|
||||
contentColor = LocalContextMenuStyle.current.contentColor.orElse() ?: LocalColors.current.textPrimary,
|
||||
borderColor = LocalContextMenuStyle.current.borderColor.orElse() ?: AreaBox.color,
|
||||
contentStyle = LocalContextMenuStyle.current.contentStyle ?: AreaBox.style.copy(
|
||||
padding = 0.dp,
|
||||
startPadding = DefaultDesktopContextMenuContentPadding,
|
||||
|
Reference in New Issue
Block a user