Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type PushButton ¶
type PushButton struct { Origin widget.Clickable // Origin is the clickable of this push button. Background op.CallOp // Background is called to fill the background of this button. BackgroundDisabled op.CallOp // BackgroundDisabled is used instead of Background in disabled mode. CornerRadius unit.Dp // CornerRadius is the radius of smooth corners. Shadow Shadow // Shadow is the shadow casted by this button. Inset layout.Inset // Inset is used to margin the text from corners of this button. Shaper *text.Shaper // Shaper is used to layout the text. Font font.Font // Font is used for the text. Label string // Label is the text. FontSize unit.Sp // FontSize is the size of the text. Foreground op.CallOp // Foreground is the material operation for the text. ForegroundDisabled op.CallOp // ForegroundDisabled is used instead of Foreground in disabled mode. HoverColor color.NRGBA // HoverColor is drawn over the push button when it's hovered. ClickColor color.NRGBA // ClickColor is drawn over the push button while it's being pressed. }
PushButton is a button with text.
Example ¶
package main import ( "image/color" "gioui.org/font/gofont" "gioui.org/layout" "gioui.org/op" "gioui.org/op/paint" "gioui.org/text" "gioui.org/unit" "github.com/widetape/freyja/pkg/freyja" ) func main() { fonts := gofont.Collection() font := fonts[0].Font shaper := text.NewShaper(fonts) gtx := layout.Context{} button := freyja.PushButton{ Label: "Press Me!", // This text will be shown on the button. FontSize: unit.Sp(13), // Size of the text. Font: font, // Font of the text. Shaper: shaper, // Shaper to draw the text. CornerRadius: unit.Dp(12), Inset: layout.Inset{ Top: unit.Dp(8), Bottom: unit.Dp(8), Left: unit.Dp(12), Right: unit.Dp(12), }, Background: func() op.CallOp { ops := op.Ops{} r := op.Record(&ops) // Fill button'a background with pure red. paint.Fill(&ops, color.NRGBA{R: 0xFF, A: 0xFF}) return r.Stop() }(), BackgroundDisabled: func() op.CallOp { ops := op.Ops{} r := op.Record(&ops) // Fill button's background with light gray when it's disabled. paint.Fill(&ops, color.NRGBA{A: 0x10}) return r.Stop() }(), Foreground: func() op.CallOp { ops := op.Ops{} r := op.Record(&ops) // Fill button's text color with black. paint.Fill(&ops, color.NRGBA{A: 0xFF}) return r.Stop() }(), ForegroundDisabled: func() op.CallOp { ops := op.Ops{} r := op.Record(&ops) // Fill button's text color with light gray when it's disabled. // // Note that this won't be the same color as the disabled background, // but instead it will blend with it, because they are layed // on top of each other, so the text will still be readable. paint.Fill(&ops, color.NRGBA{A: 0x10}) return r.Stop() }(), // These do not affect the button in disabled mode... // Both, HoverColor and ClickColor, do not affect the text, // but only affect the background. // Drawn on top of the button's background when the pointer // is hover on top of the button. // // Note that this does not appear when the button is being pressed. HoverColor: color.NRGBA{A: 0x08}, // Drawn of top of the button's background when the pointer // is pressing the button. ClickColor: color.NRGBA{A: 0x0F}, } // Layout the button to the context. button.Layout(gtx) }
Output:
func (*PushButton) Layout ¶
func (b *PushButton) Layout(gtx layout.Context) layout.Dimensions
Layout lays PushButton out to the context.
type RadioButton ¶
type RadioButton struct { Group *widget.Enum // Group is the group this radio button belongs to. Key string // Key is this radio button's key in the group. Background op.CallOp // Background is used to render the background of this radio button. BackgroundDisabled op.CallOp // BackgroundDisabled is used instead of Background in disabled mode. Outline op.CallOp // Outline is used to render the outline of this radio button. OutlineDisabled op.CallOp // OutlineDisabled is used instead of Outline in disabled mode. OutlineWidth unit.Dp // OutlineWidth is the width of the outline. Tint op.CallOp // Tint is used to render the tint of the radio button when it's selected. Inset unit.Dp // Inset is the padding of the knob. Knob op.CallOp // Knob is used to render the knob of the radio button when it's selected. KnobDisabled op.CallOp // KnobDisabled is used instead of Knob in disabled mode. KnobSize unit.Dp // KnobSize is the diameter if the knob. }
RadioButton represents a selectable option in a group of mutually exclusive choices.
func (*RadioButton) Layout ¶
func (b *RadioButton) Layout(gtx layout.Context) layout.Dimensions
Layout lays the radio button out to the context.
type Shadow ¶
type Shadow struct { Color color.NRGBA // Color is the basic of the shadow. Layers int // Layers determines how many shadow layer to draw. Spread unit.Dp // Spread determines how far the shadow goes from the content. X unit.Dp // X is the horizontal offset of this shadow. Y unit.Dp // Y is the vertical offset of this shadow. Slope float64 }
Shadow draws a component and a shadow below it.
Note that non-opaque components may produce unexpected look.
type Slider ¶
type Switch ¶
type Switch struct { Origin widget.Bool // Origin is the bool if this switch. Background op.CallOp // Background is used to draw the background for this switch. BackgroundDisabled op.CallOp // BackgroundDisabled is used instead of Background when the switch is disabled. EnvironmentShadow Shadow // EnvironmentShadow is the shadow casted into the switch. KnobShadow Shadow // KnobShadow is the shadow casted by the knob. Tint op.CallOp // Tint is used to draw the tinted background overlay of the switch in "On" mode. TintDisabled op.CallOp // TintDisabled is used instead of Tint when the switch is disabled. Knob op.CallOp // Knob is used to draw the knob of this switch. KnobDisabled op.CallOp // KnobDisabled is used instead of Knob when the switch is disabled. KnobSize unit.Dp // KnobSize is the diameter of the knob. Inset unit.Dp // Inset is the gab between the knob and the borders of switch. Shift unit.Dp // Shift is the distance that the knob shifts to the right. }
Switch is a toggle button with knob.
type TextField ¶
type TextField struct { Origin widget.Editor LeadingContent layout.Widget TrailingContent layout.Widget Spacing unit.Dp Shadow Shadow Background color.NRGBA BackgroundDisabled color.NRGBA BorderColor color.NRGBA BorderColorDisabled color.NRGBA BorderWidth unit.Dp BorderRadius unit.Dp Inset layout.Inset OutlineColor color.NRGBA OutlineWidth unit.Dp Font font.Font Shaper *text.Shaper SelectionColor color.NRGBA FontColor color.NRGBA FontColorDisabled color.NRGBA FontSize unit.Sp Hint string HintColor color.NRGBA HintColorDisabled color.NRGBA }
Click to show internal directories.
Click to hide internal directories.