view

– import “gomatcha.io/matcha/view”

Package view provides the component library. See https://gomatcha.io/guide/view/ for more details.

func Alert

func Alert(title, message string, buttons ...*AlertButton)

Alert displays an alert with the given title, message and buttons. If no buttons are passed, a default OK button is created.

func CopyFields

func CopyFields(dst, src View)

Copy all public fields from src to dst, that aren’t ‘Embed’.

func EntersStage

func EntersStage(from, to, s Stage) bool

EntersStage returns true if from﹤s and to≥s.

func ExitsStage

func ExitsStage(from, to, s Stage) bool

ExitsStage returns true if from≥s and to﹤s.

type AlertButton

type AlertButton struct {
	Title   string
	OnPress func()
}

AlertButton represents an alert button.

type BasicView

type BasicView struct {
	Embed
	Painter  paint.Painter
	Layouter layout.Layouter
	Children []View
}

func NewBasicView

func NewBasicView() *BasicView

NewBasicView returns a new view.

func (*BasicView) Build

func (v *BasicView) Build(ctx Context) Model

Build implements view.View.

type Button

type Button struct {
	Embed
	String     string
	Color      color.Color
	OnPress    func()
	Enabled    bool
	PaintStyle *paint.Style
}

Button implements a native button view.

func NewButton

func NewButton() *Button

NewButton returns a new view.

func (*Button) Build

func (v *Button) Build(ctx Context) Model

Build implements view.View.

type Context

type Context interface {
	Path() []Id
}

type Embed

type Embed struct {
	Key interface{}
}

Embed is a convenience struct that provides a default implementation of View. It also wraps a comm.Relay.

func NewEmbed

func NewEmbed(key interface{}) Embed

func (*Embed) Build

func (e *Embed) Build(ctx Context) Model

Build is an empty implementation of View’s Build method.

func (*Embed) Lifecycle

func (e *Embed) Lifecycle(from, to Stage)

Lifecycle is an empty implementation of View’s Lifecycle method.

func (*Embed) Notify

func (e *Embed) Notify(f func()) comm.Id

Notify calls Notify(id) on the underlying comm.Relay.

func (*Embed) Signal

func (e *Embed) Signal()

Update calls Signal() on the underlying comm.Relay.

func (*Embed) Subscribe

func (e *Embed) Subscribe(n comm.Notifier)

Subscribe calls Subscribe(n) on the underlying comm.Relay.

func (*Embed) Unnotify

func (e *Embed) Unnotify(id comm.Id)

Unnotify calls Unnotify(id) on the underlying comm.Relay.

func (*Embed) Unsubscribe

func (e *Embed) Unsubscribe(n comm.Notifier)

Unsubscribe calls Unsubscribe(n) on the underlying comm.Relay.

func (*Embed) Update

func (e *Embed) Update(v View)

Update is an empty implementation of View’s Update method.

func (*Embed) ViewKey

func (e *Embed) ViewKey() interface{}

type Id

type Id int64

type ImageButton

type ImageButton struct {
	Embed
	Image      image.Image
	OnPress    func()
	PaintStyle *paint.Style
}

func NewImageButton

func NewImageButton() *ImageButton

func (*ImageButton) Build

func (v *ImageButton) Build(ctx Context) Model

type ImageResizeMode

type ImageResizeMode int
const (
	// The image is resized proportionally such that a single axis is filled.
	ImageResizeModeFit ImageResizeMode = iota
	// The image is resized proportionally such that the entire view is filled.
	ImageResizeModeFill
	// The image is stretched to fill the view.
	ImageResizeModeStretch
	// The image is centered in the view with its natural size.
	ImageResizeModeCenter
)

TODO(KD): ResizeModeFit and ResizeModeFill behave oddly on Android.

func (ImageResizeMode) MarshalProtobuf

func (m ImageResizeMode) MarshalProtobuf() pbview.ImageResizeMode

type ImageView

type ImageView struct {
	Embed
	Image      image.Image
	URL        string
	ResizeMode ImageResizeMode
	ImageTint  color.Color
	PaintStyle *paint.Style
}

ImageView implements a view that displays an image.

func NewImageView

func NewImageView() *ImageView

NewImageView returns a new view.

func (*ImageView) Build

func (v *ImageView) Build(ctx Context) Model

Build implements view.View.

func (*ImageView) Lifecycle

func (v *ImageView) Lifecycle(from, to Stage)

Lifecycle implements view.View.

func (*ImageView) Update

func (v *ImageView) Update(v2 View)

type Model

