Documentation
¶
Overview ¶
Package dropdown provides a stateful dropdown.
Index ¶
- type Select
- func (s *Select) Choose(i int)
- func (s *Select) HoverColor(c properties.Color) *Select
- func (s *Select) Layout(gtx layout.Context) layout.Dimensions
- func (s *Select) ListStyles(st styles.Styles) *Select
- func (s *Select) OnChange(fn func(index int)) *Select
- func (s *Select) Opened() bool
- func (s *Select) Options() []string
- func (s *Select) Selected() int
- func (s *Select) SetOptions(options ...string)
- func (s *Select) SetSelected(i int)
- func (s *Select) Sheet(m SheetMode) *Select
- func (s *Select) Value() string
- type SheetMode
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Select ¶
type Select struct {
// Contextual gives it a context menu (Context).
elements.Contextual
// contains filtered or unexported fields
}
Select is a stateful dropdown. Create it once with New and lay it out every frame.
func New ¶
New returns a Select with the given styles and options: Background is the dropdown background, Color the text, BorderColor the field border, BorderRadius the corners.
func (*Select) Choose ¶
Choose selects option i and invokes OnChange, as picking it from the list would. Out-of-range indexes are ignored.
func (*Select) HoverColor ¶
func (s *Select) HoverColor(c properties.Color) *Select
HoverColor sets the background of the option under the pointer. It returns s for chaining.
func (*Select) Layout ¶
func (s *Select) Layout(gtx layout.Context) layout.Dimensions
Layout lays out the field and, when open, queues the dropdown panel as a portal (see elements.RegisterPortal) anchored just below it, so it paints above everything else regardless of where Layout is called from.
func (*Select) ListStyles ¶
ListStyles styles the open list of options apart from the field: its Background, Color, BorderColor, BorderWidth, BorderRadius and BoxShadow, over the field's. It returns s for chaining.
func (*Select) OnChange ¶
OnChange sets the handler invoked when the selection changes. It returns s for chaining.
func (*Select) SetOptions ¶
SetOptions replaces the options. The selection stays on the same text when it's still among them, and otherwise moves to the first option; OnChange isn't called. An open list shows the new options.
func (*Select) SetSelected ¶
SetSelected changes the selection without invoking OnChange.
type SheetMode ¶
type SheetMode int
SheetMode selects when a Select shows its options as a bottom sheet rather than a list below the field.
const ( // SheetNever always opens the list below the field (the default). SheetNever SheetMode = iota // SheetCompact opens a bottom sheet on compact screens: inside a // Responsive breakpoint named "compact" (see elements.Compact), or // in a window narrower than 600dp. This is the usual phone pattern // for pickers. SheetCompact // SheetAlways always opens a bottom sheet. SheetAlways )