增加网格模式封面大小自定义

This commit is contained in:
HapeLee
2026-05-24 02:42:13 +08:00
parent 7b32cb732f
commit c6cf239d49
4 changed files with 41 additions and 11 deletions
@@ -301,6 +301,13 @@ object BookshelfConfig {
var bookshelfListCoverWidth by _bookshelfListCoverWidth var bookshelfListCoverWidth by _bookshelfListCoverWidth
val bookshelfListCoverWidthState: State<Int> get() = _bookshelfListCoverWidth.state val bookshelfListCoverWidthState: State<Int> get() = _bookshelfListCoverWidth.state
/**
* 书架网格模式下封面宽度
*/
private val _bookshelfGridCoverWidth = prefStateDelegate(PreferKey.bookshelfGridCoverWidth, 120)
var bookshelfGridCoverWidth by _bookshelfGridCoverWidth
val bookshelfGridCoverWidthState: State<Int> get() = _bookshelfGridCoverWidth.state
/** /**
* 书架搜索按钮是否直接跳转搜索页 * 书架搜索按钮是否直接跳转搜索页
*/ */
@@ -99,6 +99,7 @@ fun BookshelfItem(
if (isGrid) { if (isGrid) {
Box( Box(
modifier = modifier modifier = modifier
.fillMaxWidth()
.clip(RoundedCornerShape(4.dp)) .clip(RoundedCornerShape(4.dp))
.then( .then(
if (isSelected) { if (isSelected) {
@@ -112,7 +113,12 @@ fun BookshelfItem(
onLongClick = onLongClick onLongClick = onLongClick
) )
) { ) {
Column(horizontalAlignment = Alignment.CenterHorizontally) { Column(
horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier
.align(Alignment.Center)
.width(coverWidth.dp)
) {
Box( Box(
modifier = Modifier modifier = Modifier
@@ -434,7 +440,7 @@ fun BookGroupItemGrid(
titleCenter = titleCenter, titleCenter = titleCenter,
titleMaxLines = titleMaxLines, titleMaxLines = titleMaxLines,
coverShadow = coverShadow, coverShadow = coverShadow,
coverWidth = 84, coverWidth = BookshelfConfig.bookshelfGridCoverWidth,
onClick = onClick, onClick = onClick,
onLongClick = onLongClick onLongClick = onLongClick
) )
@@ -757,7 +763,7 @@ fun BookItem(
titleCenter = titleCenter, titleCenter = titleCenter,
titleMaxLines = titleMaxLines, titleMaxLines = titleMaxLines,
coverShadow = coverShadow, coverShadow = coverShadow,
coverWidth = if (layoutMode == 0) BookshelfConfig.bookshelfListCoverWidth else 84, coverWidth = if (layoutMode == 0) BookshelfConfig.bookshelfListCoverWidth else BookshelfConfig.bookshelfGridCoverWidth,
onClick = onClick, onClick = onClick,
onLongClick = onLongClick onLongClick = onLongClick
) )
@@ -257,6 +257,14 @@ fun BookshelfConfigSheet(
color = LegadoTheme.colorScheme.surface, color = LegadoTheme.colorScheme.surface,
onCheckedChange = { BookshelfConfig.bookshelfTitleCenter = it } onCheckedChange = { BookshelfConfig.bookshelfTitleCenter = it }
) )
CompactSliderSettingItem(
title = "网格封面宽度",
value = BookshelfConfig.bookshelfGridCoverWidth.toFloat(),
valueRange = 40f..150f,
steps = 110,
onValueChange = { BookshelfConfig.bookshelfGridCoverWidth = it.toInt() }
)
} }
} }
@@ -315,14 +323,6 @@ fun BookshelfConfigSheet(
} }
) )
CompactSliderSettingItem(
title = "列表封面宽度",
value = BookshelfConfig.bookshelfListCoverWidth.toFloat(),
valueRange = 40f..120f,
steps = 80,
onValueChange = { BookshelfConfig.bookshelfListCoverWidth = it.toInt() }
)
CompactSwitchSettingItem( CompactSwitchSettingItem(
title = "精简详情", title = "精简详情",
checked = BookshelfConfig.bookshelfLayoutCompact, checked = BookshelfConfig.bookshelfLayoutCompact,
@@ -332,6 +332,14 @@ fun BookshelfConfigSheet(
val listColCount = val listColCount =
if (isLandscape) BookshelfConfig.bookshelfLayoutListLandscape else BookshelfConfig.bookshelfLayoutListPortrait if (isLandscape) BookshelfConfig.bookshelfLayoutListLandscape else BookshelfConfig.bookshelfLayoutListPortrait
CompactSliderSettingItem(
title = "列表封面宽度",
value = BookshelfConfig.bookshelfListCoverWidth.toFloat(),
valueRange = 40f..120f,
steps = 80,
onValueChange = { BookshelfConfig.bookshelfListCoverWidth = it.toInt() }
)
CompactSliderSettingItem( CompactSliderSettingItem(
title = stringResource(R.string.number_rows_columns), title = stringResource(R.string.number_rows_columns),
value = listColCount.toFloat(), value = listColCount.toFloat(),
@@ -232,6 +232,15 @@ fun BookshelfScreen(
val latestGroups by rememberUpdatedState(uiState.groups) val latestGroups by rememberUpdatedState(uiState.groups)
val latestSelectedGroupId by rememberUpdatedState(uiState.selectedGroupId) val latestSelectedGroupId by rememberUpdatedState(uiState.selectedGroupId)
LaunchedEffect(uiState.selectedGroupIndex, uiState.groups.size) {
if (uiState.groups.isNotEmpty()
&& uiState.selectedGroupIndex in uiState.groups.indices
&& pagerState.currentPage != uiState.selectedGroupIndex
) {
pagerState.scrollToPage(uiState.selectedGroupIndex)
}
}
LaunchedEffect(pagerState) { LaunchedEffect(pagerState) {
snapshotFlow { pagerState.settledPage } snapshotFlow { pagerState.settledPage }
.distinctUntilChanged() .distinctUntilChanged()