Add shared internal UI toolkit for both readers

This commit is contained in:
ak47 committed 2026-11-12 01:27:42 -05:00
1 parent 672caca854
commit e49ba198d7
34 files changed
+3471

No files matched your search

+39
View File
@@ -0,0 +1,39 @@
// 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
}