40 lines
1.4 KiB
Go
40 lines
1.4 KiB
Go
// Copyright (c) 2026 Storm Dragon
|
|
// Authors: Storm Dragon, Angus Kola
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
package interaction
|
|
|
|
import (
|
|
"errors"
|
|
ui "git.stormux.org/storm/screenreader-common/internalui"
|
|
)
|
|
|
|
type GridTab struct {
|
|
ID, Label string
|
|
Items []Item
|
|
}
|
|
|
|
func NewGridSession(title string, tabs []GridTab, columns int, checkbox Element) (*Session, error) {
|
|
if title == "" || len(tabs) == 0 || columns < 1 || columns > 64 || checkbox.Kind != CheckBox || checkbox.ID == "" || checkbox.Label == "" {
|
|
return nil, errors.New("invalid tabbed grid")
|
|
}
|
|
form := ui.Form{Type: ui.TabForm, Title: title, Detailed: true}
|
|
for _, tab := range tabs {
|
|
choices := make([]ui.Choice, 0, len(tab.Items))
|
|
for _, item := range tab.Items {
|
|
if item.ID == "" {
|
|
return nil, errors.New("invalid grid item")
|
|
}
|
|
choices = append(choices, ui.Choice{ID: item.ID, Label: item.Label, Disabled: item.Disabled, Literal: true})
|
|
}
|
|
form.Tabs = append(form.Tabs, ui.Tab{ID: tab.ID, Label: tab.Label, Controls: []ui.Control{
|
|
{ID: "grid", Label: "Grid", Kind: ui.Grid, Choices: choices, Columns: columns, Action: "select-grid-item"},
|
|
{ID: checkbox.ID, Label: checkbox.Label, Kind: ui.CheckBox, Checked: checkbox.Checked},
|
|
}})
|
|
}
|
|
core, err := ui.NewSession(form, ui.Messages{})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &Session{core: core, title: title, grid: true, checkbox: checkbox.ID}, nil
|
|
}
|