Skip to content

Commit

Permalink
Finalise landscape player layout
Browse files Browse the repository at this point in the history
  • Loading branch information
toasterofbread committed Dec 16, 2023
1 parent d3fa423 commit 909e4a8
Show file tree
Hide file tree
Showing 25 changed files with 502 additions and 372 deletions.
2 changes: 1 addition & 1 deletion ComposeKit
12 changes: 5 additions & 7 deletions desktopApp/src/jvmMain/kotlin/main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,7 @@ import androidx.compose.ui.window.rememberWindowState
import com.toasterofbread.composekit.platform.composable.onWindowBackPressed
import com.toasterofbread.spmp.model.settings.category.DesktopSettings
import com.toasterofbread.spmp.platform.AppContext
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.cancel
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import kotlinx.coroutines.*
import org.jetbrains.skiko.OS
import org.jetbrains.skiko.hostOs
import java.awt.Toolkit
Expand Down Expand Up @@ -56,7 +51,10 @@ fun main() {
}
return@Window false
},
state = rememberWindowState(size = DpSize(1280.dp, 720.dp), position = WindowPosition(Alignment.Center))
state = rememberWindowState(
size = DpSize(1280.dp, 720.dp),
position = WindowPosition(Alignment.Center)
)
) {
LaunchedEffect(Unit) {
val startup_command: String = DesktopSettings.Key.STARTUP_COMMAND.get()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package com.toasterofbread.spmp.model.settings.category
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.Palette
import com.toasterofbread.spmp.model.settings.SettingsKey
import com.toasterofbread.spmp.platform.AppContext
import com.toasterofbread.spmp.resources.getString
import com.toasterofbread.spmp.ui.layout.apppage.settingspage.category.getThemeCategoryItems
import com.toasterofbread.spmp.ui.layout.nowplaying.ThemeMode

data object ThemeSettings: SettingsCategory("theme") {
override val keys: List<SettingsKey> = Key.entries.toList()
Expand All @@ -32,7 +32,7 @@ data object ThemeSettings: SettingsCategory("theme") {
ACCENT_COLOUR_SOURCE -> AccentColourSource.THUMBNAIL.ordinal
CURRENT_THEME -> 0
THEMES -> "[]"
NOWPLAYING_THEME_MODE -> 0
NOWPLAYING_THEME_MODE -> ThemeMode.DEFAULT.ordinal
NOWPLAYING_DEFAULT_GRADIENT_DEPTH -> 1f
} as T
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ fun PlayerState.getDefaultHorizontalPadding(): Dp =
if (Platform.DESKTOP.isCurrent() && form_factor == FormFactor.LANDSCAPE) 30.dp else 10.dp
@Composable
fun PlayerState.getDefaultVerticalPadding(): Dp =
if (Platform.DESKTOP.isCurrent() && form_factor == FormFactor.LANDSCAPE) 30.dp else 10.dp // TODO
if (Platform.DESKTOP.isCurrent() && form_factor == FormFactor.LANDSCAPE) 10.dp else 10.dp

@Composable
fun PlayerState.getDefaultPaddingValues(): PaddingValues = PaddingValues(horizontal = getDefaultHorizontalPadding(), vertical = getDefaultVerticalPadding())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.toasterofbread.spmp.ui.component

import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.fadeOut
import androidx.compose.animation.slideInVertically
import androidx.compose.animation.slideOutVertically
import androidx.compose.animation.*
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.IntrinsicSize
import androidx.compose.foundation.layout.fillMaxWidth
Expand All @@ -20,6 +17,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import com.toasterofbread.composekit.utils.composable.AlignableCrossfade
import com.toasterofbread.spmp.model.lyrics.SongLyrics
import com.toasterofbread.spmp.model.settings.category.TopBarSettings
import kotlinx.coroutines.delay

private const val UPDATE_INTERVAL_MS = 100L
Expand All @@ -43,16 +41,17 @@ private fun getCurrentLine(lyrics: SongLyrics, time: Long, linger: Boolean): Int
fun LyricsLineDisplay(
lyrics: SongLyrics,
getTime: () -> Long,
lyrics_linger: Boolean = true,
show_furigana: Boolean = true,
max_lines: Int = 1,
preallocate_needed_space: Boolean = false,
modifier: Modifier = Modifier,
text_colour: Color = LocalContentColor.current,
emptyContent: (@Composable () -> Unit)? = null
) {
require(lyrics.synced)

val lyrics_linger: Boolean by TopBarSettings.Key.LYRICS_LINGER.rememberMutableState()
val show_furigana: Boolean by TopBarSettings.Key.LYRICS_SHOW_FURIGANA.rememberMutableState()
val max_lines: Int by TopBarSettings.Key.LYRICS_MAX_LINES.rememberMutableState()
val preallocate_max_space: Boolean by TopBarSettings.Key.LYRICS_PREAPPLY_MAX_LINES.rememberMutableState()

var current_line: Int? by remember { mutableStateOf(getCurrentLine(lyrics, getTime(), lyrics_linger)) }
var line_a: Int? by remember { mutableStateOf(current_line) }
var line_b: Int? by remember { mutableStateOf(null) }
Expand All @@ -62,7 +61,7 @@ fun LyricsLineDisplay(
while (true) {
delay(UPDATE_INTERVAL_MS)

val line = getCurrentLine(lyrics, getTime(), lyrics_linger)
val line: Int? = getCurrentLine(lyrics, getTime(), lyrics_linger)
if (lyrics_linger && line == null) {
continue
}
Expand All @@ -80,17 +79,17 @@ fun LyricsLineDisplay(
}
}

val enter = slideInVertically { it }
val exit = slideOutVertically { -it } + fadeOut()
val enter: EnterTransition = slideInVertically { it }
val exit: ExitTransition = slideOutVertically { -it } + fadeOut()

Box(modifier.height(IntrinsicSize.Min), contentAlignment = Alignment.Center) {
val show_a = line_a != null && show_line_a
val show_b = line_b != null && !show_line_a
val show_a: Boolean = line_a != null && show_line_a
val show_b: Boolean = line_b != null && !show_line_a

@Composable
fun phase(show: Boolean, index: Int?) {
AnimatedVisibility(show, Modifier.height(IntrinsicSize.Min).fillMaxWidth(), enter = enter, exit = exit) {
var line by remember { mutableStateOf(index) }
var line: Int? by remember { mutableStateOf(index) }
LaunchedEffect(index) {
if (index != null) {
line = index
Expand All @@ -103,7 +102,7 @@ fun LyricsLineDisplay(
show_readings = show_furigana,
text_colour = text_colour,
max_lines = max_lines,
preallocate_needed_space = preallocate_needed_space
preallocate_needed_space = preallocate_max_space
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,21 +299,12 @@ class MusicTopBar(val player: PlayerState) {
Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
when (state) {
is SongLyrics -> {
val linger: Boolean by TopBarSettings.Key.LYRICS_LINGER.rememberMutableState()
val show_furigana: Boolean by TopBarSettings.Key.LYRICS_SHOW_FURIGANA.rememberMutableState()
val max_lines: Int by TopBarSettings.Key.LYRICS_MAX_LINES.rememberMutableState()
val preallocate_max_space: Boolean by TopBarSettings.Key.LYRICS_PREAPPLY_MAX_LINES.rememberMutableState()

LyricsLineDisplay(
lyrics = state,
getTime = {
(player.controller?.current_position_ms ?: 0) +
(sync_offset_state?.value ?: 0)
},
lyrics_linger = linger,
show_furigana = show_furigana,
max_lines = max_lines,
preallocate_needed_space = preallocate_max_space,
modifier = Modifier.fillMaxWidth(),
emptyContent = {
TopBarEmptyContent()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,16 @@ const val WAVE_BORDER_HEIGHT_DP: Float = 20f
data class WaveShape(
val waves: Int,
val offset: Float,
val invert: Boolean = false
val invert: Boolean = false,
val width_multiplier: Float = 1f
): Shape {
override fun createOutline(size: Size, layoutDirection: LayoutDirection, density: Density): Outline {
val path: Path = Path()

path.addRect(Rect(0f, 0f, size.width, size.height / 2))

wavePath(path, size, 1, waves) { offset }
wavePath(path, size, -1, waves) { offset }
wavePath(path, size, 1, waves, width_multiplier) { offset }
wavePath(path, size, -1, waves, width_multiplier) { offset }

if (invert) {
path.transform(
Expand All @@ -63,6 +64,7 @@ fun WaveBorder(
getOffset: ((height: Float) -> Float)? = null,
waves: Int = 3,
invert: Boolean = false,
width_multiplier: Float = 1f,
getWaveOffset: (Density.() -> Float)? = null,
border_thickness: Dp = 0.dp,
border_colour: Color = LocalContentColor.current
Expand All @@ -72,8 +74,8 @@ fun WaveBorder(

val colour: Color = getColour(player.theme)
val offset: Float? = getWaveOffset?.invoke(density)
val shape: WaveShape = remember(waves, offset) {
WaveShape(waves, offset ?: 0f, invert = invert)
val shape: WaveShape = remember(waves, offset, width_multiplier) {
WaveShape(waves, offset ?: 0f, invert = invert, width_multiplier = width_multiplier)
}

Box(modifier.requiredHeight(0.dp)) {
Expand All @@ -86,8 +88,8 @@ fun WaveBorder(
with(density) {
val user_offset: Dp = getOffset?.invoke(height.toPx())?.toDp()
?: (
if (invert) (-height / 2) + 0.1.dp
else (height / 2) - 0.1.dp
if (invert) (-height / 2) + 0.2.dp
else (height / 2) - 0.2.dp
)
user_offset + border_thickness
}
Expand All @@ -103,6 +105,7 @@ inline fun DrawScope.drawWave(
waves: Int,
wave_size: Size = size,
stroke_width: Float = 2f,
width_multiplier: Float = 1f,
getWaveOffset: () -> Float,
getColour: () -> Color,
) {
Expand All @@ -111,12 +114,12 @@ inline fun DrawScope.drawWave(
val stroke: Stroke = Stroke(stroke_width)

// Above equilibrium
wavePath(path, wave_size, -1, waves, getWaveOffset)
wavePath(path, wave_size, -1, waves, width_multiplier, getWaveOffset)
drawPath(path, colour, style = stroke)
path.reset()

// Below equilibrium
wavePath(path, wave_size, 1, waves, getWaveOffset)
wavePath(path, wave_size, 1, waves, width_multiplier, getWaveOffset)
drawPath(path, colour, style = stroke)
}

Expand All @@ -125,6 +128,7 @@ inline fun wavePath(
size: Size,
direction: Int,
waves: Int,
width_multiplier: Float,
getOffset: () -> Float
): Path {
val y_offset: Float = size.height / 2
Expand All @@ -135,7 +139,7 @@ inline fun wavePath(

path.moveTo(x = offset_px, y = y_offset)

for (i in 0 until ceil(size.width / (half_period + 1)).toInt()) {
for (i in 0 until ceil((size.width * width_multiplier) / (half_period + 1)).toInt()) {
if ((i % 2 == 0) != (direction == 1)) {
path.relativeMoveTo(half_period, 0f)
continue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,19 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.DpSize
import androidx.compose.ui.unit.dp
import com.toasterofbread.spmp.model.mediaitem.MediaItem
import com.toasterofbread.spmp.model.mediaitem.db.rememberPinnedItems
import com.toasterofbread.spmp.model.mediaitem.db.setPinned
import com.toasterofbread.spmp.ui.component.mediaitemlayout.MediaItemGrid
import com.toasterofbread.spmp.ui.component.multiselect.MediaItemMultiSelectContext
import com.toasterofbread.spmp.ui.layout.apppage.mainpage.PlayerState

@Composable
fun PinnedItemsRow(
modifier: Modifier = Modifier
modifier: Modifier = Modifier,
multiselect_context: MediaItemMultiSelectContext? = null
) {
val player: PlayerState = LocalPlayerState.current
val pinned_items: List<MediaItem>? = rememberPinnedItems()
Expand Down Expand Up @@ -89,13 +90,9 @@ fun PinnedItemsRow(
}
}
},
multiselect_context = player.main_multiselect_context,
multiselect_context = multiselect_context,
itemSizeProvider = {
val width: Dp = 100.dp
return@MediaItemGrid DpSize(
width,
width + 50.dp
)
DpSize(100.dp, 100.dp)
}
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.toasterofbread.spmp.ui.layout.apppage.mainpage
import LocalPlayerState
import SpMp
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.core.Spring
import androidx.compose.animation.core.animateDpAsState
import androidx.compose.animation.core.spring
import androidx.compose.animation.fadeIn
Expand All @@ -19,8 +20,6 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.onSizeChanged
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.unit.*
import androidx.compose.ui.window.Dialog
import com.toasterofbread.composekit.platform.Platform
import com.toasterofbread.composekit.platform.PlatformPreferences
import com.toasterofbread.composekit.platform.PlatformPreferencesListener
import com.toasterofbread.composekit.platform.composable.BackHandler
Expand Down Expand Up @@ -76,7 +75,7 @@ class PlayerStateImpl(override val context: AppContext, private val coroutine_sc
np_swipe_state.value.animateTo(
page,
when (form_factor) {
// NowPlayingMainTabPage.Mode.LARGE -> spring(Spring.DampingRatioNoBouncy, Spring.StiffnessMediumLow)
FormFactor.LANDSCAPE -> spring(Spring.DampingRatioNoBouncy, Spring.StiffnessMediumLow)
else -> spring()
}
)
Expand All @@ -101,8 +100,7 @@ class PlayerStateImpl(override val context: AppContext, private val coroutine_sc

override val app_page_state = AppPageState(this)
override val main_multiselect_context: MediaItemMultiSelectContext = AppPageMultiSelectContext(this)
override var np_theme_mode: ThemeMode by mutableStateOf(
Settings.getEnum(ThemeSettings.Key.NOWPLAYING_THEME_MODE, context.getPrefs()))
override var np_theme_mode: ThemeMode by mutableStateOf(Settings.getEnum(ThemeSettings.Key.NOWPLAYING_THEME_MODE, context.getPrefs()))
override val np_overlay_menu: MutableState<PlayerOverlayMenu?> = mutableStateOf(null)
override val top_bar: MusicTopBar = MusicTopBar(this)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.layout.onSizeChanged
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.unit.Density
Expand All @@ -21,8 +19,6 @@ val MINIMISED_NOW_PLAYING_HEIGHT_DP: Float
@Composable get() = LocalPlayerState.current.form_factor.getMinimisedPlayerHeight().value
val MINIMISED_NOW_PLAYING_V_PADDING_DP: Float
@Composable get() = LocalPlayerState.current.form_factor.getMinimisedPlayerVPadding().value
const val MEDIAITEM_PREVIEW_SQUARE_SIZE_SMALL: Float = 100f
const val MEDIAITEM_PREVIEW_SQUARE_SIZE_LARGE: Float = 200f

@Composable
fun RootView(player: PlayerStateImpl) {
Expand All @@ -40,24 +36,10 @@ fun RootView(player: PlayerStateImpl) {
}
)

val focus_requester: FocusRequester = remember { FocusRequester() }

Column(
Modifier
.fillMaxSize()
.background(player.theme.background_provider)
// .pointerInput(Unit) {
// while (currentCoroutineContext().isActive) {
// awaitPointerEventScope {
// val event = awaitPointerEvent(PointerEventPass.Final)
// if (event.type == PointerEventType.Press && (event.buttons.isPrimaryPressed || event.buttons.isSecondaryPressed || event.buttons.isTertiaryPressed)) {
// println(event.changes.any { it.isConsumed })
// focus_requester.requestFocus()
// }
// }
// }
// }
// .focusRequester(focus_requester)
) {
player.HomePage()
player.NowPlaying()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ class SettingsAppPage(override val state: AppPageState, footer_modifier: Modifie
pill_menu.PillMenu()

Column(Modifier.fillMaxSize().padding(horizontal = PREFS_PAGE_EXTRA_PADDING_DP.dp)) {
val top_padding: Dp = player.top_bar.MusicTopBar(
val top_padding: Dp = 0.dp
player.top_bar.MusicTopBar(
TopBarSettings.Key.SHOW_IN_SETTINGS,
Modifier.fillMaxWidth().zIndex(10f),
getBottomBorderColour = player.theme.background_provider,
Expand Down
Loading

0 comments on commit 909e4a8

Please sign in to comment.