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
4 changes: 3 additions & 1 deletion internal/mobileui/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,9 @@ func (s *shell) mobileSearchHistoryView(c *ui.Context, state *mobileSearchState)
s.saveMobileSearchHistory(&state.history)
}
})
ui.ScrollHorizontal(c.Key("search:history")).FillWidth().Gap(8).Children(func() {
ui.ScrollHorizontal(c.Key("search:history")).FillWidth().Height(touchSize()+8).
Gap(8).Padding(0, 0, 8, 0).
ScrollbarStyle(ui.ScrollbarStyle{TrackWidth: 6, ThumbWidth: 6, MinLength: 24}).Children(func() {
for _, word := range state.history.words {
ui.Row(c).Key("history:" + word).MinHeight(touchSize()).Shrink(0).Radius(24).Background(palette.Surface2).Children(func() {
if ui.ButtonBase(c).Label(word).Padding(0, 0, 0, 10).Children(func() {
Expand Down
16 changes: 8 additions & 8 deletions internal/ui/homepage.go
Original file line number Diff line number Diff line change
Expand Up @@ -593,15 +593,15 @@ func (h *homePage) rail(c *ui.Context, songs []list.Music, inner float32, s *She
pad := homeLayoutFor(h.win).pad
ui.ScrollHorizontal(c).Key("home:rail").Width(inner+2*pad).Gap(space.Px20).
Margin(space.None, -pad, space.None, -pad).Padding(space.None, pad, space.Px8, pad).
Children(func() {
for i, m := range songs {
ev := pud.CoverCard(c, "home:recent:card:"+m.ID, h.cleanTitle(m.Title),
m.Owner, homeRailCardW, h.coverOf(m.Cover), h.isCur(m))
if ev.Open || ev.Play {
h.playFrom(s, songs, i)
}
ScrollbarStyle(horizontalRailScrollbarStyle()).Children(func() {
for i, m := range songs {
ev := pud.CoverCard(c, "home:recent:card:"+m.ID, h.cleanTitle(m.Title),
m.Owner, homeRailCardW, h.coverOf(m.Cover), h.isCur(m))
if ev.Open || ev.Play {
h.playFrom(s, songs, i)
}
})
}
})
}

// skeletonRail 是 rail 的骨架。
Expand Down
8 changes: 6 additions & 2 deletions internal/ui/homepage_artists.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ func (h *homePage) viewHotArtists(c *ui.Context, s *Shell) {
}
h.section(c, func() {
pud.SecHead(c, "home:artists", "热门歌手", "来自本周热榜", "")
ui.ScrollHorizontal(c).Key("home:artists:rail").FillWidth().Gap(space.Px24).Children(func() {
ui.ScrollHorizontal(c).Key("home:artists:rail").FillWidth().Height(avatarSize+38).
Gap(space.Px24).Padding(space.None, space.None, space.Px12, space.None).
ScrollbarStyle(horizontalRailScrollbarStyle()).Children(func() {
for _, name := range artists {
name := name
button := ui.ButtonBase(c).Key("home:artist:" + name).Label("搜索 " + name).Width(itemWidth).Shrink(0).AlignItems(ui.Center).Radius(tok.R12)
Expand All @@ -78,7 +80,9 @@ func (h *homePage) skeletonArtists(c *ui.Context) {
if h.win <= 760 {
itemWidth, avatarSize = 100, 84
}
ui.ScrollHorizontal(c).Key("home:artists:sk:rail").FillWidth().Gap(space.Px24).Children(func() {
ui.ScrollHorizontal(c).Key("home:artists:sk:rail").FillWidth().Height(avatarSize+38).
Gap(space.Px24).Padding(space.None, space.None, space.Px12, space.None).
ScrollbarStyle(horizontalRailScrollbarStyle()).Children(func() {
// 6 是这一排的上限(`hotArtists` 取到 6 就停)。
for i := 0; i < 6; i++ {
ui.Column(c).Key(fmt.Sprintf("home:artist:sk:%d", i)).Width(itemWidth).Shrink(0).
Expand Down
6 changes: 6 additions & 0 deletions internal/ui/scrollbar.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
package ui

import "github.com/egoist/mygo/ui"

// scrollbarWidth 是滚动条的宽,照上游 `--os-size: 10px`。
const scrollbarWidth = 10

// scrollbarGutter 是滚动条轨道盖住的那条竖带。v0.9.0 的
// `ScrollbarStyle.Resolve` 把轨道宽定成 thumb + 6;内容要让开它,否则悬停时被盖住。
const scrollbarGutter = scrollbarWidth + 6

func horizontalRailScrollbarStyle() ui.ScrollbarStyle {
return ui.ScrollbarStyle{TrackWidth: 6, ThumbWidth: 6, MinLength: 24}
}
74 changes: 60 additions & 14 deletions internal/ui/search_creators.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/ShellMonster/PudMusic/internal/app"
"github.com/ShellMonster/PudMusic/internal/ui/widgets/imgcache"
"github.com/ShellMonster/PudMusic/internal/ui/widgets/list"
"github.com/ShellMonster/PudMusic/internal/ui/widgets/pud"
"github.com/ShellMonster/PudMusic/internal/ui/widgets/scale"
"github.com/ShellMonster/PudMusic/internal/ui/widgets/space"
Expand Down Expand Up @@ -40,6 +41,10 @@ type creatorPreview struct {
pageValid bool
}

// verificationBadgeRadius keeps the certification badge circular while matching
// its 21px diameter.
const verificationBadgeRadius = 10.5

// storePage 记下预览那一次请求的整页(`uniqueCreators` 截断之前的那一份)。
func (p *creatorPreview) storePage(keyword string, page app.SearchPage) {
p.pageMu.Lock()
Expand Down Expand Up @@ -146,19 +151,35 @@ func creatorRetryAvailable(err error) bool {
return !ok || searchErr.Retryable
}

// viewSearchCreators 画搜索页头那一排相关 UP 主,返回 true 表示这一帧占了页头。
//
// 预览还在路上时画页头 + 骨架:结果回来时页头几何不变(同一支
// `pud.PageHeadFnEyebrow`),只有骨架换成真人,下面的 Tab 不会往下跳。没有匹配用户
// (空结果 / 失败)时返回 false,由调用方画普通的「搜索结果」页头。
func (s *Shell) viewSearchCreators(c *ui.Context, keyword string, winW float32) bool {
func (s *Shell) searchCreatorLead(keyword string, tab int) *list.Lead {
p := &s.search.creators
pg := s.search.lists[tab].list.Paged()
if p.keyword != keyword || (len(p.items) == 0 && p.result == nil) {
return false
return nil
}
if pg.Loaded == 0 && !pg.Loading {
return nil
Comment on lines +160 to +161

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: When the selected tab finishes with zero rows, this rejects the lead even if the creator preview has results, hiding the creator rail behind the empty state.

Assessment: 🟠 Major · 🔁 Occurrence: Sometimes · 🏷️ Incorrect condition logic

Use CodeAnt Skill Fix in Cursor Fix in VSCode Claude

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** internal/ui/search_creators.go
**Line:** 160:161
**Comment:**
	*Incorrect Condition Logic: When the selected tab finishes with zero rows, this rejects the lead even if the creator preview has results, hiding the creator rail behind the empty state.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

}
return &list.Lead{
Label: "搜索结果页头",
Height: func() float32 {
if tab == searchTabUser {
return 300
}
return 340
},
Draw: func(c *ui.Context) {
s.viewSearchLead(c, keyword, tab)
},
}
}

func (s *Shell) viewSearchLead(c *ui.Context, keyword string, tab int) {
winW, _ := c.Size()
ty := tok.Of(c.Theme())
p := &s.search.creators

pud.PageHeadFnEyebrow(c, func() {
// 关键词原样画:`typo.Eyebrow` 会转全大写,搜索词的大小写是有意义的。
typo.EyebrowText(c, "搜索「"+keyword+"」").SingleLine().Ellipsis("…")
}, "相关 UP 主", winW, nil, func() {
if ui.ButtonBase(c).Label("查看全部 UP 主").Padding(space.Px8).Children(func() {
Expand All @@ -169,10 +190,33 @@ func (s *Shell) viewSearchCreators(c *ui.Context, keyword string, winW float32)
})
if len(p.items) == 0 {
s.viewCreatorSkeleton(c)
return true
} else {
s.viewCreatorRail(c, p.items)
}
ui.ScrollHorizontal(c).Key("search:creators").FillWidth().Gap(space.Px16).Margin(space.Px16, space.None, space.None, space.None).Children(func() {
for _, item := range p.items {

ui.Column(c).FillWidth().Margin(space.Px12, space.None, space.None, space.None).Children(func() {
tabs := make([]pud.Tab, searchTabCount)
for i := range tabs {
tabs[i] = pud.Tab{Label: searchTabLabels[i], Count: s.searchTabCountText(i)}
}
pud.Tabs(c, "search:tabs", &s.search.tab, tabs)
})
s.viewSearchToolbar(c, tab)

t := &s.search.lists[tab]
if t.list.Layout() != list.ViewCard && tab != searchTabUser && t.list.Paged().Loaded > 0 {
ui.Box(c).Height(space.Px8)
t.list.Header(c, "search:header:"+fmt.Sprint(tab))
}
}

func (s *Shell) viewCreatorRail(c *ui.Context, items []app.SearchItem) {
ty := tok.Of(c.Theme())
ui.ScrollHorizontal(c).Key("search:creators").FillWidth().Height(112).
Gap(space.Px16).Padding(space.None, space.None, space.Px16, space.None).
Margin(space.Px16, space.None, space.None, space.None).
ScrollbarStyle(horizontalRailScrollbarStyle()).Children(func() {
for _, item := range items {
item := item
button := ui.ButtonBase(c).Key("search:creator:" + item.Item.Bvid).Label("打开 " + item.Title + " 的空间").Width(116).Shrink(0).
AlignItems(ui.Center).Radius(tok.R8)
Expand All @@ -197,7 +241,7 @@ func (s *Shell) viewSearchCreators(c *ui.Context, keyword string, winW float32)
if item.Verification == app.SearchVerificationOrganization {
color, label = ui.RGB(48, 142, 204), "机构认证"
}
ui.Box(c).Absolute().Right(0).Bottom(0).Size(21, 21).Radius(10.5).Background(color).Border(2, ty.Bg).Center().Label(label).Children(func() { ui.Text(c, "V").FontSize(11).TextColor(ui.RGB(255, 255, 255)) })
ui.Box(c).Absolute().Right(0).Bottom(0).Size(21, 21).Radius(verificationBadgeRadius).Background(color).Border(2, ty.Bg).Center().Label(label).Children(func() { ui.Text(c, "V").FontSize(11).TextColor(ui.RGB(255, 255, 255)) })
}
})
ui.Text(c, item.Title).FontSize(scale.Font(c, scale.Size13)).TextColor(ty.Text).SingleLine().Ellipsis("…")
Expand All @@ -207,13 +251,15 @@ func (s *Shell) viewSearchCreators(c *ui.Context, keyword string, winW float32)
}
}
})
return true
}

// viewCreatorSkeleton 是相关 UP 主那一排在预览路上的样子:几何和真的一模一样
// (头像 72、项宽 116、缝 16、上边距 16),所以结果回来时下面的 Tab 不动。
func (s *Shell) viewCreatorSkeleton(c *ui.Context) {
ui.ScrollHorizontal(c).Key("search:creators:sk").FillWidth().Gap(space.Px16).Margin(space.Px16, space.None, space.None, space.None).Children(func() {
ui.ScrollHorizontal(c).Key("search:creators:sk").FillWidth().Height(112).
Gap(space.Px16).Padding(space.None, space.None, space.Px16, space.None).
Margin(space.Px16, space.None, space.None, space.None).
ScrollbarStyle(horizontalRailScrollbarStyle()).Children(func() {
for i := 0; i < 8; i++ {
ui.Column(c).Key(fmt.Sprintf("search:creator:sk:%d", i)).Width(116).Shrink(0).
AlignItems(ui.Center).Gap(space.Px8).Children(func() {
Expand Down
20 changes: 20 additions & 0 deletions internal/ui/search_creators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,26 @@ func TestSearchCreatorHeaderKeepsPageGeometry(t *testing.T) {
}
}

// TestSearchCreatorPreviewScrollsWithResults locks the related creator strip inside the
// result list instead of leaving it fixed above the scrolling rows.
func TestSearchCreatorPreviewScrollsWithResults(t *testing.T) {
s, tt := newSearchPage(t, "音乐", newSearchStub(24, 24), at(1200, 800))
s.search.creators.fetch = func(context.Context, string) ([]app.SearchItem, error) {
return []app.SearchItem{creatorItem("42", "滚动测试UP", "", 0)}, nil
}
waitFrames(t, tt, "滚动测试UP出现", func() bool { return tt.HasText("滚动测试UP") })
before, ok := tt.Find("滚动测试UP")
if !ok {
t.Fatal("画面上找不到相关 UP 主")
}
tt.Scroll(700, 400, 0, 300)
tt.Frame()
after, ok := tt.Find("滚动测试UP")
if ok && after.Y >= before.Y-100 {
t.Fatalf("滚动 300 后相关 UP 主仍固定在原位,y 从 %.1f 变成 %.1f", before.Y, after.Y)
}
}

// TestSearchCreatorKeywordKeepsItsCase locks that the eyebrow shows the keyword as
// typed: `typo.Eyebrow` upper-cases, and 「Taylor Swift」 used to render as
// 「TAYLOR SWIFT」.
Expand Down
42 changes: 22 additions & 20 deletions internal/ui/searchpage.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,11 @@ func (s *Shell) viewSearchResults(c *ui.Context, keyword string, winW float32) {
st := &s.search

ui.Column(c).Key("search:results").Grow(1).AlignItems(ui.Stretch).Children(func() {
hasCreators := s.viewSearchCreators(c, keyword, winW)
cur := st.tab
lead := s.searchCreatorLead(keyword, cur)
st.lists[cur].list.SetLead(lead)

hasCreators := lead != nil
if !hasCreators {
pud.PageHead(c, "搜索结果", "「"+keyword+"」", "", winW, nil)
if p := &s.search.creators; p.keyword == keyword && creatorRetryAvailable(p.err) {
Expand All @@ -223,26 +227,24 @@ func (s *Shell) viewSearchResults(c *ui.Context, keyword string, winW float32) {
}
}

// 🔴 **Tab 要在 `current` 之前画**:它是建到的时候才写 `st.tab`(理由见 `mygo/ui` 的
// `tabsParts.Tab`);顺序反过来的表现是点了 Tab 画面先抖一下才换。
tabGap := float32(space.Px32)
if hasCreators {
tabGap = space.Px12
if !hasCreators {
// 🔴 **Tab 要在 `current` 之前画**:它是建到的时候才写 `st.tab`(理由见 `mygo/ui` 的
// `tabsParts.Tab`);顺序反过来的表现是点了 Tab 画面先抖一下才换。
ui.Column(c).FillWidth().Margin(space.Px32, space.None, space.None, space.None).Children(func() {
tabs := make([]pud.Tab, searchTabCount)
for i := range tabs {
tabs[i] = pud.Tab{Label: searchTabLabels[i], Count: s.searchTabCountText(i)}
}
pud.Tabs(c, "search:tabs", &st.tab, tabs)
})
s.viewSearchToolbar(c, cur)
}
ui.Column(c).FillWidth().Margin(tabGap, space.None, space.None, space.None).Children(func() {
tabs := make([]pud.Tab, searchTabCount)
for i := range tabs {
tabs[i] = pud.Tab{Label: searchTabLabels[i], Count: s.searchTabCountText(i)}
}
pud.Tabs(c, "search:tabs", &st.tab, tabs)
})
cur := st.tab
s.viewSearchToolbar(c, cur)

// 🔴 换查询 → 重置到第 1 页(理由见 searchTab.current)。
cur = st.tab
st.lists[cur].current(searchQuerySpec{keyword: keyword, sort: st.sorts[cur]}, &st.scroll)

s.viewSearchResultsBody(c, cur, keyword)
lead = s.searchCreatorLead(keyword, cur)
st.lists[cur].list.SetLead(lead)
s.viewSearchResultsBody(c, cur, keyword, lead != nil)
})
}

Expand Down Expand Up @@ -297,7 +299,7 @@ func (s *Shell) viewSearchToolbar(c *ui.Context, tab int) {
//
// ⚠️ **加载的时候列表照画,不 return**:后台回来的结果是在列表的 `View` 里收的
// (`adopt`),不画它这一页就永远停在「正在加载」。
func (s *Shell) viewSearchResultsBody(c *ui.Context, tab int, keyword string) {
func (s *Shell) viewSearchResultsBody(c *ui.Context, tab int, keyword string, lead bool) {
t := &s.search.lists[tab]
pg := t.list.Paged()

Expand Down Expand Up @@ -354,7 +356,7 @@ func (s *Shell) viewSearchResultsBody(c *ui.Context, tab int, keyword string) {
// `searchHeaderSpec`。
winW, _ := c.Size()
t.list.SetAlbumMode(pud.AlbumModeFor(winW))
if v := t.list.Layout(); v != list.ViewCard && tab != searchTabUser {
if !lead && t.list.Layout() != list.ViewCard && tab != searchTabUser {
ui.Box(c).Height(space.Px8)
t.list.Header(c, "search:header:"+strconv.Itoa(tab))
}
Expand Down
4 changes: 3 additions & 1 deletion internal/ui/settings_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,9 @@ func (s *Shell) settingsNav(c *ui.Context, p tok.Palette, stacked bool) {
var nav ui.Element
iconGap := float32(space.Px10)
if stacked {
nav = ui.ScrollHorizontal(c).Key("set-nav").FillWidth().Gap(space.Px8)
nav = ui.ScrollHorizontal(c).Key("set-nav").FillWidth().Height(52).
Gap(space.Px8).Padding(space.None, space.None, space.Px8, space.None).
ScrollbarStyle(horizontalRailScrollbarStyle())
iconGap = space.Px8
} else {
nav = ui.Column(c).Key("set-nav").Width(setNavW).Shrink(0).Gap(space.Px2)
Expand Down