Merge branch 'dev' into search-proclamations

This commit is contained in:
NeilClack
2026-03-31 09:14:54 -05:00
+24 -6
View File
@@ -110,13 +110,19 @@ func (p *ProclamationOptions) Init(ctx *PageCtx) error {
func (p *ProclamationOptions) createFlatItem(name, id string, isCat bool, depth int) *FlatItem {
text := name
if isCat {
if isCat && depth == 0 {
text = "[+] " + name
}
itemScale := float32(32) / float32(p.Context.CfgPtr.StandardFontSize)
lbl, _ := NewStringItem(text, p.font, colors.White)
lbl.Scale(itemScale)
return &FlatItem{Label: lbl, ID: id, IsCategory: isCat, Depth: depth}
return &FlatItem{
Label: lbl,
ID: id,
IsCategory: isCat,
IsSubCategory: isCat && depth > 0,
Depth: depth,
}
}
func (p *ProclamationOptions) layout() {
@@ -143,8 +149,8 @@ func (p *ProclamationOptions) layout() {
func (p *ProclamationOptions) toggleExpansion(index int) {
item := p.allItems[index]
if !item.IsCategory {
return
if !item.IsCategory || item.IsSubCategory {
return // Subcategories are never manually toggled
}
pureName := item.Label.content[4:]
@@ -171,7 +177,9 @@ func (p *ProclamationOptions) expand(index int) {
var cats []db.ProclamationCategory
p.Context.DbPtr.Where("parent_id = ?", parentID).Find(&cats)
for _, c := range cats {
newItems = append(newItems, p.createFlatItem(c.Name, fmt.Sprint(c.ID), true, parent.Depth+1))
fi := p.createFlatItem(c.Name, fmt.Sprint(c.ID), true, parent.Depth+1)
fi.Expanded = true // Mark expanded so collapse state is consistent
newItems = append(newItems, fi)
}
var procs []db.Proclamation
@@ -182,6 +190,16 @@ func (p *ProclamationOptions) expand(index int) {
tail := append([]*FlatItem{}, p.allItems[index+1:]...)
p.allItems = append(p.allItems[:index+1], append(newItems, tail...)...)
// Auto-expand any subcategories just inserted
// Walk forward: for each newly inserted category, expand it in-place
i := index + 1
for i < len(p.allItems) && p.allItems[i].Depth > parent.Depth {
if p.allItems[i].IsCategory && p.allItems[i].Depth > 0 {
p.expand(i) // Recurse — inserts children in-place, loop will walk into them
}
i++
}
}
func (p *ProclamationOptions) collapse(index int) {
@@ -235,7 +253,7 @@ func (p *ProclamationOptions) HandleEvent(event *sdl.Event) error {
item := p.allItems[p.highlightIndex]
if !item.IsCategory {
p.activeMap[item.ID] = !p.activeMap[item.ID]
} else {
} else if !item.IsSubCategory {
p.toggleExpansion(p.highlightIndex)
}
case sdl.K_BACKSPACE, sdl.K_ESCAPE: