ui

package module
v0.0.0-...-2b49ed6 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2023 License: MIT Imports: 21 Imported by: 0

README

UI

An immedia mode UI for Go.

Go Report Card GoDoc

What

  • Set of widgets for Go
  • Build on top of https://gioui.org
  • Built to allow nesting function calls

Why

  • For learning
  • For my Go projects
  • For anyone who likes the idea (it's a bit similar to SwiftUI declarative syntax)

When

  • Now it's a work in progress

How

Examples

  • The package provides runnable examples each is named after the widget function.
  • Examples will show widgets in a window
  • Clone the package or go get it to your system.
  • to run an example use. where RoundedCorners is the function name and count=1 is to force running the example regardless of caching.
go test . -run RoundedCorners -count=1

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	STRAWBERRY_100 = Color(0xff8c82)
	STRAWBERRY_300 = Color(0xed5353)
	STRAWBERRY_500 = Color(0xc6262e)
	STRAWBERRY_700 = Color(0xa10705)
	STRAWBERRY_900 = Color(0x7a0000)

	ORANGE_100 = Color(0xffc27d)
	ORANGE_300 = Color(0xffa154)
	ORANGE_500 = Color(0xf37329)
	ORANGE_700 = Color(0xcc3b02)
	ORANGE_900 = Color(0xa62100)

	BANANA_100 = Color(0xfff394)
	BANANA_300 = Color(0xffe16b)
	BANANA_500 = Color(0xf9c440)
	BANANA_700 = Color(0xd48e15)
	BANANA_900 = Color(0xad5f00)

	LIME_100 = Color(0xd1ff82)
	LIME_300 = Color(0x9bdb4d)
	LIME_500 = Color(0x68b723)
	LIME_700 = Color(0x3a9104)
	LIME_900 = Color(0x206b00)

	MINT_100 = Color(0x89ffdd)
	MINT_300 = Color(0x43d6b5)
	MINT_500 = Color(0x28bca3)
	MINT_700 = Color(0x0e9a83)
	MINT_900 = Color(0x007367)

	BLUEBERRY_100 = Color(0x8cd5ff)
	BLUEBERRY_300 = Color(0x64baff)
	BLUEBERRY_500 = Color(0x3689e6)
	BLUEBERRY_700 = Color(0x0d52bf)
	BLUEBERRY_900 = Color(0x002e99)

	BUBBLEGUM_100 = Color(0xfe9ab8)
	BUBBLEGUM_300 = Color(0xf4679d)
	BUBBLEGUM_500 = Color(0xde3e80)
	BUBBLEGUM_700 = Color(0xbc245d)
	BUBBLEGUM_900 = Color(0x910e38)

	GRAPE_100 = Color(0xe4c6fa)
	GRAPE_300 = Color(0xcd9ef7)
	GRAPE_500 = Color(0xa56de2)
	GRAPE_700 = Color(0x7239b3)
	GRAPE_900 = Color(0x452981)

	COCOA_100 = Color(0xa3907c)
	COCOA_300 = Color(0x8a715e)
	COCOA_500 = Color(0x715344)
	COCOA_700 = Color(0x57392d)
	COCOA_900 = Color(0x3d211b)

	SILVER_100 = Color(0xfafafa)
	SILVER_300 = Color(0xd4d4d4)
	SILVER_500 = Color(0xabacae)
	SILVER_700 = Color(0x7e8087)
	SILVER_900 = Color(0x555761)

	SLATE_100 = Color(0x95a3ab)
	SLATE_300 = Color(0x667885)
	SLATE_500 = Color(0x485a6c)
	SLATE_700 = Color(0x273445)
	SLATE_900 = Color(0x0e141f)

	BLACK_100 = Color(0x666666)
	BLACK_300 = Color(0x4d4d4d)
	BLACK_500 = Color(0x333333)
	BLACK_700 = Color(0x1a1a1a)
	BLACK_900 = Color(0x000000)

	WHITE = Color(0xffffff)
)

ElementaryOS palette https://github.com/elementary/stylesheet/blob/master/src/gtk-4.0/_palette.scss

