Documentation
¶
Overview ¶
Package base holds the behavior of Keel's components without their look: keyboard navigation over a list, type-to-find, multi-selection with ranges, and open/closed state. It draws nothing and depends on no other Keel package. kit builds its components from it; build your own with base for the behavior and el for the look.
Index ¶
- Constants
- func Text(name string, shortcut bool) (string, bool)
- type Disclosure
- type List
- type Selection
- func (s *Selection[K]) Anchor() (K, bool)
- func (s *Selection[K]) Click(order []K, i int, extend, toggle bool, disabled func(int) bool)
- func (s *Selection[K]) Has(k K) bool
- func (s *Selection[K]) In(order []K) []K
- func (s *Selection[K]) Indexes(order []K) []int
- func (s *Selection[K]) Keep(keep func(K) bool)
- func (s *Selection[K]) Len() int
- func (s *Selection[K]) Set(keys ...K)
- type Typeahead
Constants ¶
const TypeaheadPause = time.Second
TypeaheadPause is how long a pause in typing starts a new search.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Disclosure ¶
type Disclosure struct {
OnChange func(open bool)
// contains filtered or unexported fields
}
Disclosure is open/closed state that can be disabled, for popovers, menus, collapsibles and dialogs. OnChange runs only for changes the user makes through Change, not for Set.
func (*Disclosure) Change ¶
func (d *Disclosure) Change(open bool) bool
Change opens or closes as the user asked and calls OnChange if that changed anything. It reports whether it did.
func (*Disclosure) Disabled ¶
func (d *Disclosure) Disabled() bool
func (*Disclosure) Open ¶
func (d *Disclosure) Open() bool
func (*Disclosure) Set ¶
func (d *Disclosure) Set(open bool)
Set opens or closes without calling OnChange. A disabled disclosure stays closed.
func (*Disclosure) SetDisabled ¶
func (d *Disclosure) SetDisabled(on bool)
SetDisabled disables it, which also closes it.
type List ¶
type List struct {
Count int
Disabled func(i int) bool
// Wrap moves from the last item to the first and back, as menus do.
Wrap bool
// Page is how far PageUp and PageDown move; 10 by default.
Page int
}
List navigates Count items, some of which may be disabled. The zero Disabled enables every item. Indexes count from 0; -1 means none.
func (List) Key ¶
Key moves from i for ↑ ↓ Home End PageUp PageDown and reports whether name was one of them. From no item (-1), ↓ goes to the first and ↑ to the last. Disabled items are skipped; a page move that lands on one goes on in the same direction, then back toward i. With nowhere to go it stays at i.
type Selection ¶
type Selection[K comparable] struct { // contains filtered or unexported fields }
Selection is a set of chosen items, keyed so it survives reordering and filtering, with an anchor for Shift ranges. The zero value is empty.
func (*Selection[K]) Anchor ¶
Anchor is where a Shift range starts: the item last clicked without Shift.
func (*Selection[K]) Click ¶
Click applies a click on item i of order, with the platform's rules: a plain click selects only i; toggle (Cmd, or Ctrl off macOS) adds or removes i; extend (Shift) selects from the anchor to i, added to the selection when toggle is also held. Disabled items in a range are skipped. A disabled i changes nothing.
func (*Selection[K]) In ¶
func (s *Selection[K]) In(order []K) []K
In returns the selected keys in the order of order.
type Typeahead ¶
type Typeahead struct {
// contains filtered or unexported fields
}
Typeahead finds an item by the first letters of its label as they are typed, like a native list: typing "re" goes to "Red", and pressing the same letter again cycles through the items that start with it.
func (*Typeahead) Find ¶
func (t *Typeahead) Find(now time.Time, text string, current int, l List, label func(int) string) (int, bool)
Find adds text to the search at time now and returns the enabled item whose label starts with it, searching from the item after current and wrapping. It returns current and false when nothing matches.