wid

package
v0.0.0-...-657ba5f Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2023 License: MIT, Unlicense Imports: 28 Imported by: 1

Documentation

Overview

Package wid is an alternative implementation of gio's material widgets

Index

Constants

View Source
const (
	CursorSizeX = 10
	CursorSizeY = 32
)

Variables

View Source
var (
	MouseX   float32
	MouseY   float32
	WinX     int
	WinY     int
	CurrentX int
	CurrentY int
	GuiLock  sync.RWMutex
)
View Source
var (
	Red    = RGB(0xFF0000)
	Yellow = RGB(0xFFFF00)
	Green  = RGB(0x00FF00)
	Blue   = RGB(0x0000FF)
	White  = RGB(0xFFFFFF)
	Black  = RGB(0x000000)
)

Some default colors

View Source
var SpaceClose = []float32{}

SpaceClose is a shortcut for specifying that the row elements are placed close together, left to right

View Source
var SpaceDistribute []float32 = nil

SpaceDistribute should disribute the widgets on a row evenly, with equal space for each

Functions

func ARGB

func ARGB(c uint32) color.NRGBA

ARGB creates a NRGBA color from its hex code

func Button

func Button[V StrValue](th *Theme, label V, options ...Option) layout.Widget

Button is the generic button selector. Defaults to primary

func CalcMin

func CalcMin(gtx C, width unit.Dp) image.Point

CalcMin will calculate the minimum size of widget.

func Checkbox

func Checkbox(th *Theme, label string, options ...Option) func(gtx C) D

Checkbox returns a widget that can be checked, with label, initial state and handler function

func Clamp

func Clamp[T constraints.Ordered](v T, lo T, hi T) T

func ColDisabled

func ColDisabled(c color.NRGBA, disabled bool) color.NRGBA

ColDisabled returns the disabled color of c, depending on the disabled flag.

func DeEmphasis

func DeEmphasis(c color.NRGBA, amount uint8) color.NRGBA

DeEmphasis will change a color to a less prominent color In light mode, colors will be lighter, in dark mode, colors will be darker The amount of darkening is greater than the amount of lightening

func Disabled

func Disabled(c color.NRGBA) (d color.NRGBA)

Disabled blends color towards the luminance and multiplies alpha. Blending towards luminance will desaturate the color. Multiplying alpha blends the color together more with the background.

func DrawShadow

func DrawShadow(gtx C, outline image.Rectangle, rr int, elevation int)
func DropDown(th *Theme, index *int, items []string, options ...Option) layout.Widget

DropDown returns an initiated struct with drop-dow box setup info

func Edit

func Edit(th *Theme, options ...Option) func(gtx C) D

Edit will return a widget (layout function) for a text editor

func FPt

func FPt(p image.Point) f32.Point

func Gray

func Gray(c color.NRGBA) color.NRGBA

Gray returns a NRGBA color with the same luminance as the parameter

func GridRow

func GridRow(th *Theme, pbgColor *color.NRGBA, gridLineWidth unit.Dp, weights []float32, widgets ...layout.Widget) layout.Widget

GridRow returns a widget grid row with a grid separating columns and rows

func HeaderButton

func HeaderButton(th *Theme, label string, options ...Option) layout.Widget

HeaderButton is a shortcut to a text only button with left justified text and a given size

func Hovered

func Hovered(c color.NRGBA) (d color.NRGBA)

Hovered blends color towards a brighter color.

func Hsl2rgb

func Hsl2rgb(hueDegrees float64, saturation float64, light float64) color.NRGBA

Internal HSV->RGB function for doing conversions using float inputs (saturation, value) and outputs (for R, G, and B). Basically a direct implementation of this: https://en.wikipedia.org/wiki/HSL_and_HSV#Converting_to_RGB

func Image

func Image(img image.Image, fit Fit) func(gtx C) D

func ImageFromJpgFile

func ImageFromJpgFile(filename string, fit Fit) func(gtx C) D

func Interpolate

func Interpolate(a, b color.NRGBA, progress float32) color.NRGBA

Interpolate returns a color in between given colors a and b, depending on progress from 0.0 to 1.0

func Invalidate

func Invalidate()

func Label

func Label[V Value](th *Theme, v V, options ...Option) func(gtx C) D