View Source
var (
	ACCENT_COLOR_100 = BLUEBERRY_100
	ACCENT_COLOR_300 = BLUEBERRY_300
	ACCENT_COLOR_500 = BLUEBERRY_500
	ACCENT_COLOR_700 = BLUEBERRY_700
	ACCENT_COLOR_900 = BLUEBERRY_900
	ACCENT_COLOR     = MixColor(BLUEBERRY_300, BLUEBERRY_500, 25)
)
View Source
var (
	IconFolder = Icon(icons.FileFolderOpen, Theme.SecondaryTextColor)
	IconFile   = Icon(icons.ActionDescription, Theme.SecondaryTextColor)
	IconUp     = Icon(icons.NavigationArrowUpward, Theme.TextColor)
)
View Source
var (
	IconCheckbox       = Inset05(Icon(icons.ToggleCheckBoxOutlineBlank, Theme.CheckboxColor))
	IconCheckboxActive = Inset05(Icon(icons.ToggleCheckBox, Theme.CheckboxColor))
)
View Source
var (
	Flexed = layout.Flexed
	Rigid  = layout.Rigid
)
View Source
var (
	RowSpacer1 = Rigid(HSpacer1)
	RowSpacer2 = Rigid(HSpacer2)
	RowSpacer3 = Rigid(HSpacer3)
	RowSpacer4 = Rigid(HSpacer4)
	RowSpacer5 = Rigid(HSpacer5)
	RowSpacer6 = Rigid(HSpacer6)
)
View Source
var (
	ColSpacer1 = Rigid(WSpacer1)
	ColSpacer2 = Rigid(WSpacer2)
	ColSpacer3 = Rigid(WSpacer3)
	ColSpacer4 = Rigid(WSpacer4)
	ColSpacer5 = Rigid(WSpacer5)
	ColSpacer6 = Rigid(WSpacer6)
)

Insets

View Source
var (
	WSpacer1 = layout.Spacer{Width: SpaceUnit}.Layout
	WSpacer2 = layout.Spacer{Width: SpaceUnit * 2}.Layout
	WSpacer3 = layout.Spacer{Width: SpaceUnit * 3}.Layout
	WSpacer4 = layout.Spacer{Width: SpaceUnit * 4}.Layout
	WSpacer5 = layout.Spacer{Width: SpaceUnit * 5}.Layout
	WSpacer6 = layout.Spacer{Width: SpaceUnit * 6}.Layout
)

Spaces

View Source
var (
	HSpacer1 = layout.Spacer{Height: SpaceUnit}.Layout
	HSpacer2 = layout.Spacer{Height: SpaceUnit * 2}.Layout
	HSpacer3 = layout.Spacer{Height: SpaceUnit * 3}.Layout
	HSpacer4 = layout.Spacer{Height: SpaceUnit * 4}.Layout
	HSpacer5 = layout.Spacer{Height: SpaceUnit * 5}.Layout
	HSpacer6 = layout.Spacer{Height: SpaceUnit * 6}.Layout
)
View Source
var (
	SelectedTabBgColor = MixColor(ACCENT_COLOR_100, WHITE, 20)
	SelectedTabFgColor = ACCENT_COLOR_500
)
View Source
var (
	TooltipFgColor = WHITE
	TooltipBgColor = Alpha(BLACK_500, 242)
)
View Source
var AlignEnd = TextAlignment(text.End)
View Source
var AlignMiddle = TextAlignment(text.Middle)
View Source
var AlignStart = TextAlignment(text.Start)
View Source
var OneLine = MaxLines(1)
View Source
var Theme = ThemeStyle{
	FontSize:           13,
	FontFamily:         fontShaper,
	FontWeight:         font.Normal,
	TextAlignment:      text.Start,
	TextColor:          BLACK_500,
	MaxLines:           0,
	BorderRadius:       10,
	BackgroundColor:    WHITE,
	SecondaryTextColor: SILVER_500,

	DangerColor:       STRAWBERRY_500,
	SuccessColor:      LIME_700,
	WarningColor:      BANANA_900,
	InputBgColor:      SILVER_100,
	ViewsBgColor:      WHITE,
	SidebarBgColor:    MixColor(SILVER_100, SILVER_300, 75),
	BorderColor:       MixColor(SILVER_300, WHITE, 70),
	ActiveBorderColor: SILVER_500,
	CardColor:         MixColor(SILVER_100, SILVER_300, 75),
	CheckboxColor:     ACCENT_COLOR_500,
}
View Source
var (
	ToolbarBgColor = SILVER_100
)

