LCOV - code coverage report
Current view: top level - widgets/overlay - detailui.go Coverage Total Hit
Test: coverage.lcov Lines: 100.0 % 48 48
Test Date: 2026-11-19 00:25:22 Functions: - 0 0

            Line data    Source code
       1              : package overlay
       2              : 
       3              : import (
       4              :         "fmt"
       5              :         "image"
       6              : 
       7              :         "github.com/kijimaD/ruins/internal/resources"
       8              :         "github.com/kijimaD/ruins/internal/widgets/entityspec"
       9              :         "github.com/kijimaD/ruins/internal/widgets/pagination"
      10              :         "github.com/kijimaD/ruins/internal/widgets/theme"
      11              :         "github.com/kijimaD/ruins/internal/widgets/uicore"
      12              : )
      13              : 
      14              : // buildPanelsUI は複数の詳細内容を rect 内へ等幅で横並びに組む。各枠は buildPanelUI と
      15              : // 同じ組み方で、枠間は一定の間隔を空ける。
      16              : func buildPanelsUI(res resources.UIResources, rect image.Rectangle, contents []DetailContent, page int) uicore.Widget {
      17            1 :         gap := theme.Space7
      18            1 :         n := len(contents)
      19            1 :         panelW := (rect.Dx() - gap*(n-1)) / n
      20            1 :         panels := make([]uicore.Widget, n)
      21            1 :         for i, c := range contents {
      22            1 :                 x := rect.Min.X + i*(panelW+gap)
      23            1 :                 panelRect := image.Rect(x, rect.Min.Y, x+panelW, rect.Max.Y)
      24            1 :                 panels[i] = buildPanelUI(res, panelRect, c, page)
      25            1 :         }
      26            1 :         group := uicore.NewGroup(panels...)
      27            1 :         group.Layout(rect)
      28            1 :         return group
      29              : }
      30              : 
      31              : // buildPanelUI は詳細内容1件を uicore のツリーとして組み、rect いっぱいに配置して返す。
      32              : // 名前が空なら名前行を省き、説明が空なら説明行を省く。行が多いときは page でページ分割する。
      33              : // 説明は名前の直下に全ページで出し、用途は最終ページにだけ出す。位置表示は1ページでも常に出す。page は範囲外なら内部でクランプする。
      34              : // 背景はパネルテクスチャを rect 全体へ敷き、内容は上寄せにする。
      35              : func buildPanelUI(res resources.UIResources, rect image.Rectangle, content DetailContent, page int) uicore.Widget {
      36            1 :         face := res.Text.BodyFace
      37            1 :         // 説明とページ番号は小さめのフェイスで補助色、名前と性能行は本文フェイスにする。
      38            1 :         smallFace := res.Text.SmallFace
      39            1 :         // 行高は本文フェイスの行送りにする。全行を同じ高さで並べ、いちばん背の高い本文が字面を切らない。
      40            1 :         rowH := uicore.LineHeight(face)
      41            1 : 
      42            1 :         rows := content.Rows
      43            1 :         total := detailPageCount(len(rows))
      44            1 :         if page < 0 {
      45            1 :                 page = 0
      46            1 :         }
      47            1 :         if page >= total {
      48            1 :                 page = total - 1
      49            1 :         }
      50            1 :         pg := pagination.New(page*detailRowsPerPage, len(rows), detailRowsPerPage)
      51            1 :         start, end := pg.GetVisibleRange()
      52            1 : 
      53            1 :         var items []uicore.Widget
      54            1 :         if content.Name != "" {
      55            1 :                 items = append(items, uicore.NewText(content.Name, face, theme.TextPrimary))
      56            1 :         }
      57              :         // 説明はアイテム名の直下に出す。名前と対の見出しなので全ページで示し、性能行の上に置く
      58            1 :         if content.Desc != "" {
      59            1 :                 for _, line := range uicore.WrapText(content.Desc, smallFace, rect.Dx()-theme.Space7*2) {
      60            1 :                         items = append(items, uicore.NewText(line, smallFace, theme.TextSecondary))
      61            1 :                 }
      62              :         }
      63            1 :         items = append(items, entityspec.SpecRowWidgets(rows[start:end], face)...)
      64            1 :         // 用途は性能行の下に出す。ページ送りは性能行の数だけで決めるので用途は数えず、最終ページにまとめて出す
      65            1 :         if page == total-1 {
      66            1 :                 items = append(items, entityspec.SpecRowWidgets(content.Uses, face)...)
      67            1 :         }
      68            1 :         items = append(items, uicore.NewText(fmt.Sprintf("%d/%d", pg.GetCurrentPage(), pg.GetTotalPages()), smallFace, theme.TextSecondary))
      69            1 : 
      70              :         // 内側余白はパネルテクスチャの枠を避けて内容を内側へ寄せる
      71            1 :         panel := uicore.VBox(rowH, items...).SetPadding(theme.Space7)
      72            1 :         panel.SetStyle(uicore.BoxStyle{Fill: theme.PanelBackground, Border: theme.PanelHighlight, BorderWidth: 1, Radius: theme.CornerRadius})
      73            1 :         panel.Layout(rect)
      74            1 :         return panel
      75              : }
        

Generated by: LCOV version 2.0-1