Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 50 additions & 23 deletions app/components/cards/poster.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,71 @@ package cards
import (
"codeberg.org/dergs/tonearm/pkg/schwifty"
. "codeberg.org/dergs/tonearm/pkg/schwifty/syntax"
"codeberg.org/puregotk/puregotk/v4/gdk"
"codeberg.org/puregotk/puregotk/v4/gtk"
"codeberg.org/puregotk/puregotk/v4/pango"
"github.com/0skillallluck/scanline/app/preference"
"github.com/0skillallluck/scanline/app/sources"
"github.com/0skillallluck/scanline/utils/imageutils"
"github.com/0skillallluck/scanline/utils/textures"
)

// Poster card image dimensions. Pre-sized cover URLs (via PosterCoverURL)
// match these so the server returns ready-to-render JPEGs and no local
// scaling is needed.
const (
PosterWidth = 180
PosterHeight = 270
)

// PosterCoverURL returns a thumb→URL builder that asks src for cover art
// at the poster's exact display dimensions. Pages building horizontal
// poster lists pass the returned closure into lists.RenderHub etc.
func PosterCoverURL(src sources.Source) func(thumb string) string {
return func(thumb string) string {
return src.PhotoTranscodeURL(thumb, PosterWidth, PosterHeight)
}
}

func poster[T any](title string, subTitle schwifty.Widgetable[T], coverURL string) schwifty.Button {
return posterWithProgress(title, subTitle, coverURL, 0)
image := posterPicture(coverURL).
CornerRadius(10).
Overflow(gtk.OverflowHiddenValue)

return posterButton(title, subTitle, image)
}

func posterWithProgress[T any](title string, subTitle schwifty.Widgetable[T], coverURL string, progress float64) schwifty.Button {
picture := Picture().
SizeRequest(180, 270).
FromPaintable(gdk.NewTextureFromResource("/dev/skillless/Scanline/icons/scalable/state/missing-album.svg")).
if progress <= 0 {
return poster(title, subTitle, coverURL)
}

progressBar := Box(gtk.OrientationHorizontalValue).
SizeRequest(int32(PosterWidth*progress), 4).
VAlign(gtk.AlignEndValue).
HAlign(gtk.AlignStartValue).
CSS("box { background-color: @accent_bg_color; }")

image := Bin().
Child(Overlay(posterPicture(coverURL)).AddOverlay(progressBar)).
SizeRequest(PosterWidth, PosterHeight).
CornerRadius(10).
Overflow(gtk.OverflowHiddenValue)

return posterButton(title, subTitle, image)
}

func posterPicture(coverURL string) schwifty.Picture {
return Picture().
SizeRequest(PosterWidth, PosterHeight).
FromPaintable(textures.FromResource("/dev/skillless/Scanline/icons/scalable/state/missing-album.svg")).
ConnectRealize(func(w gtk.Widget) {
if preference.Performance().AllowPreviewImages() {
imageutils.LoadIntoPictureScaled(coverURL, 180, 270, gtk.PictureNewFromInternalPtr(w.Ptr))
imageutils.LoadIntoPictureScaled(coverURL, PosterWidth, PosterHeight, gtk.PictureNewFromInternalPtr(w.Ptr))
}
})
}

var image any
if progress > 0 {
progressBar := Box(gtk.OrientationHorizontalValue).
SizeRequest(int32(180*progress), 4).
VAlign(gtk.AlignEndValue).
HAlign(gtk.AlignStartValue).
CSS("box { background-color: @accent_bg_color; }")

image = Bin().
Child(Overlay(picture).AddOverlay(progressBar)).
SizeRequest(180, 270).
CornerRadius(10).
Overflow(gtk.OverflowHiddenValue)
} else {
image = picture.CornerRadius(10).Overflow(gtk.OverflowHiddenValue)
}