Label returns a widget for a label showing a string

func List

func List(th *Theme, a AnchorStrategy, widgets ...layout.Widget) layout.Widget

List makes a vertical list

func Luminance

func Luminance(c color.NRGBA) byte

Luminance is a fast approximate version of RGBA.Luminance.

func Max

func Max[T constraints.Ordered](x, y T) T

func Min

func Min[T constraints.Ordered](x, y T) T

func MulAlpha

func MulAlpha(c color.NRGBA, alpha uint8) color.NRGBA

MulAlpha applies the alpha to the color.

func OutlineButton

func OutlineButton(th *Theme, label string, options ...Option) layout.Widget

OutlineButton is a shortcut to an outlined button

func ProgressBar

func ProgressBar(th *Theme, progress *float32, options ...Option) func(gtx C) D

ProgressBar returns a widget for a progress bar

func RGB

func RGB(c uint32) color.NRGBA

RGB creates a NRGBA color from its hex code, with alpha=255

func RadioButton

func RadioButton(th *Theme, value *string, key string, label string, options ...Option) func(gtx C) D

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

func Rgb2hsl

func Rgb2hsl(c color.NRGBA) (float64, float64, float64)

Internal implementation converting RGB to HSL, HSV, or HSI. Basically a direct implementation of this: https://en.wikipedia.org/wiki/HSL_and_HSV#General_approach

func RoundButton

func RoundButton(th *Theme, d *Icon, options ...Option) layout.Widget

RoundButton is a shortcut to a round button

func Row

func Row(th *Theme, pbgColor *color.NRGBA, weights []float32, widgets ...layout.Widget) layout.Widget

Row returns a widget grid row with selectable color.

func RrOp

func RrOp(rr clip.RRect, d int, ops *op.Ops) clip.Op

Op returns the op for the rounded rectangle.

func Run

func Run(win *app.Window, form *layout.Widget, th *Theme)

func RunWithContext

func RunWithContext(ctx context.Context, win *app.Window, form *layout.Widget, th *Theme)

func Separator

func Separator(th *Theme, thickness unit.Dp, options ...Option) layout.Widget

Separator creates a material separator widget

func ShadowPath

func ShadowPath(rr clip.RRect, d int, ops *op.Ops) clip.PathSpec

ShadowPath returns the PathSpec for the shadow This is a border around a rounded rectangle with width d

func Slider

func Slider(th *Theme, value *float32, minV, maxV float32, options ...Option) layout.Widget

Slider is for selecting a value in a range.

func Space

func Space(size unit.Dp) layout.Widget

Space will create an open space, like separator but without any line drawn

func SplitHorizontal

func SplitHorizontal(th *Theme, ratio float32, w1 layout.Widget, w2 layout.Widget) func(gtx C) D

SplitHorizontal is used to layout two widgets with a vertical splitter between.

func SplitVertical

func SplitVertical(th *Theme, ratio float32, w1 layout.Widget, w2 layout.Widget) func(gtx C) D

SplitVertical is used to layout two widgets with a vertical splitter between.

func StringerValue

func StringerValue(th *Theme, s func(dp int) string, options ...Option) func(gtx C) D

Value returns a widget for a value given by stringer function

func Switch

func Switch(th *Theme, statePtr *bool, options ...Option) func(gtx C) D

Switch returns a widget for a switch

func Table

func Table(th *Theme, a AnchorStrategy, heading layout.Widget, widgets ...layout.Widget) layout.Widget

Table makes a scrollable vertical list with a fixed header row

func TextButton

func TextButton(th *Theme, label string, options ...Option) layout.Widget

TextButton is a shortcut to a text only button

func Tone

func Tone(c color.NRGBA, tone int) color.NRGBA

Tone is the google material tone implementation See: https://m3.material.io/styles/color/the-color-system/key-colors-tones

func UpdateMousePos

func UpdateMousePos(gtx C, win *app.Window)

UpdateMousePos must be called from the main program in order to get mouse position and window size. They are needed to avoid that the tooltip is outside the window frame

func WithAlpha

func WithAlpha(c color.NRGBA, alpha uint8) color.NRGBA

WithAlpha returns the input color with the new alpha value.

