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

            Line data    Source code
       1              : package entityspec
       2              : 
       3              : import (
       4              :         "image/color"
       5              : 
       6              :         text "github.com/hajimehoshi/ebiten/v2/text/v2"
       7              : 
       8              :         "github.com/kijimaD/ruins/internal/widgets/theme"
       9              :         "github.com/kijimaD/ruins/internal/widgets/uicore"
      10              : )
      11              : 
      12              : // specLabelColor はラベルと見出しの色。
      13              : var specLabelColor color.Color = theme.SpecLabel
      14              : 
      15              : // SpecRowWidgets は SpecRow の並びを uicore の行ウィジェット列にする。
      16              : // ラベルは左寄せ、値は右寄せ。見出し行はラベルを行の全幅で描き、色付き行は値をその色で描く。
      17              : // ラベル列の幅は全行の実測から決め、値列が余り幅を吸って行の右端に揃う。幅の数値は持たない。
      18              : // モーダルはこの列に name や desc の行を足して1枚のパネルに組む。
      19              : func SpecRowWidgets(rows []SpecRow, face text.Face) []uicore.Widget {
      20            1 :         labels := make([]int, 0, len(rows))
      21            1 :         for _, r := range rows {
      22            1 :                 if !r.Header {
      23            1 :                         labels = append(labels, uicore.MeasureTextWidth(r.Label, face))
      24            1 :                 }
      25              :         }
      26            1 :         cols := []int{uicore.FitWidth(labels, theme.Space3, 0), 0}
      27            1 : 
      28            1 :         items := make([]uicore.Widget, 0, len(rows))
      29            1 :         for _, r := range rows {
      30            1 :                 if r.Header {
      31            1 :                         items = append(items, uicore.Row([]int{0}, uicore.NewText(r.Label, face, specLabelColor)))
      32            1 :                         continue
      33              :                 }
      34            1 :                 valColor := specLabelColor
      35            1 :                 if r.Color != nil {
      36            1 :                         valColor = r.Color
      37            1 :                 }
      38            1 :                 value := uicore.NewText(r.Value, face, valColor)
      39            1 :                 value.Align = uicore.AlignRight
      40            1 :                 label := uicore.NewText(r.Label, face, specLabelColor)
      41            1 :                 if r.Indent > 0 {
      42              :                         // 子行を段数ぶん下げる。先頭に空の桁を差してラベルだけ右へずらし、値は右端揃えのまま
      43            1 :                         items = append(items, uicore.Row([]int{r.Indent * theme.Space4, cols[0], cols[1]}, uicore.NewGroup(), label, value))
      44            1 :                         continue
      45              :                 }
      46            1 :                 items = append(items, uicore.Row(cols, label, value))
      47              :         }
      48            1 :         return items
      49              : }
      50              : 
      51              : // BuildSpecPanel は SpecRow の並びから uicore の保持型ツリーを組む。
      52              : // 必要なのは本文フェイスだけなのでそれだけを受け取る。行高は渡されたフェイスの行送りにする。
      53              : // 行は文字を収める箱なので、字面を切らない高さはフェイスから導ける。固定値では持たない。
      54              : // パッケージグローバルの可変状態に触れないので、複数の UI を並行に組んでも競合しない。
      55              : func BuildSpecPanel(rows []SpecRow, face text.Face) uicore.Widget {
      56            1 :         return uicore.VBox(uicore.LineHeight(face), SpecRowWidgets(rows, face)...)
      57            1 : }
        

Generated by: LCOV version 2.0-1