func posterButton[T any](title string, subTitle schwifty.Widgetable[T], image any) schwifty.Button {
return Button().
Child(
VStack(
Expand Down
4 changes: 2 additions & 2 deletions app/components/cards/preview.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package cards
import (
"codeberg.org/dergs/tonearm/pkg/schwifty"
. "codeberg.org/dergs/tonearm/pkg/schwifty/syntax"
"codeberg.org/puregotk/puregotk/v4/gdk"
"codeberg.org/puregotk/puregotk/v4/gtk"
"codeberg.org/puregotk/puregotk/v4/pango"
"github.com/0skillallluck/scanline/app/preference"
"github.com/0skillallluck/scanline/utils/imageutils"
"github.com/0skillallluck/scanline/utils/textures"
)

func previewCard[T any](title string, subTitle schwifty.Widgetable[T], artURL string, progress float64) schwifty.Button {
Expand All @@ -17,7 +17,7 @@ func previewCard[T any](title string, subTitle schwifty.Widgetable[T], artURL st
// Create the picture widget
picture := Picture().
SizeRequest(480, 270).
FromPaintable(gdk.NewTextureFromResource("/dev/skillless/Scanline/icons/scalable/state/missing-album.svg")).
FromPaintable(textures.FromResource("/dev/skillless/Scanline/icons/scalable/state/missing-album.svg")).
ContentFit(gtk.ContentFitCoverValue).
ConnectRealize(func(w gtk.Widget) {
if preference.Performance().AllowPreviewImages() {
Expand Down
4 changes: 2 additions & 2 deletions app/components/cards/season_episode.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package cards
import (
"codeberg.org/dergs/tonearm/pkg/schwifty"
. "codeberg.org/dergs/tonearm/pkg/schwifty/syntax"
"codeberg.org/puregotk/puregotk/v4/gdk"
"codeberg.org/puregotk/puregotk/v4/glib"
"codeberg.org/puregotk/puregotk/v4/gtk"
"codeberg.org/puregotk/puregotk/v4/pango"
"github.com/0skillallluck/scanline/app/preference"
"github.com/0skillallluck/scanline/app/sources"
"github.com/0skillallluck/scanline/internal/gettext"
"github.com/0skillallluck/scanline/utils/imageutils"
"github.com/0skillallluck/scanline/utils/textures"
)

func NewSeasonEpisode(metadata *sources.Metadata, coverURL, serverID string) schwifty.Button {
Expand All @@ -26,7 +26,7 @@ func NewSeasonEpisode(metadata *sources.Metadata, coverURL, serverID string) sch
picture := Picture().
SizeRequest(320, 180).
ContentFit(gtk.ContentFitCoverValue).
FromPaintable(gdk.NewTextureFromResource("/dev/skillless/Scanline/icons/scalable/state/missing-album.svg")).
FromPaintable(textures.FromResource("/dev/skillless/Scanline/icons/scalable/state/missing-album.svg")).
ConnectRealize(func(w gtk.Widget) {
if preference.Performance().AllowPreviewImages() {
imageutils.LoadIntoPictureScaled(coverURL, 320, 180, gtk.PictureNewFromInternalPtr(w.Ptr))
Expand Down
4 changes: 2 additions & 2 deletions app/components/widgets/hero.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import (

"codeberg.org/dergs/tonearm/pkg/schwifty"
. "codeberg.org/dergs/tonearm/pkg/schwifty/syntax"
"codeberg.org/puregotk/puregotk/v4/gdk"
"codeberg.org/puregotk/puregotk/v4/glib"
"codeberg.org/puregotk/puregotk/v4/gtk"
"codeberg.org/puregotk/puregotk/v4/pango"
"github.com/0skillallluck/scanline/app/preference"
"github.com/0skillallluck/scanline/app/sources"
"github.com/0skillallluck/scanline/internal/gettext"
"github.com/0skillallluck/scanline/utils/imageutils"
"github.com/0skillallluck/scanline/utils/textures"
)

// linkButtonCSS strips button chrome so it looks like inline text.
Expand Down Expand Up @@ -85,7 +85,7 @@ func HeroSection(poster HeroPosterParams, content schwifty.Box) schwifty.Box {
Picture().
SizeRequest(poster.Width, poster.Height).
ContentFit(gtk.ContentFitCoverValue).
FromPaintable(gdk.NewTextureFromResource("/dev/skillless/Scanline/icons/scalable/state/missing-album.svg")).
FromPaintable(textures.FromResource("/dev/skillless/Scanline/icons/scalable/state/missing-album.svg")).
ConnectRealize(func(w gtk.Widget) {
if preference.Performance().AllowPreviewImages() {
imageutils.LoadIntoPictureScaled(poster.ImageURL, poster.Width, poster.Height, gtk.PictureNewFromInternalPtr(w.Ptr))
Expand Down
5 changes: 2 additions & 3 deletions app/components/widgets/ratings.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (

"codeberg.org/dergs/tonearm/pkg/schwifty"
. "codeberg.org/dergs/tonearm/pkg/schwifty/syntax"
"codeberg.org/puregotk/puregotk/v4/gdk"
"github.com/0skillallluck/scanline/app/sources"
"github.com/0skillallluck/scanline/utils/textures"
)

// RatingsParams contains the rating values for the Ratings component.
Expand Down Expand Up @@ -49,8 +49,7 @@ func Ratings(params RatingsParams) schwifty.Box {
iconPath := ratingIconPath(r.Image)
var icon schwifty.Image
if iconPath != "" {
texture := gdk.NewTextureFromResource(iconPath)
icon = Image().FromPaintable(texture).PixelSize(16)
icon = Image().FromPaintable(textures.FromResource(iconPath)).PixelSize(16)
} else {
// Fallback icons based on type
if r.Type == "critic" {
Expand Down
5 changes: 2 additions & 3 deletions app/pages/cast.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"codeberg.org/puregotk/puregotk/v4/gtk"
"codeberg.org/puregotk/puregotk/v4/pango"
"github.com/0skillallluck/scanline/app/appctx"
"github.com/0skillallluck/scanline/app/components/cards"
"github.com/0skillallluck/scanline/app/components/lists"
"github.com/0skillallluck/scanline/app/preference"
"github.com/0skillallluck/scanline/app/router"
Expand All @@ -32,9 +33,7 @@ func Cast(ctx context.Context, appCtx *appctx.AppContext, serverID, tagID string
return router.FromError(gettext.Get("Cast"), err)
}

coverURL := func(thumb string) string {
return src.PhotoTranscodeURL(thumb, 240, 360)
}
coverURL := cards.PosterCoverURL(src)

var allContent []sources.Metadata
var personName, personThumb string
Expand Down
5 changes: 2 additions & 3 deletions app/pages/genre.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"codeberg.org/puregotk/puregotk/v4/gtk"
"codeberg.org/puregotk/puregotk/v4/pango"
"github.com/0skillallluck/scanline/app/appctx"
"github.com/0skillallluck/scanline/app/components/cards"
"github.com/0skillallluck/scanline/app/components/lists"
"github.com/0skillallluck/scanline/app/router"
"github.com/0skillallluck/scanline/app/sources"
Expand All @@ -30,9 +31,7 @@ func Genre(ctx context.Context, appCtx *appctx.AppContext, serverID, genreID str
return router.FromError(gettext.Get("Genre"), err)
}

coverURL := func(thumb string) string {
return src.PhotoTranscodeURL(thumb, 240, 360)
}
coverURL := cards.PosterCoverURL(src)

var allContent []sources.Metadata
seen := make(map[string]bool)
Expand Down
4 changes: 1 addition & 3 deletions app/pages/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ func home(ctx context.Context, appCtx *appctx.AppContext) *router.Response {
}

serverID := src.ID()
coverURL := func(thumb string) string {
return src.PhotoTranscodeURL(thumb, 240, 360)
}
coverURL := cards.PosterCoverURL(src)

for i := range hubList {
hub := &hubList[i]
Expand Down
5 changes: 2 additions & 3 deletions app/pages/library.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"codeberg.org/puregotk/puregotk/v4/adw"
"codeberg.org/puregotk/puregotk/v4/gtk"
"github.com/0skillallluck/scanline/app/appctx"
"github.com/0skillallluck/scanline/app/components/cards"
"github.com/0skillallluck/scanline/app/components/lists"
"github.com/0skillallluck/scanline/app/router"
"github.com/0skillallluck/scanline/app/sources"
Expand All @@ -32,9 +33,7 @@ func Library(ctx context.Context, appCtx *appctx.AppContext, serverID, sectionID
return router.FromError(section.Title, err)
}

coverURL := func(thumb string) string {
return src.PhotoTranscodeURL(thumb, 240, 360)
}
coverURL := cards.PosterCoverURL(src)

body := WrapBox().
ConnectConstruct(func(w *adw.WrapBox) {
Expand Down
4 changes: 1 addition & 3 deletions app/pages/movie.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,7 @@ func Movie(ctx context.Context, appCtx *appctx.AppContext, serverID, ratingKey s
}

// Related section
coverURL := func(thumb string) string {
return src.PhotoTranscodeURL(thumb, 240, 360)
}
coverURL := cards.PosterCoverURL(src)
for i := range relatedHubs {
hub := &relatedHubs[i]
list := lists.NewHorizontalList(hub.Title)
Expand Down
7 changes: 3 additions & 4 deletions app/pages/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"codeberg.org/puregotk/puregotk/v4/gdk"
"codeberg.org/puregotk/puregotk/v4/gtk"
"github.com/0skillallluck/scanline/app/appctx"
"github.com/0skillallluck/scanline/app/components/cards"
"github.com/0skillallluck/scanline/app/pages/search"
"github.com/0skillallluck/scanline/app/router"
"github.com/0skillallluck/scanline/app/sources"
Expand Down Expand Up @@ -76,10 +77,8 @@ var SearchRoute = router.NewRoute("search", func(ctx context.Context, appCtx *ap
}
srcID := src.ID()
newCached = append(newCached, cachedSource{
hubs: hubs,
coverURL: func(thumb string) string {
return src.PhotoTranscodeURL(thumb, 240, 360)
},
hubs: hubs,
coverURL: cards.PosterCoverURL(src),
serverID: srcID,
})
}
Expand Down
6 changes: 2 additions & 4 deletions app/pages/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func Show(ctx context.Context, appCtx *appctx.AppContext, serverID, ratingKey st
seasonList := lists.NewHorizontalList(gettext.Get("Seasons"))
for i := range seasons {
s := &seasons[i]
seasonList.Append(cards.NewSeasonPoster(s, src.PhotoTranscodeURL(s.Thumb, 240, 360), serverID))
seasonList.Append(cards.NewSeasonPoster(s, src.PhotoTranscodeURL(s.Thumb, cards.PosterWidth, cards.PosterHeight), serverID))
}
body = body.Append(seasonList.SetPageMargin(0))
}
Expand All @@ -121,9 +121,7 @@ func Show(ctx context.Context, appCtx *appctx.AppContext, serverID, ratingKey st
}

// Related section
coverURL := func(thumb string) string {
return src.PhotoTranscodeURL(thumb, 240, 360)
}
coverURL := cards.PosterCoverURL(src)
for i := range relatedHubs {
hub := &relatedHubs[i]
list := lists.NewHorizontalList(hub.Title)
Expand Down
9 changes: 5 additions & 4 deletions app/pages/watchlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ import (

. "codeberg.org/dergs/tonearm/pkg/schwifty/syntax"
"codeberg.org/puregotk/puregotk/v4/adw"
"codeberg.org/puregotk/puregotk/v4/gdk"
"codeberg.org/puregotk/puregotk/v4/glib"
"codeberg.org/puregotk/puregotk/v4/gtk"
"codeberg.org/puregotk/puregotk/v4/pango"
"github.com/0skillallluck/scanline/app/appctx"
"github.com/0skillallluck/scanline/app/components/cards"
"github.com/0skillallluck/scanline/app/preference"
"github.com/0skillallluck/scanline/app/router"
"github.com/0skillallluck/scanline/app/sources"
"github.com/0skillallluck/scanline/internal/gettext"
"github.com/0skillallluck/scanline/utils/imageutils"
"github.com/0skillallluck/scanline/utils/textures"
)

var WatchlistRoute = router.NewRoute("watchlist", watchlist)
Expand Down Expand Up @@ -82,11 +83,11 @@ func watchlistPoster(title, subtitle, thumbURL string, match *sources.WatchlistM
Child(
VStack(
Picture().
SizeRequest(180, 270).
FromPaintable(gdk.NewTextureFromResource("/dev/skillless/Scanline/icons/scalable/state/missing-album.svg")).
SizeRequest(cards.PosterWidth, cards.PosterHeight).
FromPaintable(textures.FromResource("/dev/skillless/Scanline/icons/scalable/state/missing-album.svg")).
ConnectRealize(func(w gtk.Widget) {
if thumbURL != "" && preference.Performance().AllowPreviewImages() {
imageutils.LoadIntoPictureScaled(thumbURL, 180, 270, gtk.PictureNewFromInternalPtr(w.Ptr))
imageutils.LoadIntoPictureScaled(thumbURL, cards.PosterWidth, cards.PosterHeight, gtk.PictureNewFromInternalPtr(w.Ptr))
}
}).
CornerRadius(10).
Expand Down
Loading