Types

type AnchorStrategy

type AnchorStrategy uint8

AnchorStrategy defines a means of attaching a scrollbar to content.

const (
	// Occupy reserves space for the scrollbar, making the underlying
	// content region smaller on one axis.
	Occupy AnchorStrategy = iota
	// Overlay causes the scrollbar to float atop the content without
	// occupying any space. Content in the underlying area can be occluded
	// by the scrollbar.
	Overlay
)

type Base

type Base struct {
	Font     *text.Font
	FontSize float32
	// contains filtered or unexported fields
}

Base is tha base structure for widgets. It contains variables that (almost) all widgets share

func (*Base) Apply

func (wid *Base) Apply(options ...Option)

Apply will apply all optional parameters. This can only be used when the widget has no own options.

func (Base) Bg

func (b Base) Bg() color.NRGBA

func (Base) CheckDisable

func (b Base) CheckDisable(gtx C)

func (Base) Fg

func (b Base) Fg() color.NRGBA

func (*Base) Pad

func (wid *Base) Pad(t, r, b, l float32)

Pad is used to set default widget paddings (outside of widget)

type BaseIf

type BaseIf interface {
	// contains filtered or unexported methods
}

BaseIf is the interface functions for widgets, used by options to set parameters

type BaseOption

type BaseOption func(BaseIf)

BaseOption is a type for optional parameters when creating widgets

func Bg

func Bg(c *color.NRGBA) BaseOption

Bg is an option parameter to set widget background color

func Border

func Border(b unit.Dp) BaseOption

func Do

func Do(f func()) BaseOption

Do is an optional parameter to set a callback when widget state changes

func En

func En(b *bool) BaseOption

func Fg

func Fg(c *color.NRGBA) BaseOption

Fg is an option parameter to set widget foreground color

func FontSize

func FontSize(v float32) BaseOption

FontSize set the font size for text in the widget

func Heading

func Heading() BaseOption

Heading makes text 75% larger.

func Hint

func Hint(hint string) BaseOption

Hint is an option parameter to set the widget hint (tooltip)

func Large

func Large() BaseOption

Large makes text 40% larger.

func Lbl

func Lbl(s string) BaseOption

Lbl is an option parameter to set the widget label

func Pads

func Pads(pads ...float32) BaseOption

Pads is an option parameter to set customized padding. Noe that 1,2,3 or 4 paddings can be specified. If 1 is supplied, it is used for left,right,top,bottom, all with the same padding If 2 is supplied, the first is used for top/bottom, and the second for left and right padding If 4 is supplied, it is used for top, right, bottom, left in that sequence. All values are in Dp (float32 device independent pixels)

func Prim

func Prim() BaseOption

P is a shortcut to set role=Primary

func PrimCont

func PrimCont() BaseOption

PC is a shortcut to set role=PrimaryContainer

func Role

func Role(r UIRole) BaseOption

Role set the theme role for the widget (Primary, Secondary etc)

func Sec

func Sec() BaseOption

S is a shortcut to set role=Secondary

func SecCont

func SecCont() BaseOption

SC is a shortcut to set role=SecondaryContainer

func Small

func Small() BaseOption

Small makes text 20% smaller.

func W

func W(width float32) BaseOption

W is the option parameter for setting widget width

type BtnOption

type BtnOption func(*ButtonDef)

BtnOption is the options for buttons only

func BtnIcon

func BtnIcon(i *Icon) BtnOption

BtnIcon sets button icon

func RR

func RR(rr unit.Dp) BtnOption

RR is the corner radius

type ButtonDef

type ButtonDef struct {
	Base
	Tooltip
	Clickable
	Text  *string
	Icon  *Icon
	Style ButtonStyle
	// contains filtered or unexported fields
}

ButtonDef is the struct for buttons

func (*ButtonDef) HandleClick

func (b *ButtonDef) HandleClick()

HandleClick will call the callback function

func (*ButtonDef) Layout

func (b *ButtonDef) Layout(gtx C) D

Layout will draw a button defined in b.

type ButtonStyle

type ButtonStyle int

ButtonStyle indicates a Contained, Text, Outline or round button

