LoadPanelLayout loads a panel layout definition from the datafiles directory. name is relative to the panel-layouts/ subdirectory and has no extension. Example: LoadPanelLayout("character/status")
(name string)
| 644 | // name is relative to the panel-layouts/ subdirectory and has no extension. |
| 645 | // Example: LoadPanelLayout("character/status") |
| 646 | func LoadPanelLayout(name string) (*PanelLayout, error) { |
| 647 | dataFiles := string(configs.GetFilePathsConfig().DataFiles) |
| 648 | path := dataFiles + "/panel-layouts/" + name + ".yaml" |
| 649 | |
| 650 | data, err := os.ReadFile(path) |
| 651 | if err != nil { |
| 652 | return nil, fmt.Errorf("panel layout %q: %w", name, err) |
| 653 | } |
| 654 | |
| 655 | var def panelLayoutDef |
| 656 | if err := yaml.Unmarshal(data, &def); err != nil { |
| 657 | return nil, fmt.Errorf("panel layout %q: %w", name, err) |
| 658 | } |
| 659 | |
| 660 | border := borderFull |
| 661 | if borderStyle(def.Border) == borderOpen { |
| 662 | border = borderOpen |
| 663 | } |
| 664 | |
| 665 | chars := charsetForName(def.Charset) |
| 666 | |
| 667 | gap := def.Gap |
| 668 | if gap < 0 { |
| 669 | gap = 0 |
| 670 | } |
| 671 | |
| 672 | layout := &PanelLayout{ |
| 673 | border: border, |
| 674 | chars: chars, |
| 675 | gap: gap, |
| 676 | margin: def.Margin, |
| 677 | defaultColor: def.DefaultColor, |
| 678 | byID: make(map[string]*Panel), |
| 679 | } |
| 680 | |
| 681 | for _, sd := range def.Slots { |
| 682 | slot := &layoutSlot{} |
| 683 | for _, rd := range sd.Rows { |
| 684 | var rowPanels []*Panel |
| 685 | for _, pd := range rd.Panels { |
| 686 | cols := pd.Columns |
| 687 | if cols < 1 { |
| 688 | cols = 1 |
| 689 | } |
| 690 | colGap := pd.ColumnGap |
| 691 | if colGap < 1 { |
| 692 | colGap = defaultColumnGap |
| 693 | } |
| 694 | panelChars := chars |
| 695 | if pd.Charset != "" { |
| 696 | panelChars = charsetForName(pd.Charset) |
| 697 | } |
| 698 | p := &Panel{ |
| 699 | id: pd.ID, |
| 700 | title: pd.Title, |
| 701 | width: pd.Width, |
| 702 | border: border, |
| 703 | chars: panelChars, |
no test coverage detected