MainView.kt 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. package org.mjdev.desktop.main
  2. import androidx.compose.foundation.layout.Box
  3. import androidx.compose.foundation.layout.Column
  4. import androidx.compose.foundation.layout.fillMaxSize
  5. import androidx.compose.foundation.layout.size
  6. import androidx.compose.runtime.Composable
  7. import androidx.compose.ui.Alignment
  8. import androidx.compose.ui.Modifier
  9. import androidx.compose.ui.unit.dp
  10. import org.mjdev.desktop.context.DesktopContextScope.Companion.withDesktopContext
  11. import org.mjdev.desktop.extensions.Compose.preview
  12. import org.jetbrains.compose.ui.tooling.preview.Preview
  13. import org.mjdev.desktop.components.background.BackgroundImage
  14. import org.mjdev.desktop.components.qrcode.QrCodeView
  15. @Composable
  16. fun MainView() = withDesktopContext {
  17. Box(
  18. modifier = Modifier.fillMaxSize(),
  19. contentAlignment = Alignment.Center
  20. ) {
  21. BackgroundImage(
  22. modifier = Modifier.fillMaxSize(),
  23. switchDelay = theme.backgroundRotationDelay,
  24. images = backgrounds,
  25. onChange = { src ->
  26. palette.apply {
  27. update(src)
  28. }.also { p ->
  29. context.currentUser.theme.backgroundColor = p.backgroundColor
  30. }
  31. }
  32. )
  33. Box(
  34. modifier = Modifier.size(256.dp, 256.dp),
  35. contentAlignment = Alignment.Center
  36. ) {
  37. Column {
  38. QrCodeView(
  39. modifier = Modifier.fillMaxSize()
  40. )
  41. }
  42. }
  43. }
  44. // val tooltipState: TooltipState = rememberTooltipState()
  45. // val appsMenuState = rememberAppsMenuState(
  46. // visible = isDesign
  47. // )
  48. // val controlCenterState = rememberVisibilityState(
  49. // visible = isDesign
  50. // )
  51. // val panelState = rememberVisibilityState(
  52. // visible = isDesign || !panelAutoHideEnabled,
  53. // enabled = panelAutoHideEnabled,
  54. // autoHideDelay = panelHideDelay
  55. // )
  56. // val bottomPadding by rememberCalculated(
  57. // panelState.enabled, panelState.height
  58. // ) {
  59. // if (panelState.enabled) 0.dp
  60. // else max(0.dp, panelState.height)
  61. // }
  62. //// val installWindowState = rememberVisibilityState()
  63. //// val infoWindowState = rememberVisibilityState(false) //(api.isFirstStart || api.isDebug) // todo
  64. // val onTooltip: (item: Any?) -> Unit = { item ->
  65. // println("Showing tooltip : $item")
  66. // tooltipState.show(item)
  67. // }
  68. // // todo not showing nothing
  69. // Box(
  70. // modifier = Modifier.fillMaxSize(),
  71. // contentAlignment = Alignment.Center
  72. // ) {
  73. // // todo, something prevent preview
  74. // if (!isDesign) {
  75. // Desktop(
  76. // tooltipState = tooltipState,
  77. // onTooltip = onTooltip,
  78. // padding = PaddingValues(
  79. // bottom = bottomPadding
  80. // ),
  81. // widgets = {
  82. // MemoryChart(
  83. // modifier = Modifier
  84. // .size(350.dp, 300.dp)
  85. // .align(Alignment.BottomEnd)
  86. // )
  87. // }, onLeftMouseClick = {
  88. // runAsync {
  89. // panelState.hide()
  90. // appsMenuState.hide()
  91. // controlCenterState.hide()
  92. // }
  93. // }, onRightMouseClick = {
  94. //// contextMenuState.show()
  95. // })
  96. // }
  97. // DesktopPanel(
  98. // panelState = panelState,
  99. // onTooltip = onTooltip,
  100. // onMenuIconClicked = {
  101. // runAsync {
  102. // appsMenuState.show()
  103. // }
  104. // }
  105. // )
  106. // ControlCenter(
  107. // modifier = Modifier
  108. // .fillMaxHeight()
  109. // .align(Alignment.TopEnd),
  110. // controlCenterState = controlCenterState,
  111. // onTooltip = onTooltip,
  112. // )
  113. // AppsMenu(
  114. // modifier = Modifier
  115. // .wrapContentSize()
  116. // .align(Alignment.BottomStart),
  117. // appsMenuState = appsMenuState,
  118. // panelState = panelState,
  119. // onAppClick = { app ->
  120. // runAsync {
  121. // app.start()
  122. // appsMenuState.hide()
  123. // }
  124. // },
  125. // onAppContextMenuClick = {},
  126. // onCategoryContextMenuClick = {},
  127. // onUserAvatarClick = {},
  128. // onActionClick = {},
  129. // onTooltip = onTooltip,
  130. // )
  131. // }
  132. }
  133. @Preview
  134. @Composable
  135. fun MainViewPreview() = preview {
  136. MainView()
  137. }