const (
	// Contained is a solid, colored button
	Contained ButtonStyle = iota
	// Text is a button without outline or color. Just text
	Text
	// Outlined is a text button with outline
	Outlined
	// Round is a round button, usually with icon only
	Round
	// Header
	Header
)

type C

type C = layout.Context

C is a shortcut for layout.Context

type CheckBoxDef

type CheckBoxDef struct {
	Base
	Clickable
	Label     string
	StrValue  *string
	BoolValue *bool
	Checked   bool
	TextSize  unit.Sp

	Key string
	// contains filtered or unexported fields
}

CheckBoxDef defines a checkbox widget

func (*CheckBoxDef) Layout

func (c *CheckBoxDef) Layout(gtx C) D

Layout updates the checkBox and displays it.

type CheckboxOption

type CheckboxOption func(w *CheckBoxDef)

CheckboxOption is options specific to Checkboxes

func Bool

func Bool(b *bool) CheckboxOption

Bool is an option parameter to set the variable updated

type Click

type Click struct {
	Modifiers key.Modifiers
	NumClicks int
}

Click represents a click.

type Clickable

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

Clickable represents a clickable area.

func (*Clickable) Click

func (b *Clickable) Click()

Click executes a simple programmatic click

func (*Clickable) Clicked

func (b *Clickable) Clicked() bool

Clicked reports whether there are pending clicks as would be reported by Clicks. If so, Clicked removes the earliest click.

func (*Clickable) Clicks

func (b *Clickable) Clicks() []Click

Clicks returns and clear the clicks since the last call to Clicks.

func (*Clickable) Focused

func (b *Clickable) Focused() bool

Focused reports whether b has focus.

func (Clickable) GetIndex

func (b Clickable) GetIndex(n int) int

func (*Clickable) HandleEvents

func (b *Clickable) HandleEvents(gtx C)

HandleEvents the button state by processing events.

func (*Clickable) History

func (b *Clickable) History() []Press

History is the past pointer presses useful for drawing markers. History is retained for a short duration (about a second).

func (*Clickable) Hovered

func (b *Clickable) Hovered() bool

Hovered reports whether a pointer is over the element.

func (*Clickable) Pressed

func (b *Clickable) Pressed() bool

Pressed reports whether a pointer is pressing the element.

func (*Clickable) SetupEventHandlers

func (b *Clickable) SetupEventHandlers(gtx C, size image.Point)

type Con

type Con = layout.Constraints

type D

type D = layout.Dimensions

D is a shortcut for layout.Dimensions

type DropDownStyle struct {
	Base
	Clickable

	Items []Wid
	// contains filtered or unexported fields
}

DropDownStyle is the struct for dropdown lists.

func (b *DropDownStyle) Layout(gtx C) D

Layout adds padding to a dropdown box drawn with b.layout().

type EditDef

type EditDef struct {
	Base
	widget.Editor

	CharLimit uint
	// contains filtered or unexported fields
}

EditDef is the parameters for the text editor

func (*EditDef) Layout

func (e *EditDef) Layout(gtx C) D

type EditOption

type EditOption func(w *EditDef)

EditOption is options specific to Edits

func Area

func Area(min, max int) EditOption

Area is an option parameter to set the minimum and maximum height of the edit area and allow multi-line editing.

func ReadOnly

func ReadOnly() EditOption

ReadOnly is an option parameter to set the edit to read-only

func Var

func Var(s *string) EditOption

Var is an option parameter to set the variable uptdated

type Fit

type Fit uint8

Fit scales a widget to fit and clip to the constraints.

const (
	// Unscaled does not alter the scale of a widget.
	Unscaled Fit = iota
	// Contain scales widget as large as possible without cropping,
	// and it preserves aspect-ratio.
	Contain
	// Cover scales the widget to cover the constraint area and
	// preserves aspect-ratio.
	Cover
	// ScaleDown scales the widget smaller without cropping,
	// when it exceeds the constraint area.
	// It preserves aspect-ratio.
	ScaleDown
	// Fill stretches the widget to the constraints and does not
	// preserve aspect-ratio.
	Fill
)

type Icon

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

Icon is the definition of an icon

func NewIcon

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

NewIcon returns a new Icon from IconVG data.

func (*Icon) Layout

func (ic *Icon) Layout(gtx C, color color.NRGBA) D

Layout displays the icon with its size set to the X minimum constraint.

func (*Icon) Update

func (ic *Icon) Update(data []byte) error

type ImageDef

type ImageDef struct {
	// Src is the image to display.
	Src paint.ImageOp
	// Fit specifies how to scale the image to the constraints.
	// By default, it does not do any scaling.
	Fit Fit
	// Position specifies where to position the image within
	// the constraints.
	Position layout.Direction
	// Scale is the ratio of image pixels to
	// dps. If Scale is zero Image falls back to
	// a scale that match a standard 72 DPI.
	Scale float32
}

ImageDef is a widget that displays an image.

func (ImageDef) Layout

func (im ImageDef) Layout(gtx C) D

type InvalidateDeadline

type InvalidateDeadline struct {
	// The time at which a frame needs to be drawn.
	Target time.Time
	// Whether the deadline is active.
	Active bool
}

InvalidateDeadline helps to ensure that a frame is generated at a specific point in time in the future. It does this by always requesting a future invalidation at its target time until it reaches its target time. This makes animating delays much cleaner.

func (*InvalidateDeadline) ClearTarget

func (i *InvalidateDeadline) ClearTarget()

ClearTarget cancels a request to invalidate in the future.

func (*InvalidateDeadline) Process

func (i *InvalidateDeadline) Process(gtx C) bool

Process checks the current frame time and either requests a future invalidation or does nothing. It returns whether the current frame is the frame requested by the last call to SetTarget.

func (*InvalidateDeadline) SetTarget

func (i *InvalidateDeadline) SetTarget(t time.Time)

SetTarget configures a specific time in the future at which a frame should be rendered.

type LabelDef

type LabelDef struct {
	Base
	// Face defines the text style.
	Font text.Font
	// Alignment specify the text alignment.
	Alignment text.Alignment
	// MaxLines limits the number of lines. Zero means no limit.
	MaxLines int
	TextSize unit.Sp
	Stringer func(dp int) string
	// contains filtered or unexported fields
}

LabelDef is the setup for a label.

func (LabelDef) Layout

func (l LabelDef) Layout(gtx C) D

Layout will draw the label

type LabelOption

type LabelOption func(w *LabelDef)

LabelOption is options specific to Edits.

func Bold

func Bold() LabelOption

Bold is an option parameter to set the widget hint (tooltip).

func Dp

func Dp(n int) LabelOption

func Middle

func Middle() LabelOption

Middle will align text in the middle.

func Right() LabelOption

End will align text to the end.

func Weight

func Weight(weight text.Weight) LabelOption

Weight sets the font weight.

type ListStyle

type ListStyle struct {
	Hpos       int
	HorTotal   int
	HorVisible bool
	VScrollBar ScrollbarStyle
	HScrollBar ScrollbarStyle
	AnchorStrategy
	// contains filtered or unexported fields
}

ListStyle configures the presentation of a layout.List with a scrollbar.

func (*ListStyle) Layout

func (l *ListStyle) Layout(gtx C, length int, header layout.Widget, w layout.ListElement) D

Layout the list and its scrollbar.

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option is the interface for optional parameters

type Pallet

type Pallet struct {
	PrimaryColor        color.NRGBA
	SecondaryColor      color.NRGBA
	TertiaryColor       color.NRGBA
	ErrorColor          color.NRGBA
	NeutralColor        color.NRGBA
	NeutralVariantColor color.NRGBA
}

Pallet is the key colors. All other colors are derived from them

type Press

type Press struct {
	// Position of the press.
	Position image.Point
	// Start is when the press began.
	Start time.Time
	// End is when the press was ended by a release or cancel.
	// A zero End means it hasn't ended yet.
	End time.Time
	// Cancelled is true for cancelled presses.
	Cancelled bool
}

Press represents a past pointer press.

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 reversible.

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 HandleEvents the progress value.

func (Progress) Absolute

func (p Progress) Absolute() float32

Absolute reports the absolute progress, ignoring direction.

func (Progress) Direction

func (p Progress) Direction() ProgressDirection

Direction reports the current direction.

func (Progress) Finished

func (p Progress) Finished() bool

Finished is true when animation is done

func (Progress) Progress