Functions

func Alpha

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

func Color

func Color(hex int) color.NRGBA

func LayoutToWrapper

func LayoutToWrapper(r func(C, W) D) func(w W) W

func LineEditor

func LineEditor() widget.Editor

func Max

func Max[T Numeric](s []T) (m T)

func MixColor

func MixColor(c1, c2 color.NRGBA, percent int) color.NRGBA

Types

type C

type C = layout.Context

type Clickable

type Clickable = widget.Clickable

type ClickableList

type ClickableList struct {
	List
	Btns map[int]*Clickable
}

func NewClickableList

func NewClickableList() ClickableList

func (*ClickableList) Layout

func (l *ClickableList) Layout(len int, ele layout.ListElement, onClick func(i int)) W

type D

type D = layout.Dimensions

func EmptyWidget

func EmptyWidget(c C) D

type DP

type DP = unit.Dp
var (
	Pt            = f32.Pt
	SpaceUnit  DP = 8
	BorderSize DP = 1
)

type DirectoryBrowser

type DirectoryBrowser struct {
	List        List
	Btns        map[string]*Clickable
	Up          Clickable
	MinItemSize int
}

func NewDirectoryBrowser

func NewDirectoryBrowser() DirectoryBrowser

func (*DirectoryBrowser) Layout

func (d *DirectoryBrowser) Layout(dist *string) W

type FlexChild

type FlexChild = layout.FlexChild

type List

type List = layout.List

func NewVerticalList

func NewVerticalList() List

type Numeric

type Numeric interface {
	constraints.Float | constraints.Integer
}

type P

type P = image.Point

type SP

type SP = unit.Sp

type TabChild

type TabChild struct {
	Name  string
	Panel W
}

type Tabs

type Tabs struct {
	List      List
	Active    string
	Clickable map[string]*Clickable
}

func (*Tabs) Layout

func (l *Tabs) Layout(tabs ...*TabChild) W

type ThemeStyle

type ThemeStyle struct {
	FontSize      SP
	FontFamily    *text.Shaper
	FontWeight    font.Weight
	TextAlignment text.Alignment
	TextColor     color.NRGBA
	MaxLines      int
	BorderRadius  int

	BackgroundColor    color.NRGBA
	SecondaryTextColor color.NRGBA

	DangerColor  color.NRGBA
	SuccessColor color.NRGBA
	WarningColor color.NRGBA

	InputBgColor      color.NRGBA
	ViewsBgColor      color.NRGBA
	SidebarBgColor    color.NRGBA
	BorderColor       color.NRGBA
	ActiveBorderColor color.NRGBA
	CardColor         color.NRGBA
	CheckboxColor     color.NRGBA
}

type W

type W = layout.Widget

func Background

func Background(background color.NRGBA, w W) W
Example
colors := []color.NRGBA{
	STRAWBERRY_100, STRAWBERRY_300, STRAWBERRY_500, STRAWBERRY_700, STRAWBERRY_900,
	ORANGE_100, ORANGE_300, ORANGE_500, ORANGE_700, ORANGE_900,
	BANANA_100, BANANA_300, BANANA_500, BANANA_700, BANANA_900,
	LIME_100, LIME_300, LIME_500, LIME_700, LIME_900,
	MINT_100, MINT_300, MINT_500, MINT_700, MINT_900,
	BLUEBERRY_100, BLUEBERRY_300, BLUEBERRY_500, BLUEBERRY_700, BLUEBERRY_900,
	BUBBLEGUM_100, BUBBLEGUM_300, BUBBLEGUM_500, BUBBLEGUM_700, BUBBLEGUM_900,
	GRAPE_100, GRAPE_300, GRAPE_500, GRAPE_700, GRAPE_900,
	COCOA_100, COCOA_300, COCOA_500, COCOA_700, COCOA_900,
	SILVER_100, SILVER_300, SILVER_500, SILVER_700, SILVER_900,
	SLATE_100, SLATE_300, SLATE_500, SLATE_700, SLATE_900,
	BLACK_100, BLACK_300, BLACK_500, BLACK_700, BLACK_900,
}

