material

package
v0.0.0-...-d956aad Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 2, 2020 License: Unlicense Imports: 15 Imported by: 0

Documentation

Overview

Package material implements the Material design.

To maximize reusability and visual flexibility, user interface controls are split into two parts: the stateful widget and the stateless drawing of it.

For example, widget.Button encapsulates the state and event handling of all buttons, while the Theme can draw a single Button in various styles.

This snippet defines a button that prints a message when clicked:

var gtx *layout.Context
button := new(widget.Button)

for button.Clicked(gtx) {
    fmt.Println("Clicked!")
}

Use a Theme to draw the button:

theme := material.NewTheme(...)

th.Button("Click me!").Layout(gtx, button)

Customization

Quite often, a program needs to customize the theme provided defaults. Several options are available, depending on the nature of the change:

Mandatory parameters: Some parameters are not part of the widget state but have no obvious default. In the program above, the button text is a parameter to the Theme.Button method.

Theme-global parameters: For changing the look of all widgets drawn with a particular theme, adjust the `Theme` fields:

theme.Color.Primary = color.RGBA{...}

Widget-local parameters: For changing the look of a particular widget, adjust the widget specific theme object:

btn := th.Button("Click me!")
btn.Font.Style = text.Italic
btn.Layout(gtx)

Widget variants: A widget can have several distinct representations even though the underlying state is the same. A widget.Button can be drawn as a round icon button:

icon := material.NewIcon(...)

th.IconButton(icon).Layout(gtx, button)

Specialized widgets: Theme both define a generic Label method that takes a text size, and specialized methods for standard text sizes such as Theme.H1 and Theme.Body2.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Button

type Button struct {
	Text string
	// Color is the text color.
	Color        color.RGBA
	Font         text.Font
	Background   color.RGBA
	CornerRadius unit.Value
	// contains filtered or unexported fields
}

func (Button) Layout

func (b Button) Layout(gtx *layout.Context, button *widget.Button)

type CheckBox

type CheckBox struct {
	// contains filtered or unexported fields
}

func (CheckBox) Layout

func (c CheckBox) Layout(gtx *layout.Context, checkBox *widget.CheckBox)

type Editor

type Editor struct {
	Font text.Font
	// Color is the text color.
	Color color.RGBA
	// Hint contains the text displayed when the editor is empty.
	Hint string
	// HintColor is the color of hint text.
	HintColor color.RGBA
	// contains filtered or unexported fields
}

func (Editor) Layout

func (e Editor) Layout(gtx *layout.Context, editor *widget.Editor)

type Icon

type Icon struct {
	Color color.RGBA
	// contains filtered or unexported fields
}

func NewIcon

func NewIcon(data []byte) (*Icon, error)

NewIcon returns a new Icon from IconVG data.

func (*Icon) Layout

func (ic *Icon) Layout(gtx *layout.Context, sz unit.Value)

type IconButton

type IconButton struct {
	Background color.RGBA
	Color      color.RGBA
	Icon       *Icon
	Size       unit.Value
	Padding    unit.Value
}

func (IconButton) Layout

func (b IconButton) Layout(gtx *layout.Context, button *widget.Button)

type Image

type Image struct {
	// Src is the image to display.
	Src paint.ImageOp
	// Scale is the ratio of image pixels to
	// dps.
	Scale float32
}

Image is a widget that displays an image.

func (Image) Layout

func (im Image) Layout(gtx *layout.Context)

type Label

type Label struct {
	// Face defines the text style.
	Font text.Font
	// Color is the text color.
	Color color.RGBA
	// Alignment specify the text alignment.
	Alignment text.Alignment
	// MaxLines limits the number of lines. Zero means no limit.
	MaxLines int
	Text     string
	// contains filtered or unexported fields
}

func (Label) Layout

func (l Label) Layout(gtx *layout.Context)

type RadioButton

type RadioButton struct {
	Key string
	// contains filtered or unexported fields
}

func (RadioButton) Layout

func (r RadioButton) Layout(gtx *layout.Context, enum *widget.Enum)

type Theme

type Theme struct {
	Shaper *text.Shaper
	Color  struct {
		Primary color.RGBA
		Text    color.RGBA
		Hint    color.RGBA
		InvText color.RGBA
	}
	TextSize unit.Value
	// contains filtered or unexported fields
}

func NewTheme

func NewTheme() *Theme

func (*Theme) Body1

func (t *Theme) Body1(txt string) Label

func (*Theme) Body2

func (t *Theme) Body2(txt string) Label

func (*Theme) Button

func (t *Theme) Button(txt string) Button

func (*Theme) Caption

func (t *Theme) Caption(txt string) Label

func (*Theme) CheckBox

func (t *Theme) CheckBox(label string) CheckBox

func (*Theme) Editor

func (t *Theme) Editor(hint string) Editor

func (*Theme) H1

func (t *Theme) H1(txt string) Label

func (*Theme) H2

func (t *Theme) H2(txt string) Label

func (*Theme) H3

func (t *Theme) H3(txt string) Label

func (*Theme) H4

func (t *Theme) H4(txt string) Label

func (*Theme) H5

func (t *Theme) H5(txt string) Label

func (*Theme) H6

func (t *Theme) H6(txt string) Label

func (*Theme) IconButton

func (t *Theme) IconButton(icon *Icon) IconButton

func (*Theme) Image

func (t *Theme) Image(img paint.ImageOp) Image

func (*Theme) Label

func (t *Theme) Label(size unit.Value, txt string) Label

func (*Theme) RadioButton

func (t *Theme) RadioButton(key, label string) RadioButton

RadioButton returns a RadioButton with a label. The key specifies the value for the Enum.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL