Documentation
¶
Index ¶
- Constants
- Variables
- func CalculateRects(hasLabel bool, style *EditStyle, r f32.Rect) (dim, frameRect, valueRect, labelRect f32.Rect)
- func ClearBuffers()
- func Default[T any](ptr **T, def *T)
- func Display(win *sys.Window, x, y, w float32, widget Wid)
- func Draw(Gd *gpu.GlData, x, y, w float32, h float32, img *Img)
- func DrawCursor(ctx Ctx, style *EditStyle, state *EditState, valueRect f32.Rect, f *font.Font)
- func DrawDebuggingInfo(ctx Ctx, labelRect f32.Rect, valueRect f32.Rect, WidgetRect f32.Rect)
- func DrawVertScrollbar(ctx Ctx, state *ScrollState, style *ScrollStyle)
- func EditMouseHandler(ctx Ctx, state *EditState, valueRect f32.Rect, f *font.Font, value any)
- func EditText(ctx Ctx, state *EditState, action func())
- func Hint(ctx Ctx, text string, tag any)
- func IsKeyClick(ctx Ctx) bool
- func Show(w Wid)
- func VertScollbarUserInput(ctx Ctx, state *ScrollState, style *ScrollStyle)
- type Alignment
- type BtnStyle
- type CachedScrollState
- type CbStyle
- type ComboState
- type ComboStyle
- type ContainerStyle
- func (style *ContainerStyle) C(c theme.UIRole) *ContainerStyle
- func (style *ContainerStyle) H(h float32) *ContainerStyle
- func (style *ContainerStyle) R(c theme.UIRole) *ContainerStyle
- func (style *ContainerStyle) Size(w, h, bw float32) *ContainerStyle
- func (style *ContainerStyle) TotalVerticalPadding() float32
- func (style *ContainerStyle) W(w float32) *ContainerStyle
- type Ctx
- type Dim
- type EditState
- type EditStyle
- func (s *EditStyle) D(flag *bool) *EditStyle
- func (s *EditStyle) Dim(ctx Ctx, f *font.Font) Dim
- func (s *EditStyle) Disabled() bool
- func (s *EditStyle) RO() *EditStyle
- func (s *EditStyle) Size(wl, we float32) *EditStyle
- func (s *EditStyle) Top() float32
- func (s *EditStyle) TopPad(p float32) *EditStyle
- type Fit
- type HintStyle
- type Img
- type ImgStyle
- type LabelStyle
- type MemoStyle
- type Mode
- type ResizerState
- type ResizerStyle
- type ScrollState
- type ScrollStyle
- type SwitchStyle
- type Wid
- func BoxText(text string, fg f32.Color, bg f32.Color, style *LabelStyle) Wid
- func Btn(text string, ic *gpu.Icon, action func(), style *BtnStyle, hint string) Wid
- func CashedScroller(state *CachedScrollState, style *ScrollStyle, f func(itemno int) Wid, ...) Wid
- func Checkbox(label string, state *bool, action func(), style *CbStyle, hint string) Wid
- func Col(style *ContainerStyle, widgets ...Wid) Wid
- func Combo(value any, list []string, label string, style *ComboStyle) Wid
- func Edit(value any, label string, action func(), style *EditStyle) Wid
- func Flex() Wid
- func HorResizer(state *ResizerState, style *ResizerStyle, widget1 Wid, widget2 Wid) Wid
- func Image(img *Img, action func(), style *ImgStyle, altText string) Wid
- func Label(text string, style *LabelStyle) Wid
- func Line(dx, dy float32, color theme.UIRole) Wid
- func Memo(text *[]string, style *MemoStyle) Wid
- func ProgressBar(fraction float32, style *ContainerStyle) Wid
- func RadioButton(label string, value *string, key string, style *CbStyle) Wid
- func Row(style *ContainerStyle, widgets ...Wid) Wid
- func Scroller(state *ScrollState, style *ScrollStyle, widgets ...Wid) Wid
- func Separator(dx, dy float32) Wid
- func Switch(label string, state *bool, action func(), style *SwitchStyle, hint string) Wid
- func VertResizer(state *ResizerState, style *ResizerStyle, widget1 Wid, widget2 Wid) Wid
Constants ¶
const GridBorderWidth = 0.0
Variables ¶
var C = &LabelStyle{ Padding: f32.Padding{L: 2, T: 2, R: 1, B: 1}, FontNo: gpu.Normal12, Align: AlignCenter, Role: theme.OnSurface, }
var CheckBoxHeader = &BtnStyle{ FontNo: gpu.Normal12, InsidePadding: f32.Padding{L: 1, T: 1, R: 1, B: 1}, BtnRole: theme.PrimaryContainer, BorderColor: theme.Outline, BorderWidth: GridBorderWidth, IconPad: 3, IconSize: 0.75, }
var ComboStateMap = make(map[any]*ComboState)
var ContStyle = &ContainerStyle{ BorderRole: theme.Transparent, BorderWidth: 0.0, Role: theme.Transparent, CornerRadius: 0.0, InsidePadding: f32.Padding{}, OutsidePadding: f32.Padding{L: 2, T: 2, R: 2, B: 2}, }
var DebugWidgets = flag.Bool("debug", false, "Set to debug widgets and write font info")
DebugWidgets is the flag set by command line argument -debug. Many widgets will then draw rectangles around their components (label/value).
var DefImg = &ImgStyle{ Width: 0, Height: 0, OutsidePadding: f32.Padding{L: 5, T: 5, R: 5, B: 5}, BorderRole: theme.Outline, SurfaceRole: theme.Surface, BorderWidth: 1.0, CornerRadius: 4.0, Scaling: FitAll, Align: AlignCenter, }
var DefMemo = &MemoStyle{ ScrollStyle: DefaultScrollStyle, InsidePadding: f32.Padding{L: 2, T: 2, R: 1, B: 2}, OutsidePadding: f32.Padding{L: 5, T: 3, R: 4, B: 3}, Height: 0.5, FontNo: gpu.Mono12, FontSize: 0.9, Color: theme.OnSurface, BorderRole: theme.Outline, BorderWidth: 1.0, CornerRadius: 0.0, Wrap: true, }
var DefaultCb = CbStyle{ FontNo: gpu.Normal12, Role: theme.OnSurface, Padding: f32.Padding{L: 3, T: 1, R: 2, B: 1}, }
var DefaultCheckbox = CbStyle{ FontNo: gpu.Normal12, Role: theme.OnSurface, Padding: f32.Padding{L: 3, T: 1, R: 2, B: 1}, }
var DefaultCombo = ComboStyle{ EditStyle: EditStyle{ FontNo: gpu.Normal12, Color: theme.Surface, BorderColor: theme.Outline, OutsidePadding: f32.Padding{L: 2, T: 2, R: 2, B: 2}, InsidePadding: f32.Padding{L: 2, T: 2, R: 2, B: 2}, BorderWidth: 1, BorderCornerRadius: 4, CursorWidth: 2, EditSize: 0.0, LabelSize: 0.0, LabelRightAdjust: true, LabelSpacing: 2, }, MaxDropDown: 10, NotEditable: false, }
var DefaultEdit = EditStyle{ FontNo: gpu.Normal12, Color: theme.Surface, BorderColor: theme.Outline, OutsidePadding: f32.Padding{L: 2, T: 2, R: 2, B: 2}, InsidePadding: f32.Padding{L: 2, T: 2, R: 2, B: 2}, BorderWidth: 1, BorderCornerRadius: 4, CursorWidth: 2, EditSize: 0.0, LabelSize: 0.0, LabelRightAdjust: true, LabelSpacing: 2, Dp: 2, }
var DefaultHintStyle = HintStyle{ FontNo: gpu.Normal10, FontSize: 0.9, Color: theme.SecondaryContainer, CornerRadius: 5, BorderColor: theme.Outline, BorderWidth: 1, Padding: f32.Padding{L: 3, T: 3, R: 3, B: 2}, Delay: time.Millisecond * 1500, }
var DefaultLabel = LabelStyle{ Padding: f32.Padding{L: 2, T: 2, R: 1, B: 1}, FontNo: gpu.Normal12, Role: theme.OnSurface, }
var DefaultRadioButton = CbStyle{ FontNo: gpu.Normal12, Role: theme.OnSurface, Padding: f32.Padding{L: 3, T: 1, R: 2, B: 1}, }
var DefaultResizer = ResizerStyle{Width: 2, Role: theme.OnSurface}
var DefaultScrollStyle = ScrollStyle{
Width: 0.5,
ScrollbarWidth: 10.0,
MinThumbHeight: 15.0,
TrackAlpha: 0.15,
NormalAlpha: 0.4,
HoverAlpha: 0.8,
ScrollerMargin: 1.0,
ThumbCornerRadius: 3.0,
ScrollFactor: 0.2,
}
var DefaultSwitchStyle = &SwitchStyle{ Padding: f32.Padding{L: 3, T: 1, R: 2, B: 1}, ShadowSize: 4, BorderThickness: 1.0, Track: theme.Surface, Knob: theme.Outline, On: theme.Primary, FontNo: gpu.Normal12, }
var DropdownScrollerStyle = ScrollStyle{
Width: 0.5,
ScrollbarWidth: 8.0,
MinThumbHeight: 10.0,
TrackAlpha: 0.15,
NormalAlpha: 0.4,
HoverAlpha: 0.8,
ScrollerMargin: 1.0,
ThumbCornerRadius: 3.0,
ScrollFactor: 0.2,
}
var Filled = &BtnStyle{ FontNo: gpu.Normal14, BtnRole: theme.Primary, BorderColor: theme.Primary, OutsidePadding: f32.Padding{L: 4, T: 4, R: 4, B: 4}, InsidePadding: f32.Padding{L: 12, T: 5, R: 12, B: 5}, BorderWidth: 0, CornerRadius: 6, IconPad: 0, IconSize: 1.3, }
var GridCheckBox = CbStyle{ FontNo: gpu.Normal12, Role: theme.PrimaryContainer, Padding: f32.Padding{L: 1, T: 1, R: 1, B: 1}, BorderThickness: 0.0, }
var GridCombo = ComboStyle{ EditStyle: GridEdit, MaxDropDown: 10, NotEditable: true, }
var GridEdit = EditStyle{ FontNo: gpu.Normal12, EditSize: 1.0, Color: theme.PrimaryContainer, BorderColor: theme.Transparent, InsidePadding: f32.Padding{L: 2, T: 1, R: 2, B: 1}, CursorWidth: 1, BorderWidth: GridBorderWidth, Dp: 2, }
var GridStyle = ContainerStyle{ BorderRole: theme.Outline, BorderWidth: 0.5, Role: theme.Surface, CornerRadius: 0.0, HasGrid: true, }
var H1C = &LabelStyle{ Padding: f32.Padding{L: 2, T: 3, R: 1, B: 2}, FontNo: gpu.Bold20, Role: theme.OnSurface, Align: AlignCenter, }
var H1L = &LabelStyle{ Padding: f32.Padding{L: 2, T: 3, R: 1, B: 2}, FontNo: gpu.Bold20, Role: theme.OnSurface, Align: AlignLeft, }
var H1R = &LabelStyle{ Padding: f32.Padding{L: 2, T: 3, R: 1, B: 2}, FontNo: gpu.Bold20, Role: theme.OnSurface, Align: AlignRight, }
var H2C = &LabelStyle{ Padding: f32.Padding{L: 2, T: 3, R: 1, B: 2}, FontNo: gpu.Bold16, Role: theme.OnSurface, Align: AlignCenter, }
var H2L = &LabelStyle{ Padding: f32.Padding{L: 2, T: 3, R: 1, B: 2}, FontNo: gpu.Bold16, Role: theme.OnSurface, Align: AlignLeft, }
var H2R = &LabelStyle{ Padding: f32.Padding{L: 2, T: 3, R: 1, B: 2}, FontNo: gpu.Bold16, Role: theme.OnSurface, Align: AlignRight, }
var Header = &BtnStyle{ FontNo: gpu.Normal12, InsidePadding: f32.Padding{L: 2, T: 1, R: 2, B: 1}, BtnRole: theme.Transparent, Width: 0.3, IconPad: 3, IconSize: 0.65, }
var I = &LabelStyle{ Padding: f32.Padding{L: 5, T: 3, R: 1, B: 2}, FontNo: gpu.Italic12, Role: theme.OnSurface, }
var L = &LabelStyle{ Padding: f32.Padding{L: 2, T: 2, R: 1, B: 1}, FontNo: gpu.Normal12, Role: theme.OnSurface, }
var MemoStateMap = make(map[any]*ScrollState)
var Outline = &BtnStyle{ FontNo: gpu.Normal14, BtnRole: theme.Transparent, BorderColor: theme.Outline, OutsidePadding: f32.Padding{L: 5, T: 5, R: 5, B: 5}, InsidePadding: f32.Padding{L: 5, T: 5, R: 5, B: 7}, BorderWidth: 1, CornerRadius: 6, IconPad: 1, IconSize: 1.3, }
var Primary = ContainerStyle{ BorderRole: theme.Outline, BorderWidth: 1, Role: theme.PrimaryContainer, CornerRadius: 0.0, InsidePadding: f32.Padding{L: 2, T: 2, R: 2, B: 2}, OutsidePadding: f32.Padding{L: 2, T: 2, R: 2, B: 2}, }
var ProgressStyle = ContainerStyle{ BorderRole: theme.Outline, BorderWidth: 1, Role: theme.PrimaryContainer, CornerRadius: 2.0, InsidePadding: f32.Padding{L: 2, T: 1, R: 2, B: 1}, OutsidePadding: f32.Padding{L: 2, T: 2, R: 2, B: 2}, Height: 16, }
var Round = &BtnStyle{ FontNo: gpu.Normal14, BtnRole: theme.Primary, BorderColor: theme.Transparent, OutsidePadding: f32.Padding{L: 5, T: 5, R: 5, B: 5}, InsidePadding: f32.Padding{L: 6, T: 6, R: 6, B: 6}, BorderWidth: 0, CornerRadius: -1, IconSize: 1.3, }
var Secondary = ContainerStyle{ BorderRole: theme.Outline, BorderWidth: 0, Role: theme.SecondaryContainer, CornerRadius: 9.0, InsidePadding: f32.Padding{L: 4, T: 4, R: 4, B: 4}, OutsidePadding: f32.Padding{L: 4, T: 4, R: 4, B: 4}, }
var Text = &BtnStyle{ FontNo: gpu.Normal14, BtnRole: theme.Transparent, BorderColor: theme.Transparent, OutsidePadding: f32.Padding{L: 5, T: 5, R: 5, B: 5}, InsidePadding: f32.Padding{L: 5, T: 5, R: 5, B: 7}, BorderWidth: 0, CornerRadius: 6, IconPad: 1, IconSize: 1.3, }
Functions ¶
func CalculateRects ¶
func CalculateRects(hasLabel bool, style *EditStyle, r f32.Rect) (dim, frameRect, valueRect, labelRect f32.Rect)
CalculateRects returns frameRect, valueRect, labelRect based on available space in r
func ClearBuffers ¶
func ClearBuffers()
func Display ¶
Display is used to paint a given widget directly to the screen at given coordinates. Skipping all layout functions.
func DrawCursor ¶
func DrawDebuggingInfo ¶
func DrawVertScrollbar ¶
func DrawVertScrollbar(ctx Ctx, state *ScrollState, style *ScrollStyle)
DrawVertScrollbar will draw a bar at the right edge of the area r. state.Ypos is the position. (Ymax-Yvis) is max Ypos. Yvis is the visible part
func EditMouseHandler ¶
func Hint ¶
Hint should be called if the mouse is inside a widget with a hint i.e. when it is hovered.
func IsKeyClick ¶ added in v0.3.0
func Show ¶
func Show(w Wid)
Show is used to display a form consisting of a widget. Typically, the widget is a column or a scroller.
func VertScollbarUserInput ¶
func VertScollbarUserInput(ctx Ctx, state *ScrollState, style *ScrollStyle)
VertScollbarUserInput will draw a bar at the right edge of the area r.
Types ¶
type BtnStyle ¶
type CachedScrollState ¶ added in v0.5.0
type CachedScrollState struct {
ScrollState
// contains filtered or unexported fields
}
CachedScrollState is a ScrollState with additional data to implement a cache of widgets.
type ComboState ¶
type ComboState struct {
EditState
ScrollState
// contains filtered or unexported fields
}
type ComboStyle ¶
func (*ComboStyle) D ¶ added in v0.2.0
func (s *ComboStyle) D(f *bool) *ComboStyle
func (*ComboStyle) Pad ¶
func (s *ComboStyle) Pad(p float32) *ComboStyle
func (*ComboStyle) Size ¶
func (s *ComboStyle) Size(wl, we float32) *ComboStyle
type ContainerStyle ¶
type ContainerStyle struct {
Width float32
Height float32
BorderRole theme.UIRole
BorderWidth float32
Role theme.UIRole
CornerRadius float32
InsidePadding f32.Padding
OutsidePadding f32.Padding
HasGrid bool
}
func (*ContainerStyle) C ¶
func (style *ContainerStyle) C(c theme.UIRole) *ContainerStyle
func (*ContainerStyle) H ¶
func (style *ContainerStyle) H(h float32) *ContainerStyle
func (*ContainerStyle) R ¶
func (style *ContainerStyle) R(c theme.UIRole) *ContainerStyle
func (*ContainerStyle) Size ¶
func (style *ContainerStyle) Size(w, h, bw float32) *ContainerStyle
func (*ContainerStyle) TotalVerticalPadding ¶ added in v0.2.0
func (style *ContainerStyle) TotalVerticalPadding() float32
func (*ContainerStyle) W ¶
func (style *ContainerStyle) W(w float32) *ContainerStyle
type Ctx ¶
type Ctx struct {
// Rect consists of the X,Y,W,H values. That is the size and position of the area to be drawn.
f32.Rect
Baseline float32
Mode Mode
Win *sys.Window
}
type EditStyle ¶
type EditStyle struct {
FontNo int
Color theme.UIRole
BorderColor theme.UIRole
BorderWidth float32
BorderCornerRadius float32
InsidePadding f32.Padding
OutsidePadding f32.Padding
CursorWidth float32
EditSize float32
LabelSize float32
LabelRightAdjust bool
LabelSpacing float32
Dp int
ReadOnly bool
Disabler *bool
}
type Img ¶
type Img struct {
// contains filtered or unexported fields
}
func NewImage ¶
NewImage generates a new image struct with the rgba image data It can later be displayed by using Draw()
func NewImageFrom ¶
type ImgStyle ¶
type LabelStyle ¶
type LabelStyle struct {
Padding f32.Padding
FontNo int
Role theme.UIRole
Align Alignment
Multiline bool
Width float32
Height float32
}
func (*LabelStyle) Font ¶
func (s *LabelStyle) Font(n int) *LabelStyle
func (*LabelStyle) R ¶
func (s *LabelStyle) R(r theme.UIRole) *LabelStyle
func (*LabelStyle) Top ¶
func (s *LabelStyle) Top(p float32) *LabelStyle
type ResizerState ¶
type ResizerState struct {
StartPos float32
// contains filtered or unexported fields
}
type ResizerStyle ¶
type ScrollState ¶
type ScrollState struct {
// Npos is the item number for the first visible widget
// which can be only partially visible
Npos int
// Nmax is the total number of items
Nmax int
// Nlast is the number of item actually drawn/calculated, will be Nmax when all items are drawn/calculated
Nlast int
// Ypos is the Y position of the first pixel drawn. I.e. the amount scrolled down,
// minimum is 0 at the top, and maximum is Ymax-VisibleHeight.
Ypos float32
// Ylast is the height of all items we have seen, will be equal to Ymax when all items are drawn/calculated
Ylast float32
// Ymax is the total height of all items
Ymax float32
// Dy is the offset from the top of the first item down to the visible window.
// i.e. the height not visible.
Dy float32
// Dragging is a flag that is true while the mous button is down in the scrollbar
Dragging bool
// StartPos is the mouse position on start of dragging
StartPos float32
AtEnd bool
Id int
PendingScroll float32
}
type ScrollStyle ¶ added in v0.5.0
type ScrollStyle struct {
Height float32
Width float32
ScrollbarWidth float32
MinThumbHeight float32
TrackAlpha float32
NormalAlpha float32
HoverAlpha float32
ScrollerMargin float32
ThumbCornerRadius float32
// ScrollFactor is the fraction of the visible area that is scrolled.
ScrollFactor float32
}
type SwitchStyle ¶
type Wid ¶
func BoxText ¶
BoxText will display a colored box with colored text inside it. The text will be centered inside the box.
func CashedScroller ¶
func CashedScroller(state *CachedScrollState, style *ScrollStyle, f func(itemno int) Wid, n func() int) Wid
CaschedScroller is a scrollable container with vertical scrolling, it implements a cache for the elements in the container, suitable for large database tables etc.
func Col ¶
func Col(style *ContainerStyle, widgets ...Wid) Wid
func Flex ¶ added in v0.3.0
func Flex() Wid
Flex is an empty widget that takes up the remaining space after all the other widgets are drawn.
func HorResizer ¶
func HorResizer(state *ResizerState, style *ResizerStyle, widget1 Wid, widget2 Wid) Wid
func Label ¶
func Label(text string, style *LabelStyle) Wid
Label will display a possibly multilied text Padding and alignment can be specified in the style.
func Line ¶
Line draws a line of the given color. If dx or dy is 0, it will be the width or height of the parent.
func ProgressBar ¶ added in v0.3.0
func ProgressBar(fraction float32, style *ContainerStyle) Wid
func Row ¶
func Row(style *ContainerStyle, widgets ...Wid) Wid
func Scroller ¶
func Scroller(state *ScrollState, style *ScrollStyle, widgets ...Wid) Wid
Scroller is a scrollable container (vertical scrolling only)
func Separator ¶
Separator draws a separator. If dx or dy is 0, it will be the width or height of the parent.
func Switch ¶
func Switch(label string, state *bool, action func(), style *SwitchStyle, hint string) Wid
func VertResizer ¶
func VertResizer(state *ResizerState, style *ResizerStyle, widget1 Wid, widget2 Wid) Wid