Documentation
¶
Overview ¶
Package textfield contains Material 3 Text Field components.
Reference: [Text Fields](https://m3.material.io/components/text-fields/overview) Specs: [Text Fields Specs](https://m3.material.io/components/text-fields/specs)
Index ¶
- Constants
- func WithAlpha(c color.NRGBA, a uint8) color.NRGBA
- type C
- type Composable
- type Composer
- type D
- type HandlerWrapper
- type OnSubmitWrapper
- type Progress
- func (p Progress) Absolute() float32
- func (p Progress) Direction() ProgressDirection
- func (p Progress) Finished() bool
- func (p Progress) Progress() float32
- func (p *Progress) Start(began time.Time, direction ProgressDirection, duration time.Duration)
- func (p Progress) Started() bool
- func (p *Progress) Stop()
- func (p *Progress) Update(now time.Time)
- type ProgressDirection
- type TextEditorConstructorArgs
- type TextFieldColors
- type TextFieldComponent
- func (in *TextFieldComponent) Clear()
- func (in *TextFieldComponent) ClearError()
- func (in TextFieldComponent) IsActive() bool
- func (in *TextFieldComponent) IsErrored() bool
- func (in *TextFieldComponent) Layout(gtx C, th *material.Theme, hint string) D
- func (in *TextFieldComponent) SetError(err string)
- func (in *TextFieldComponent) TextTooLong() bool
- func (in *TextFieldComponent) Update(gtx C, th *material.Theme, hint string)
- type TextFieldDecorator
- type TextFieldOption
- func WithColors(colors TextFieldColors) TextFieldOption
- func WithEnabled(enabled bool) TextFieldOption
- func WithError(isError bool) TextFieldOption
- func WithLabel(label string) TextFieldOption
- func WithLeadingIcon(icon Composable) TextFieldOption
- func WithMaxLines(maxLines int) TextFieldOption
- func WithMinLines(minLines int) TextFieldOption
- func WithModifier(m ui.Modifier) TextFieldOption
- func WithOnSubmit(onSubmit func()) TextFieldOption
- func WithPlaceholder(placeholder string) TextFieldOption
- func WithPrefix(prefix Composable) TextFieldOption
- func WithReadOnly(readOnly bool) TextFieldOption
- func WithShape(shape interface{}) TextFieldOption
- func WithSingleLine(singleLine bool) TextFieldOption
- func WithSuffix(suffix Composable) TextFieldOption
- func WithSupportingText(text string) TextFieldOption
- func WithTextStyle(textStyle *text.TextStyle) TextFieldOption
- func WithTrailingIcon(icon Composable) TextFieldOption
- type TextFieldOptions
- type TextFieldStateTracker
- type TextFieldWidget
- func (in *TextFieldWidget) Clear()
- func (in *TextFieldWidget) ClearError()
- func (in *TextFieldWidget) IsActive() bool
- func (in *TextFieldWidget) IsErrored() bool
- func (in *TextFieldWidget) Layout(gtx layout.Context, th *material.Theme, hint string) layout.Dimensions
- func (in *TextFieldWidget) SetError(isError bool, err string)
- func (in *TextFieldWidget) TextTooLong() bool
- type Validator
- type VisibilityAnimation
- func (v VisibilityAnimation) Animating() bool
- func (v *VisibilityAnimation) Appear(now time.Time)
- func (v *VisibilityAnimation) Disappear(now time.Time)
- func (v *VisibilityAnimation) Revealed(gtx layout.Context) float32
- func (v *VisibilityAnimation) String(gtx layout.Context) string
- func (v *VisibilityAnimation) ToggleVisibility(now time.Time)
- func (v VisibilityAnimation) Visible() bool
- type VisibilityAnimationState
Constants ¶
const Material3OutlinedTextFieldNodeID = "Material3OutlinedTextField"
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Composable ¶
type Composable = api.Composable
func Outlined ¶
func Outlined( value string, onValueChange func(string), options ...TextFieldOption, ) Composable
Outlined implements the Outlined Material Design 3 text field. It uses a custom widget implementation adapted from gio-x.
type D ¶
type D = layout.Dimensions
type HandlerWrapper ¶
type HandlerWrapper struct {
Func func(string)
}
type OnSubmitWrapper ¶
type OnSubmitWrapper struct {
Func func()
}
type Progress ¶
type Progress struct {
// contains filtered or unexported fields
}
Progress is an animation primitive that tracks progress of time over a fixed duration as a float between [0, 1].
Progress is reversable.
Widgets map async UI events to state changes: stop, forward, reverse. Widgets then interpolate visual data based on progress value.
Update method must be called every tick to update the progress value.
func (Progress) Direction ¶
func (p Progress) Direction() ProgressDirection
Direction reports the current direction.
type ProgressDirection ¶
type ProgressDirection int
ProgressDirection specifies how to update progress every tick.
const ( // Forward progresses from 0 to 1. Forward ProgressDirection = iota // Reverse progresses from 1 to 0. Reverse )
func (ProgressDirection) String ¶
func (d ProgressDirection) String() string
type TextEditorConstructorArgs ¶
type TextEditorConstructorArgs struct {
Editor *widget.Editor
Value string
Opts TextFieldOptions
Handler *HandlerWrapper
OnSubmitHandler *OnSubmitWrapper
Tracker *TextFieldStateTracker
}
type TextFieldColors ¶
type TextFieldColors struct {
TextColor graphics.Color
DisabledTextColor graphics.Color
CursorColor graphics.Color
ErrorCursorColor graphics.Color
SelectionColor graphics.Color
FocusedIndicatorColor graphics.Color
UnfocusedIndicatorColor graphics.Color
DisabledIndicatorColor graphics.Color
ErrorIndicatorColor graphics.Color
HoveredIndicatorColor graphics.Color
LeadingIconColor graphics.Color
TrailingIconColor graphics.Color
DisabledLeadingIconColor graphics.Color
DisabledTrailingIconColor graphics.Color
LabelColor graphics.Color
UnfocusedLabelColor graphics.Color
DisabledLabelColor graphics.Color
ErrorLabelColor graphics.Color
PlaceholderColor graphics.Color
DisabledPlaceholderColor graphics.Color
SupportingTextColor graphics.Color
DisabledSupportingTextColor graphics.Color
ErrorSupportingTextColor graphics.Color
}
func DefaultTextFieldColors ¶
func DefaultTextFieldColors() TextFieldColors
func ResolveTextFieldColors ¶
func ResolveTextFieldColors(c Composer, colors TextFieldColors) TextFieldColors
type TextFieldComponent ¶
type TextFieldComponent struct {
// Editor contains the edit buffer.
widget.Editor
// Helper text to give additional context to a field.
Helper string
// CharLimit specifies the maximum number of characters the text input
// will allow. Zero means "no limit".
CharLimit uint
// Prefix appears before the content of the text input.
Prefix layout.Widget
// Suffix appears after the content of the text input.
Suffix layout.Widget
// contains filtered or unexported fields
}
TextFieldComponent implements the Material Design Text Field described here: https://material.io/components/text-fields
func (*TextFieldComponent) Clear ¶
func (in *TextFieldComponent) Clear()
Clear the input text and reset any error status.
func (*TextFieldComponent) ClearError ¶
func (in *TextFieldComponent) ClearError()
ClearError clears any errored status.
func (TextFieldComponent) IsActive ¶
func (in TextFieldComponent) IsActive() bool
IsActive if input is in an active state (Active, Focused or Errored).
func (*TextFieldComponent) IsErrored ¶
func (in *TextFieldComponent) IsErrored() bool
IsErrored if input is in an errored state. Typically this is when the validator has returned an error message.
func (*TextFieldComponent) SetError ¶
func (in *TextFieldComponent) SetError(err string)
SetError puts the input into an errored state with the specified error text.
func (*TextFieldComponent) TextTooLong ¶
func (in *TextFieldComponent) TextTooLong() bool
TextTooLong returns whether the current editor text exceeds the set character limit.
type TextFieldDecorator ¶
type TextFieldDecorator struct {
// contains filtered or unexported fields
}
type TextFieldOption ¶
type TextFieldOption func(*TextFieldOptions)
func WithColors ¶
func WithColors(colors TextFieldColors) TextFieldOption
func WithEnabled ¶
func WithEnabled(enabled bool) TextFieldOption
func WithError ¶
func WithError(isError bool) TextFieldOption
func WithLabel ¶
func WithLabel(label string) TextFieldOption
func WithLeadingIcon ¶
func WithLeadingIcon(icon Composable) TextFieldOption
func WithMaxLines ¶
func WithMaxLines(maxLines int) TextFieldOption
func WithMinLines ¶
func WithMinLines(minLines int) TextFieldOption
func WithModifier ¶
func WithModifier(m ui.Modifier) TextFieldOption
func WithOnSubmit ¶
func WithOnSubmit(onSubmit func()) TextFieldOption
func WithPlaceholder ¶
func WithPlaceholder(placeholder string) TextFieldOption
func WithPrefix ¶
func WithPrefix(prefix Composable) TextFieldOption
func WithReadOnly ¶
func WithReadOnly(readOnly bool) TextFieldOption
func WithShape ¶
func WithShape(shape interface{}) TextFieldOption
func WithSingleLine ¶
func WithSingleLine(singleLine bool) TextFieldOption
func WithSuffix ¶
func WithSuffix(suffix Composable) TextFieldOption
func WithSupportingText ¶
func WithSupportingText(text string) TextFieldOption
func WithTextStyle ¶
func WithTextStyle(textStyle *text.TextStyle) TextFieldOption
func WithTrailingIcon ¶
func WithTrailingIcon(icon Composable) TextFieldOption
type TextFieldOptions ¶
type TextFieldOptions struct {
Modifier ui.Modifier
Enabled bool
ReadOnly bool
TextStyle *text.TextStyle
Label string //maybe.Maybe[api.Composable]
Placeholder string //maybe.Maybe[api.Composable]
LeadingIcon api.Composable
TrailingIcon api.Composable
Prefix api.Composable
Suffix api.Composable
SupportingText string //maybe.Maybe[api.Composable]
IsError bool
SingleLine bool
MaxLines int
MinLines int
Shape interface{}
Colors TextFieldColors
OnSubmit func() // Called when Enter is pressed (SingleLine mode)
}
func DefaultTextFieldOptions ¶
func DefaultTextFieldOptions() TextFieldOptions
type TextFieldStateTracker ¶
type TextFieldStateTracker struct {
LastValue string
}
type TextFieldWidget ¶
type TextFieldWidget struct {
// Editor contains the edit buffer.
Editor *widget.Editor
// Helper text to give additional context to a field.
Helper string
// CharLimit specifies the maximum number of characters the text input
// will allow. Zero means "no limit".
CharLimit uint
// Prefix appears before the content of the text input.
Prefix layout.Widget
// Suffix appears after the content of the text input.
Suffix layout.Widget
Colors TextFieldColors
// contains filtered or unexported fields
}
TextField implements the Material Design Text Field described here: https://material.io/components/text-fields
func (*TextFieldWidget) Clear ¶
func (in *TextFieldWidget) Clear()
Clear the input text and reset any error status.
func (*TextFieldWidget) ClearError ¶
func (in *TextFieldWidget) ClearError()
ClearError clears any errored status.
func (*TextFieldWidget) IsActive ¶
func (in *TextFieldWidget) IsActive() bool
IsActive if input is in an active state (Active, Focused or Errored).
func (*TextFieldWidget) IsErrored ¶
func (in *TextFieldWidget) IsErrored() bool
IsErrored if input is in an errored state. Typically this is when the validator has returned an error message.
func (*TextFieldWidget) Layout ¶
func (in *TextFieldWidget) Layout(gtx layout.Context, th *material.Theme, hint string) layout.Dimensions
func (*TextFieldWidget) SetError ¶
func (in *TextFieldWidget) SetError(isError bool, err string)
SetError puts the input into an errored state with the specified error text.
func (*TextFieldWidget) TextTooLong ¶
func (in *TextFieldWidget) TextTooLong() bool
TextTooLong returns whether the current editor text exceeds the set character limit.
type Validator ¶
Validator validates text and returns a string describing the error. Error is displayed as helper text.
type VisibilityAnimation ¶
type VisibilityAnimation struct {
// How long does the animation last
time.Duration
State VisibilityAnimationState
Started time.Time
}
VisibilityAnimation holds the animation state for animations that transition between a "visible" and "invisible" state for a fixed duration of time.
func (VisibilityAnimation) Animating ¶
func (v VisibilityAnimation) Animating() bool
Animating() returns whether the animation is either in the process of appearsing or disappearing.
func (*VisibilityAnimation) Appear ¶
func (v *VisibilityAnimation) Appear(now time.Time)
Appear triggers the animation to begin becoming visible at the provided time. It is a no-op if the animation is already visible.
func (*VisibilityAnimation) Disappear ¶
func (v *VisibilityAnimation) Disappear(now time.Time)
Disappear triggers the animation to begin becoming invisible at the provided time. It is a no-op if the animation is already invisible.
func (*VisibilityAnimation) Revealed ¶
func (v *VisibilityAnimation) Revealed(gtx layout.Context) float32
Revealed returns the fraction of the animated entity that should be revealed at the current time in the animation. This fraction is computed with linear interpolation.
Revealed should be invoked during every frame that v.Animating() returns true.
If the animation reaches its end this frame, Revealed will transition it to a non-animating state automatically.
If the animation is in the process of animating, calling Revealed will automatically add an InvalidateOp to the provided layout.Context to ensure that the next frame will be generated promptly.
func (*VisibilityAnimation) String ¶
func (v *VisibilityAnimation) String(gtx layout.Context) string
func (*VisibilityAnimation) ToggleVisibility ¶
func (v *VisibilityAnimation) ToggleVisibility(now time.Time)
ToggleVisibility will make an invisible animation begin the process of becoming visible and a visible animation begin the process of disappearing.
func (VisibilityAnimation) Visible ¶
func (v VisibilityAnimation) Visible() bool
Visible() returns whether any part of the animated entity should be visible during the current animation frame.
type VisibilityAnimationState ¶
type VisibilityAnimationState int
VisibilityAnimationState represents possible states that a VisibilityAnimation can be in.
const ( Visible VisibilityAnimationState = iota Disappearing Appearing Invisible )
func (VisibilityAnimationState) String ¶
func (v VisibilityAnimationState) String() string