func (p Progress) Progress() float32

Progress reports the current progress as a float between [0, 1].

func (*Progress) Start

func (p *Progress) Start(began time.Time, direction ProgressDirection, duration time.Duration)

Start the progress in the given direction over the given duration.

func (Progress) Started

func (p Progress) Started() bool

Started reports true if progression has started.

func (*Progress) Stop

func (p *Progress) Stop()

Stop the progress.

func (*Progress) Update

func (p *Progress) Update(now time.Time)

Update will do HandleEvents now

type ProgressBarStyle

type ProgressBarStyle struct {
	Base
	Progress *float32
}

ProgressBarStyle defines the progress bar

type ProgressDirection

type ProgressDirection int

ProgressDirection specifies how to HandleEvents 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 Rectangle

type Rectangle struct {
	Min, Max f32.Point
}

func FRect

func FRect(r image.Rectangle) Rectangle

type Resize

type Resize struct {
	Theme *Theme

	Length float32
	// contains filtered or unexported fields
}

Resize provides a draggable handle in between two widgets for resizing their area.

func (*Resize) Layout

func (rs *Resize) Layout(gtx C, w1 layout.Widget, w2 layout.Widget) D

Layout displays w1 and w2 with handle in between.

type ScrollIndicatorStyle

type ScrollIndicatorStyle struct {
	// MajorMinLen is the smallest that the scroll indicator is allowed to
	// be along the major axis.
	MajorMinLen unit.Dp
	// MinorWidth is the width of the scroll indicator across the minor axis.
	MinorWidth unit.Dp
	// Color and HoverColor are the normal and hovered colors of the scroll
	// indicator.
	Color, HoverColor color.NRGBA
	// CornerRadius is the corner radius of the rectangular indicator. 0
	// will produce square corners. 0.5*MinorWidth will produce perfectly
	// round corners.
	CornerRadius unit.Dp
}

ScrollIndicatorStyle configures the presentation of a scroll indicator.

type ScrollTrackStyle

type ScrollTrackStyle struct {
	// MajorPadding and MinorPadding along the major and minor axis of the
	// scrollbar's track. This is used to keep the scrollbar from touching
	// the edges of the content area.
	MajorPadding, MinorPadding unit.Dp
	// Color of the track background.
	Color color.NRGBA
}

ScrollTrackStyle configures the presentation of a track for a scroll area.

type Scrollbar

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

Scrollbar holds the persistent state for an area that can display a scrollbar. In particular, it tracks the position of a viewport along a one-dimensional region of content. The viewport's position can be adjusted by drag operations along the display area, or by clicks within the display area.

Scrollbar additionally detects when a scroll indicator region is hovered.

func (*Scrollbar) AddDrag

func (s *Scrollbar) AddDrag(ops *op.Ops)

AddDrag configures the drag listener for the scrollbar to use the most recently added pointer.AreaOp.

func (*Scrollbar) AddIndicator

func (s *Scrollbar) AddIndicator(ops *op.Ops)

AddIndicator configures the indicator click listener for the scrollbar to use the most recently added pointer.AreaOp.

func (*Scrollbar) AddTrack

func (s *Scrollbar) AddTrack(ops *op.Ops)

AddTrack configures the track click listener for the scrollbar to use the most recently added pointer.AreaOp.

func (*Scrollbar) IndicatorHovered

func (s *Scrollbar) IndicatorHovered() bool

IndicatorHovered returns whether the scroll indicator is currently being hovered by the pointer.

func (*Scrollbar) Layout

func (s *Scrollbar) Layout(gtx C, axis layout.Axis, viewportStart, viewportEnd float32) D

Layout updates the internal state of the scrollbar based on events since the previous call to Layout. The provided axis will be used to normalize input event coordinates and constraints into an axis- independent format. viewportStart is the position of the beginning of the scrollable viewport relative to the underlying content expressed as a value in the range [0,1]. viewportEnd is the position of the end of the viewport relative to the underlying content, also expressed as a value in the range [0,1]. For example, if viewportStart is 0.25 and viewportEnd is .5, the viewport described by the scrollbar is currently showing the second quarter of the underlying content.

func (*Scrollbar) ScrollDistance

func (s *Scrollbar) ScrollDistance() float32

