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 ¶
- type Button
- type CheckBox
- type Editor
- type Icon
- type IconButton
- type Image
- type Label
- type RadioButton
- type Theme
- func (t *Theme) Body1(txt string) Label
- func (t *Theme) Body2(txt string) Label
- func (t *Theme) Button(txt string) Button
- func (t *Theme) Caption(txt string) Label
- func (t *Theme) CheckBox(label string) CheckBox
- func (t *Theme) Editor(hint string) Editor
- func (t *Theme) H1(txt string) Label
- func (t *Theme) H2(txt string) Label
- func (t *Theme) H3(txt string) Label
- func (t *Theme) H4(txt string) Label
- func (t *Theme) H5(txt string) Label
- func (t *Theme) H6(txt string) Label
- func (t *Theme) IconButton(icon *Icon) IconButton
- func (t *Theme) Image(img paint.ImageOp) Image
- func (t *Theme) Label(size unit.Value, txt string) Label
- func (t *Theme) RadioButton(key, label string) RadioButton
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Button ¶
type Editor ¶
type IconButton ¶
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.
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 }
type RadioButton ¶
type RadioButton struct { Key string // contains filtered or unexported fields }
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 (*Theme) IconButton ¶
func (t *Theme) IconButton(icon *Icon) IconButton
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.