better width handling for wallpaper picker

This commit is contained in:
Zacharias-Brohn
2025-11-13 01:29:35 +01:00
parent f2a7ce6160
commit 374842b321
2 changed files with 32 additions and 2 deletions
+2
View File
@@ -9,6 +9,7 @@ Singleton {
property alias baseBgColor: adapter.baseBgColor property alias baseBgColor: adapter.baseBgColor
property alias accentColor: adapter.accentColor property alias accentColor: adapter.accentColor
property alias wallpaperPath: adapter.wallpaperPath property alias wallpaperPath: adapter.wallpaperPath
property alias maxWallpapers: adapter.maxWallpapers
FileView { FileView {
id: root id: root
@@ -27,6 +28,7 @@ Singleton {
property string wallpaperPath: Quickshell.env("HOME") + "/Pictures/Wallpapers" property string wallpaperPath: Quickshell.env("HOME") + "/Pictures/Wallpapers"
property string baseBgColor: "#801a1a1a" property string baseBgColor: "#801a1a1a"
property AccentColor accentColor: AccentColor {} property AccentColor accentColor: AccentColor {}
property int maxWallpapers: 7
} }
} }
} }
+30 -2
View File
@@ -249,17 +249,45 @@ Scope {
readonly property string search: searchInput.text.split(" ").slice(1).join(" ") readonly property string search: searchInput.text.split(" ").slice(1).join(" ")
values: SearchWallpapers.query( search ) values: SearchWallpapers.query( search )
onValuesChanged: wallpaperPickerView.currentIndex = SearchWallpapers.list.findIndex( w => w.path === WallpaperPath.currentWallpaperPath )
} }
readonly property int itemWidth: 288 + 10
readonly property int numItems: {
const screen = QsWindow.window?.screen;
if (!screen)
return 0;
// Screen width - 4x outer rounding - 2x max side thickness (cause centered)
const barMargins = 10;
let outerMargins = 0;
const maxWidth = screen.width - (barMargins + outerMargins) * 2;
if (maxWidth <= 0)
return 0;
const maxItemsOnScreen = Math.floor(maxWidth / itemWidth);
const visible = Math.min(maxItemsOnScreen, Config.maxWallpapers, wallpaperModel.values.length);
if (visible === 2)
return 1;
if (visible > 1 && visible % 2 === 0)
return visible - 1;
return visible;
}
Component.onCompleted: currentIndex = SearchWallpapers.list.findIndex( w => w.path === WallpaperPath.currentWallpaperPath )
cacheItemCount: 5 cacheItemCount: 5
snapMode: PathView.SnapToItem snapMode: PathView.SnapToItem
preferredHighlightBegin: 0.5 preferredHighlightBegin: 0.5
preferredHighlightEnd: 0.5 preferredHighlightEnd: 0.5
highlightRangeMode: PathView.StrictlyEnforceRange highlightRangeMode: PathView.StrictlyEnforceRange
pathItemCount: 7 pathItemCount: numItems
implicitHeight: 212 implicitHeight: 212
implicitWidth: Math.min( wallpaperModel.values.length, 7 ) * 192 + Math.max(0, wallpaperModel.values.length -1) * 10 implicitWidth: Math.min( numItems, count ) * itemWidth
path: Path { path: Path {
startY: wallpaperPickerView.height / 2 startY: wallpaperPickerView.height / 2