Skip to content

Commit

Permalink
💄 Implementing a reusable window decoration bar (#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
guiyanakuang committed Nov 29, 2023
1 parent 9cc39b8 commit e495fb4
Show file tree
Hide file tree
Showing 9 changed files with 211 additions and 37 deletions.
45 changes: 22 additions & 23 deletions composeApp/src/commonMain/kotlin/com/clipevery/ClipeveryApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ import androidx.compose.foundation.layout.wrapContentWidth
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Icon
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
Expand All @@ -31,8 +32,9 @@ import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.graphics.toComposeImageBitmap
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.clipevery.ui.TabsUI
import com.clipevery.ui.TitleUI
import com.clipevery.ui.AboutUI
import com.clipevery.ui.HomeUI
import com.clipevery.ui.SettingsUI
import compose.icons.TablerIcons
import compose.icons.tablericons.Scan
import org.koin.core.KoinApplication
Expand Down Expand Up @@ -61,30 +63,23 @@ fun ClipeveryCommon(koinApplication: KoinApplication) {

@Composable
fun ClipeveryWithProvidedDependencies() {
CustomWindowDecoration()
TabsUI()

}

@Composable
fun CustomWindowDecoration() {
Surface(
modifier = Modifier
.fillMaxWidth()
.height(62.dp),
color = MaterialTheme.colors.background,
shape = RoundedCornerShape(
topStart = 10.dp,
topEnd = 10.dp,
bottomEnd = 0.dp,
bottomStart = 0.dp
)
) {
TitleUI()
val currentPage = remember { mutableStateOf(PageType.HOME) }
when (currentPage.value) {
PageType.HOME -> {
HomeUI(currentPage)
}
PageType.SETTINGS -> {
SettingsUI(currentPage)
}
PageType.ABOUT -> {
AboutUI(currentPage)
}
}
}




@Preview
@Composable
fun ColumTest() {
Expand Down Expand Up @@ -138,4 +133,8 @@ fun loadImageBitmap(resourcePath: String): ImageBitmap {
Thread.currentThread().contextClassLoader.getResourceAsStream(resourcePath)
?.readBytes()!!)
return image.toComposeImageBitmap()
}

enum class PageType {
HOME, SETTINGS, ABOUT
}
19 changes: 19 additions & 0 deletions composeApp/src/commonMain/kotlin/com/clipevery/ui/AboutUI.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.clipevery.ui

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.ui.Modifier
import com.clipevery.PageType

@Composable
fun AboutUI(currentPage: MutableState<PageType>) {
WindowDecoration(currentPage, "About")
AboutContentUI()
}

@Composable
fun AboutContentUI() {
Column(modifier = Modifier.fillMaxSize()) { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
Expand All @@ -24,8 +25,11 @@ import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Divider
import androidx.compose.material.Icon
import androidx.compose.material.IconButton
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
Expand All @@ -48,17 +52,44 @@ import androidx.compose.ui.unit.sp
import androidx.compose.ui.unit.toSize
import androidx.compose.ui.window.Popup
import com.clipevery.LocalKoinApplication
import com.clipevery.PageType
import com.clipevery.i18n.GlobalCopywriter
import com.clipevery.loadImageBitmap
import compose.icons.TablerIcons
import compose.icons.tablericons.Settings
import java.awt.Desktop
import java.net.URI
import kotlin.math.roundToInt
import kotlin.system.exitProcess

@Composable
fun HomeUI(currentPage: MutableState<PageType>) {
HomeWindowDecoration(currentPage)
TabsUI()
}

@Composable
fun HomeWindowDecoration(currentPage: MutableState<PageType>) {
Surface(
modifier = Modifier
.fillMaxWidth()
.height(62.dp),
color = MaterialTheme.colors.background,
shape = RoundedCornerShape(
topStart = 10.dp,
topEnd = 10.dp,
bottomEnd = 0.dp,
bottomStart = 0.dp
)
) {
TitleUI(currentPage)
}
}


@Preview
@Composable
fun TitleUI() {
fun TitleUI(currentPage: MutableState<PageType>) {
val current = LocalKoinApplication.current
val copywriter = current.koin.get<GlobalCopywriter>()
var showPopup by remember { mutableStateOf(false) }
Expand Down Expand Up @@ -94,7 +125,7 @@ fun TitleUI() {
.clip(RoundedCornerShape(3.dp))
.size(36.dp),
bitmap = loadImageBitmap("clipevery_icon.png"),
contentDescription = "QR Code",
contentDescription = "clipevery icon",
)
Column(Modifier.wrapContentWidth()
.align(Alignment.CenterVertically)
Expand Down Expand Up @@ -169,27 +200,23 @@ fun TitleUI() {
.clip(RoundedCornerShape(5.dp))
.background(Color.White)
) {
// 菜单项1
MenuItem(copywriter.getText("Check_for_updates")) {
println("菜单项1 被点击")
// TODO: check for updates
showPopup = false
}
// 菜单项2
MenuItem(copywriter.getText("Settings")) {
println("菜单项2 被点击")
currentPage.value = PageType.SETTINGS
showPopup = false
}
// 菜单项3
MenuItem(copywriter.getText("About")) {
println("菜单项3 被点击")
currentPage.value = PageType.ABOUT
showPopup = false
}
MenuItem(copywriter.getText("FQA")) {
println("菜单项3 被点击")
Desktop.getDesktop().browse(URI("https://www.clipevery.com/FQA"))
showPopup = false
}
Divider()
// 菜单项4
MenuItem(copywriter.getText("Quit")) {
showPopup = false
exitProcess(0)
Expand Down
19 changes: 19 additions & 0 deletions composeApp/src/commonMain/kotlin/com/clipevery/ui/SettingsUI.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.clipevery.ui

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.ui.Modifier
import com.clipevery.PageType

@Composable
fun SettingsUI(currentPage: MutableState<PageType>) {
WindowDecoration(currentPage, "Settings")
SettingsContentUI()
}

@Composable
fun SettingsContentUI() {
Column(modifier = Modifier.fillMaxSize()) { }
}
106 changes: 106 additions & 0 deletions composeApp/src/commonMain/kotlin/com/clipevery/ui/WindowDecoration.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package com.clipevery.ui

import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.wrapContentWidth
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.platform.Font
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.clipevery.LocalKoinApplication
import com.clipevery.PageType
import com.clipevery.i18n.GlobalCopywriter

@Composable
fun WindowDecoration(currentPage: MutableState<PageType>, title: String) {
Surface(
modifier = Modifier
.fillMaxWidth()
.height(62.dp),
color = MaterialTheme.colors.background,
shape = RoundedCornerShape(
topStart = 10.dp,
topEnd = 10.dp,
bottomEnd = 0.dp,
bottomStart = 0.dp
)
) {
DecorationUI(currentPage, title)
}
}

@Composable
fun DecorationUI(currentPage: MutableState<PageType>, title: String) {
val current = LocalKoinApplication.current
val copywriter = current.koin.get<GlobalCopywriter>()

val customFontFamily = FontFamily(
Font(resource = "font/BebasNeue.otf", FontWeight.Normal)
)

Box(
modifier = Modifier.background(Color.Black)
.background(
brush = Brush.verticalGradient(
colors = listOf(
Color.White.copy(alpha = 0.6f),
Color.Transparent
),
startY = 0.0f,
endY = 3.0f
)
),
) {
Row(modifier = Modifier.align(Alignment.CenterStart)
.wrapContentWidth(),
horizontalArrangement = Arrangement.Center) {
Column(Modifier.weight(0.5f)
.align(Alignment.CenterVertically)
.offset(y = 2.dp),
horizontalAlignment = Alignment.CenterHorizontally) {
Text(
modifier = Modifier.padding(16.dp)
.align(Alignment.Start)
.clickable { currentPage.value = PageType.HOME },
text = "${copywriter.getText("Return")}",
color = Color(0xFF70b0f3),
fontWeight = FontWeight.Light
)
}
Column(Modifier.weight(0.5f)
.align(Alignment.CenterVertically),
horizontalAlignment = Alignment.CenterHorizontally) {
Text(
modifier = Modifier.padding(16.dp)
.align(Alignment.End),
text = copywriter.getText(title),
color = Color.White,
fontSize = 25.sp,
style = TextStyle(fontWeight = FontWeight.Bold),
fontFamily = customFontFamily
)
}

}
}
}
3 changes: 2 additions & 1 deletion composeApp/src/desktopMain/resources/i18n/en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ Check_for_updates=Check for updates
Settings=Settings
About=About
FQA=FQA↗
Quit=Quit
Quit=Quit
Return=Return
3 changes: 2 additions & 1 deletion composeApp/src/desktopMain/resources/i18n/es.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ Check_for_updates=Buscar actualizaciones
Settings=Ajustes
About=Información
FQA=Preguntas frecuentes↗
Quit=Salir
Quit=Salir
Return=Volver
3 changes: 2 additions & 1 deletion composeApp/src/desktopMain/resources/i18n/jp.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ Check_for_updates=更新を確認
Settings=設定
About=情報
FQA=よくある問題↗
Quit=終了
Quit=終了
Return=戻る
3 changes: 2 additions & 1 deletion composeApp/src/desktopMain/resources/i18n/zh.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ Check_for_updates=检查更新
Settings=设置
About=关于
FQA=常见问题↗
Quit=退出
Quit=退出
Return=返回

0 comments on commit e495fb4

Please sign in to comment.