Skip to content

Commit

Permalink
feat: scrollbars
Browse files Browse the repository at this point in the history
  • Loading branch information
xfqwdsj committed Jan 20, 2024
1 parent bcdedb6 commit 97dcc42
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 5 deletions.
2 changes: 1 addition & 1 deletion build-number.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
# You should have received a copy of the GNU General Public License along
# with Fhraise. If not, see <https://www.gnu.org/licenses/>.
#
buildNumber=17
buildNumber=18
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* This file is part of Fhraise.
* Copyright (c) 2024 HSAS Foodies. All Rights Reserved.
*
* Fhraise is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option)
* any later version.
*
* Fhraise is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with Fhraise. If not, see <https://www.gnu.org/licenses/>.
*/

package ui.composables

import androidx.compose.foundation.ScrollState
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier

@Composable
actual fun VerticalScrollbar(scrollState: ScrollState, modifier: Modifier) {
}
26 changes: 26 additions & 0 deletions composeApp/src/commonMain/kotlin/ui/composables/Scrollbars.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* This file is part of Fhraise.
* Copyright (c) 2024 HSAS Foodies. All Rights Reserved.
*
* Fhraise is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option)
* any later version.
*
* Fhraise is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with Fhraise. If not, see <https://www.gnu.org/licenses/>.
*/

package ui.composables

import androidx.compose.foundation.ScrollState
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier

@Composable
expect fun VerticalScrollbar(scrollState: ScrollState, modifier: Modifier = Modifier)
28 changes: 24 additions & 4 deletions composeApp/src/commonMain/kotlin/ui/pages/root/SignIn.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import org.jetbrains.compose.resources.ExperimentalResourceApi
import org.jetbrains.compose.resources.painterResource
import ui.WindowSizeClass
import ui.WindowWidthSizeClass
import ui.composables.VerticalScrollbar
import ui.modifiers.applyBrush
import kotlin.math.max
import kotlin.math.roundToInt
Expand Down Expand Up @@ -197,6 +198,8 @@ fun SignInLayout(
targetValue = if (animation == null) 0f else 1f, animationSpec = spring(stiffness = Spring.StiffnessLow)
)

val scrollState = rememberScrollState()

SubcomposeLayout(
modifier = Modifier.alpha(firstPrintAnimation).offset(y = 32.dp * (1f - firstPrintAnimation)).then(modifier)
) { constraints ->
Expand Down Expand Up @@ -248,28 +251,44 @@ fun SignInLayout(
val additionalContentPlaceable = additionalContentMeasurable.measure(additionalContentConstraints)

// == Measure main ==
val mainBottomSpace =
((additionalContentPlaceable.height + additionalContentPaddingBottom) * animationSecondStageReversed)

val mainMeasurable = subcompose("main") {
SignInMainLayout(
animation = animation,
animationSecondStage = animationSecondStage,
scrollState = rememberScrollState(),
scrollState = scrollState,
contentPaddingLeft = contentPaddingLeft,
contentPaddingTop = contentPaddingTop,
contentPaddingRight = contentPaddingRight,
contentPaddingBottom = contentPaddingBottom,
bottomSpace = ((additionalContentPlaceable.height + additionalContentPaddingBottom) * animationSecondStageReversed).roundToInt(),
bottomSpace = mainBottomSpace.roundToInt(),
header = header,
mainContent = content,
)
}.first()

val mainCompatWidth = width.toFloat()
val mainMediumExpandedWidth = width * 7f / 9f
val mainWidth = mainCompatWidth + (mainMediumExpandedWidth - mainCompatWidth) * animationSecondStage
val mainWidth =
(mainCompatWidth + (mainMediumExpandedWidth - mainCompatWidth) * animationSecondStage).coerceAtLeast(0f)
.roundToInt()

val mainConstraints = Constraints.fixed(width = mainWidth.roundToInt().coerceAtLeast(0), height = height)
val mainConstraints = Constraints.fixed(width = mainWidth, height = height)
val mainPlaceable = mainMeasurable.measure(mainConstraints)

// == Scrollbar ==
val scrollbarHeight = (safeHeight - mainBottomSpace).roundToInt()

val scrollbarPlaceable = subcompose("scrollBar") {
VerticalScrollbar(scrollState = scrollState)
}.firstOrNull()
?.measure(Constraints(maxWidth = mainWidth, minHeight = scrollbarHeight, maxHeight = scrollbarHeight))

val scrollbarX = scrollbarPlaceable?.let { mainWidth - scrollbarPlaceable.width }
val scrollbarY = contentPaddingTop.roundToInt()

// == Place ==
val additionalContentCompatMediumX = 0f
val additionalContentX =
Expand Down Expand Up @@ -305,6 +324,7 @@ fun SignInLayout(

layout(width, height) {
mainPlaceable.placeRelative(0, 0)
scrollbarX?.let { scrollbarPlaceable.placeRelative(scrollbarX, scrollbarY) }
additionalContentBackgroundPlaceable.placeRelative(0, additionalContentBackgroundY.roundToInt())
additionalContentPlaceable.placeRelative(additionalContentX.roundToInt(), additionalContentY.roundToInt())
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* This file is part of Fhraise.
* Copyright (c) 2024 HSAS Foodies. All Rights Reserved.
*
* Fhraise is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option)
* any later version.
*
* Fhraise is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with Fhraise. If not, see <https://www.gnu.org/licenses/>.
*/

package ui.composables

import androidx.compose.foundation.ScrollState
import androidx.compose.foundation.rememberScrollbarAdapter
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier

@Composable
actual fun VerticalScrollbar(scrollState: ScrollState, modifier: Modifier) {
androidx.compose.foundation.VerticalScrollbar(
adapter = rememberScrollbarAdapter(scrollState = scrollState), modifier = modifier
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* This file is part of Fhraise.
* Copyright (c) 2024 HSAS Foodies. All Rights Reserved.
*
* Fhraise is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option)
* any later version.
*
* Fhraise is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with Fhraise. If not, see <https://www.gnu.org/licenses/>.
*/

package ui.composables

import androidx.compose.foundation.ScrollState
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier

@Composable
actual fun VerticalScrollbar(scrollState: ScrollState, modifier: Modifier) {
}

0 comments on commit 97dcc42

Please sign in to comment.