ScrollDistance returns the normalized distance that the scrollbar moved during the last call to Layout as a value in the range [-1,1].

type ScrollbarStyle

type ScrollbarStyle struct {
	Scrollbar *Scrollbar
	Track     ScrollTrackStyle
	Indicator ScrollIndicatorStyle
}

ScrollbarStyle configures the presentation of a scrollbar.

func MakeScrollbarStyle

func MakeScrollbarStyle(th *Theme) ScrollbarStyle

MakeScrollbarStyle configures the presentation of a scrollbar using the provided theme and state.

func (ScrollbarStyle) Layout

func (s ScrollbarStyle) Layout(gtx C, axis layout.Axis, viewportStart, viewportEnd float32) D

Layout the scrollbar.

func (ScrollbarStyle) Width

func (s ScrollbarStyle) Width() unit.Dp

Width returns the minor axis width of the scrollbar in its current configuration (taking padding for the scroll track into account).

type SeparatorStyle

type SeparatorStyle struct {
	Base
	// contains filtered or unexported fields
}

SeparatorStyle defines material rendering parameters for separator

type ShadowStyle

type ShadowStyle struct {
	CornerRadius int
	Elevation    int
}

ShadowStyle defines a shadow cast by a rounded rectangle.

func Shadow

func Shadow(radius int, elevation int) ShadowStyle

Shadow defines a shadow cast by a rounded rectangle with the given corner radius and elevation.

func (ShadowStyle) Layout

func (s ShadowStyle) Layout(gtx C) D

Layout renders the shadow into the gtx. The shadow's size will assume that the rectangle casting the shadow is of size gtx.Constraints.Min.

type SliderStyle

type SliderStyle struct {
	Base

	Value *float32
	// contains filtered or unexported fields
}

SliderStyle is the parameters for a slider

func (*SliderStyle) Layout

func (s *SliderStyle) Layout(gtx C) D

Layout will draw the slider

type StrValue

type StrValue interface {
	string | *string
}

type SwitchDef

type SwitchDef struct {
	Base

	StatePtr *bool
	// contains filtered or unexported fields
}

SwitchDef is the parameters for a slider

func (*SwitchDef) Layout

func (s *SwitchDef) Layout(gtx C) D

Layout updates the switch and displays it.

type Theme

type Theme struct {
	Pallet
	DarkMode            bool
	Shaper              *text.Shaper
	TextSize            unit.Sp
	DefaultFont         text.Font
	CheckBoxChecked     *Icon
	CheckBoxUnchecked   *Icon
	RadioChecked        *Icon
	RadioUnchecked      *Icon
	FingerSize          unit.Dp // FingerSize is the minimum touch target size.
	SelectionColor      color.NRGBA
	BorderThickness     unit.Dp
	BorderColor         color.NRGBA
	BorderColorHovered  color.NRGBA
	BorderColorActive   color.NRGBA
	BorderCornerRadius  unit.Dp
	TooltipInset        layout.Inset
	TooltipCornerRadius unit.Dp
	TooltipWidth        unit.Dp
	TooltipBackground   color.NRGBA
	TooltipOnBackground color.NRGBA
	OutsidePadding      layout.Inset
	InsidePadding       layout.Inset
	IconInset           layout.Inset
	ListInset           layout.Inset
	ButtonPadding       layout.Inset
	ButtonLabelPadding  layout.Inset
	ButtonCornerRadius  unit.Dp
	IconSize            unit.Dp
	// Elevation is the shadow width
	Elevation unit.Dp
	// SashColor is the color of the movable divider
	SashColor  color.NRGBA
	SashWidth  unit.Dp
	TrackColor color.NRGBA
	DotColor   color.NRGBA
	// Tooltip settings
	// HoverDelay is the delay between the cursor entering the tip area
	// and the tooltip appearing.
	HoverDelay time.Duration
	// LongPressDelay is the required duration of a press in the area for
	// it to count as a long press.
	LongPressDelay time.Duration
	// LongPressDuration is the amount of time the tooltip should be displayed
	// after being triggered by a long press.
	LongPressDuration time.Duration
	// FadeDuration is the amount of time it takes the tooltip to fade in
	// and out.
	FadeDuration time.Duration
	RowPadTop    unit.Sp
	RowPadBtm    unit.Sp
	// Scroll bar size
	ScrollMajorPadding unit.Sp
	ScrollMinorPadding unit.Sp
	ScrollMajorMinLen  unit.Sp
	ScrollMinorWidth   unit.Sp
	ScrollCornerRadius unit.Sp
}

