|
| 1 | +package com.kdroid.composetray.demo |
| 2 | + |
| 3 | +import androidx.compose.foundation.Image |
| 4 | +import androidx.compose.foundation.layout.fillMaxSize |
| 5 | +import androidx.compose.runtime.getValue |
| 6 | +import androidx.compose.runtime.mutableStateOf |
| 7 | +import androidx.compose.runtime.remember |
| 8 | +import androidx.compose.runtime.setValue |
| 9 | +import androidx.compose.ui.Modifier |
| 10 | +import androidx.compose.ui.window.Window |
| 11 | +import androidx.compose.ui.window.application |
| 12 | +import com.kdroid.composetray.tray.api.Tray |
| 13 | +import composenativetray.demo.generated.resources.Res |
| 14 | +import composenativetray.demo.generated.resources.icon |
| 15 | +import org.jetbrains.compose.resources.painterResource |
| 16 | + |
| 17 | +/** |
| 18 | + * UnicodeTrayDemo |
| 19 | + * |
| 20 | + * Demonstrates a tray menu with French and Chinese items, including special |
| 21 | + * characters like accented letters (é, à, ç) and punctuation. |
| 22 | + * This validates end-to-end UTF-8 → UTF-16 handling on Windows and generic |
| 23 | + * Unicode rendering across platforms. |
| 24 | + */ |
| 25 | +fun main() = application { |
| 26 | + val painter = painterResource(Res.drawable.icon) |
| 27 | + |
| 28 | + var lastClicked by remember { mutableStateOf("-") } |
| 29 | + |
| 30 | + Tray( |
| 31 | + iconContent = { |
| 32 | + Image(painter = painter, contentDescription = "Unicode Tray", modifier = Modifier.fillMaxSize()) |
| 33 | + }, |
| 34 | + primaryAction = { |
| 35 | + // no-op: right-click to open menu |
| 36 | + }, |
| 37 | + tooltip = "Démo: Menu Unicode (Français/中文)" |
| 38 | + ) { |
| 39 | + // French items |
| 40 | + Item(label = "Bonjour – Édition") { |
| 41 | + lastClicked = "Bonjour – Édition" |
| 42 | + println("Clicked: $lastClicked") |
| 43 | + } |
| 44 | + Item(label = "Préférences…") { |
| 45 | + lastClicked = "Préférences…" |
| 46 | + println("Clicked: $lastClicked") |
| 47 | + } |
| 48 | + Item(label = "À propos") { |
| 49 | + lastClicked = "À propos" |
| 50 | + println("Clicked: $lastClicked") |
| 51 | + } |
| 52 | + Item(label = "Quitter") { |
| 53 | + lastClicked = "Quitter" |
| 54 | + println("Clicked: $lastClicked") |
| 55 | + exitApplication() |
| 56 | + } |
| 57 | + |
| 58 | + Divider() |
| 59 | + |
| 60 | + // Chinese submenu with mixed content |
| 61 | + SubMenu(label = "设置 / 設置") { |
| 62 | + Item(label = "语言:中文(简体)") { |
| 63 | + lastClicked = "语言:中文(简体)" |
| 64 | + println("Clicked: $lastClicked") |
| 65 | + } |
| 66 | + Item(label = "語言:中文(繁體)") { |
| 67 | + lastClicked = "語言:中文(繁體)" |
| 68 | + println("Clicked: $lastClicked") |
| 69 | + } |
| 70 | + CheckableItem(label = "启用高级选项 ✓", checked = true) { checked -> |
| 71 | + lastClicked = "启用高级选项: ${if (checked) "开" else "关"}" |
| 72 | + println("Clicked: $lastClicked") |
| 73 | + } |
| 74 | + } |
| 75 | + |
| 76 | + SubMenu(label = "信息 ℹ / 信息") { |
| 77 | + Item(label = "关于 / 關於") { |
| 78 | + lastClicked = "关于 / 關於" |
| 79 | + println("Clicked: $lastClicked") |
| 80 | + } |
| 81 | + Item(label = "退出 / 退出") { |
| 82 | + lastClicked = "退出" |
| 83 | + println("Clicked: $lastClicked") |
| 84 | + exitApplication() |
| 85 | + } |
| 86 | + } |
| 87 | + |
| 88 | + Divider() |
| 89 | + |
| 90 | + // Mixed accents and symbols |
| 91 | + Item(label = "Café crème – façade – piñata – coöperate") { |
| 92 | + lastClicked = "Café crème – façade – piñata – coöperate" |
| 93 | + println("Clicked: $lastClicked") |
| 94 | + } |
| 95 | + Item(label = "Symbols: € £ ¥ • — … ✓ ✗ © ® ™") { |
| 96 | + lastClicked = "Symbols" |
| 97 | + println("Clicked: $lastClicked") |
| 98 | + } |
| 99 | + |
| 100 | + Divider() |
| 101 | + |
| 102 | + Item(label = "Dernier: $lastClicked", isEnabled = false) |
| 103 | + } |
| 104 | + |
| 105 | + Window(onCloseRequest = ::exitApplication, title = "Unicode Tray Demo") { } |
| 106 | +} |
0 commit comments