type Model struct {
	Children []View
	Layouter layout.Layouter
	Painter  paint.Painter
	Options  []Option

	NativeViewName  string
	NativeViewState []byte
	NativeOptions   map[string][]byte
	NativeFuncs     map[string]interface{}
}

Model describes the view and its children.

type Option

type Option interface {
	OptionKey() string
}

type ScrollPosition

type ScrollPosition struct {
	X animate.Value
	Y animate.Value
}

func (*ScrollPosition) Notify

func (p *ScrollPosition) Notify(f func()) comm.Id

func (*ScrollPosition) SetValue

func (p *ScrollPosition) SetValue(val layout.Point)

func (*ScrollPosition) Unnotify

func (p *ScrollPosition) Unnotify(id comm.Id)

func (*ScrollPosition) Value

func (p *ScrollPosition) Value() layout.Point

type ScrollView

type ScrollView struct {
	Embed
	ScrollAxes     layout.Axis
	IndicatorAxes  layout.Axis
	ScrollEnabled  bool
	ScrollPosition *ScrollPosition
	OnScroll       func(position layout.Point)

	ContentChildren []View
	ContentPainter  paint.Painter
	ContentLayouter layout.Layouter
	PaintStyle      *paint.Style
}

func NewScrollView

func NewScrollView() *ScrollView

NewScrollView returns a new view.

func (*ScrollView) Build

func (v *ScrollView) Build(ctx Context) Model

Build implements View.

func (*ScrollView) Lifecycle

func (v *ScrollView) Lifecycle(from, to Stage)

func (*ScrollView) Update

func (v *ScrollView) Update(v2 View)

type Slider

type Slider struct {
	Embed
	PaintStyle    *paint.Style
	Value         float64
	ValueNotifier comm.Float64Notifier
	MaxValue      float64
	MinValue      float64
	OnChange      func(value float64)
	OnSubmit      func(value float64)
	Enabled       bool
}

func NewSlider

func NewSlider() *Slider

New returns a new view.

func (*Slider) Build

func (v *Slider) Build(ctx Context) Model

Build implements view.View.

func (*Slider) Lifecycle

func (v *Slider) Lifecycle(from, to Stage)

func (*Slider) Update

func (v *Slider) Update(v2 View)

type Stage

type Stage int
const (
	// Views start in StageDead.
	StageDead Stage = iota
	// Views enter StageMounted before the first Build() call and exit it after the last one.
	StageMounted
	// StageVisible marks views that are in the view hierarchy and visible.
	// TODO(KD): StageVisible is not used.
	StageVisible
)

type Switch

type Switch struct {
	Embed
	Enabled    bool
	Value      bool
	OnSubmit   func(value bool)
	PaintStyle *paint.Style
}

func NewSwitch

func NewSwitch() *Switch

NewSwitch returns a new view.

func (*Switch) Build

func (v *Switch) Build(ctx Context) Model

Build implements view.View.

type TextInput

type TextInput struct {
	Embed
	PaintStyle *paint.Style
	Text       *text.Text

	Style            *text.Style
	Placeholder      string
	PlaceholderStyle *text.Style
	Password         bool
	KeyboardType     keyboard.Type
	Responder        *keyboard.Responder

	MaxLines int // This is used only for sizing.
	OnChange func(*text.Text)
	OnSubmit func(*text.Text)
	OnFocus  func(*keyboard.Responder)
}

TextInput represents a text input view. TextInput mutates the Text and StyledText fields in place.

func NewTextInput

func NewTextInput() *TextInput

NewTextInput returns a new view.

func (*TextInput) Build

func (v *TextInput) Build(ctx Context) Model

Build implements the view.View interface.

func (*TextInput) Lifecycle

func (v *TextInput) Lifecycle(from, to Stage)

Lifecyle implements the view.View interface.

type TextView

type TextView struct {
	Embed
	PaintStyle *paint.Style
	String     string
	Text       *text.Text
	Style      *text.Style
	StyledText *text.StyledText // TODO(KD): subscribe to StyledText and Text
	MaxLines   int
}

TextView displays a multiline text region within it bounds.

func NewTextView

func NewTextView() *TextView

NewTextView returns a new view.

func (*TextView) Build

func (v *TextView) Build(ctx Context) Model

Build implements the view.View interface.

type View

type View interface {
	Build(Context) Model
	Lifecycle(from, to Stage)
	ViewKey() interface{}
	Update(View)
	comm.Notifier
}

func WithOptions

func WithOptions(v View, opts ...Option) View

WithOptions wraps the view v, and adds the given options to its Model.Options.

func WithPainter

func WithPainter(v View, p paint.Painter) View

WithPainter wraps the view v, and replaces its Model.Painter with p.