Theme contains color/layout settings for all widgets

func NewTheme

func NewTheme(fontCollection []text.FontFace, fontSize unit.Sp, colors ...color.NRGBA) *Theme

NewTheme creates a new theme with given FontFace and FontSize, based on the theme t

func (*Theme) Bg

func (th *Theme) Bg(kind UIRole) color.NRGBA

Bg returns the background color used to fill the element.

func (*Theme) Fg

func (th *Theme) Fg(kind UIRole) color.NRGBA

Fg returns the text/icon color. This is the OnPrimary, OnBackground... colors

type Tooltip

type Tooltip struct {
	VisibilityAnimation
	// MaxWidth is the maximum width of the tool-tip box. Should be less than form width.
	MaxWidth unit.Dp
	// Text defines the content of the tooltip.
	Text widget.Label

	Hover     InvalidateDeadline
	Press     InvalidateDeadline
	LongPress InvalidateDeadline
	Fgc       color.NRGBA
	Bgc       color.NRGBA
	TooltipRR unit.Dp
	TextSize  unit.Sp
	// contains filtered or unexported fields
}

Tooltip implements a material design tool tip as defined at: https://material.io/components/tooltips#specs

func DesktopTooltip

func DesktopTooltip(th *Theme) Tooltip

DesktopTooltip constructs a tooltip suitable for use on desktop devices.

func MobileTooltip

func MobileTooltip(th *Theme) Tooltip

MobileTooltip constructs a tooltip suitable for use on mobile devices.

func PlatformTooltip

func PlatformTooltip(th *Theme) Tooltip

PlatformTooltip creates a tooltip styled to the current platform (desktop or mobile) by choosing based on the OS. This choice may not always be appropriate as it only uses the OS to decide.

func (*Tooltip) Layout

func (t *Tooltip) Layout(gtx C, hint string, w layout.Widget) D

Layout renders the provided widget with the provided tooltip. The tooltip will be summoned if the widget is hovered or long-pressed.

type UIRole

type UIRole uint8

UIRole describes the type of UI element There are two colors for each UIRole, one for text/icon and one for background Typicaly you specify a UIRole for each user elemet (button, checkbox etc). Default and Zero value is Neutral.

const (
	// Canvas is white/black. Used in edits, dropdowns etc to standouw
	Canvas UIRole = iota
	// Surface is the default surface for windows.
	Surface
	// SurfaceVariant is for variation
	SurfaceVariant
	// Primary is for prominent buttons, active states etc
	Primary
	// PrimaryContainer is a light background tinted with Primary color.
	PrimaryContainer
	// Secondary is for less prominent components
	Secondary
	// SecondaryContainer is a light background tinted with Secondary color.
	SecondaryContainer
	// Tertiary is for contrasting elements
	Tertiary
	// TertiaryContainer is a light background tinted with Tertiary color.
	TertiaryContainer
	// Error is usualy red
	Error
	// ErrorContainer is usualy light red
	ErrorContainer
	// Outline is used for frames and buttons
	Outline
	// Undefined can be used to detect missing initializations
	Undefined
)

type UIState

type UIState uint8

UIState is the hovered/focusted etc. state

type Value

type Value interface {
	int | float64 | float32 | string | *int | *float64 | *float32 | *string
}

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 appearing 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 C) 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 Context to ensure that the next frame will be generated promptly.

func (*VisibilityAnimation) String

func (v *VisibilityAnimation) String(gtx C) 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
)

Visibility constants

func (VisibilityAnimationState) String

func (v VisibilityAnimationState) String() string

type Wid

type Wid = layout.Widget

func Col

func Col(weights []float32, widgets ...Wid) Wid

Col makes a column of widgets. It is not scrollable, but weights are used to split the available area. Set weigth to 0 for fixed height widgets, and 1 for flexible widgets (like lists)

Jump to

Keyboard shortcuts

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