l := NewVerticalList()
w := func(c C) D {
	return l.Layout(c, len(colors), func(c C, i int) D {
		return Background(colors[i], Text(""))(c)
	})
}

exampleLoop(w)
Output:

func Border

func Border(w W) W
Example
box := Inset1(
	Border(
		Inset1(
			Text("Normal Border"),
		),
	),
)

boxActive := Inset1(
	BorderActive(
		Inset1(
			Text("Active Border"),
		),
	),
)

exampleLoop(
	Rows(
		Flexed(1, box),
		Flexed(1, boxActive),
	),
)
Output:

func BorderActive

func BorderActive(w W) W

func Button

func Button(clickable *Clickable, label string) W

func Centered

func Centered(w W) W

func Chart

func Chart[T Numeric](ds []T, height float32) W
Example
exampleLoop(
	Rows(
		Flexed(1, Chart([]int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 2, 1}, 100)),
		Flexed(1, Chart([]int{1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 9, 1, 5, 1}, 100)),
	),
)
Output:

func Checkbox

func Checkbox(btn *Clickable, value bool, onclick func()) W

func CheckboxBool

func CheckboxBool(btn *Clickable, value *bool) W

func CheckboxBtn

func CheckboxBtn(value bool, btn *Clickable) W

func Columns

func Columns(children ...layout.FlexChild) W

func ColumnsVCentered

func ColumnsVCentered(children ...layout.FlexChild) W

func Constraint

func Constraint(width, height int, w W) W

func FormRow

func FormRow(children ...layout.FlexChild) W

func Grid

func Grid(l *List, count int, minItemSize int, ele layout.ListElement) W

func HR

func HR(sz int) W
Example
exampleLoop(
	Inset1(
		Rows(
			Flexed(1, Text("Line 1")),
			Flexed(1, HR(1)),
			Flexed(1, Text("Line 2")),
			Flexed(1, HR(2)),
			Flexed(1, Text("Line 3")),
		),
	),
)
Output:

func Icon

func Icon(b []byte, color color.NRGBA) W

func Label

func Label(s string) W

func LayoutToWidget

func LayoutToWidget(r func(C, W) D, w W) W

func OnClick

func OnClick(btn *Clickable, w W, onclick func()) W

func Panel

func Panel(title string, w W) W

func RoundedCorners

func RoundedCorners(w W) W
Example
box := Inset1(
	RoundedCorners(
		Background(
			STRAWBERRY_100,
			Inset1(
				Text("Hello world"),
			),
		),
	),
)

exampleLoop(
	Rows(
		Flexed(1, box),
		Flexed(1, box),
		Flexed(1, box),
	),
)
Output:

func Rows

func Rows(children ...layout.FlexChild) W

func TabButton

func TabButton(cl *Clickable, active bool, l string) W

func Text

func Text(s string) W

func TextInput

func TextInput(editor *widget.Editor, hint string) W

func ToolbarButton

func ToolbarButton(clickable *Clickable, icon W, desc string) W

func Tooltip

func Tooltip(attachTo W, s string) W

func VR

func VR(sz int) W
Example
exampleLoop(
	Inset1(
		Columns(
			Flexed(1, Text("Line 1")),
			Flexed(1, VR(1)),
			Flexed(1, Text("Line 2")),
			Flexed(1, VR(2)),
			Flexed(1, Text("Line 3")),
		),
	),
)
Output:

func WidgetIf

func WidgetIf(cond bool, w W) W

func Wrap

func Wrap(w W, wrappers ...Wrapper) W

func ZebraList

func ZebraList(l *List, len int, ele layout.ListElement) W

type Wrapper

type Wrapper = func(W) W

func Font

func Font(f *text.Shaper) Wrapper

func FontEnlarge

func FontEnlarge(s float32) Wrapper

func FontSize

func FontSize(s SP) Wrapper

func FontWeight

func FontWeight(f font.Weight) Wrapper

func Margin

func Margin(t, r, b, l unit.Dp) Wrapper

func MaxLines

func MaxLines(i int) Wrapper

func TextAlignment

func TextAlignment(a text.Alignment) Wrapper

func TextColor

func TextColor(col color.NRGBA) Wrapper

Jump to

Keyboard shortcuts

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