Categorygithub.com/mjl-/duit
modulepackage
0.0.0-20201214150121-e34272092e47
Repository: https://github.com/mjl-/duit.git
Documentation: pkg.go.dev

# README

GoDoc

duit - developer ui toolkit

WARNING: this library is work in progress. backwards incompatible changes will be made.

details

duit is a pure go (*), cross platform, MIT-licensed ui toolkit for developers. the api is small and uncomplicated.

duit works on the bsd's, linux and macos. it should be easy to get running on plan 9. for now, use the windows subsystem for linux on windows.

(*) duit currently needs a helper tool called devdraw, from plan9port (aka plan 9 from user space). plan9port is available for most unix systems, with devdraw in an x11 and native macos variant.

screenshots

duit screenshot

you should just try duit. using it and interacting with it gives a more complete impression.

instructions

setting this up currently requires some effort:

  • install plan9port, see https://9fans.github.io/plan9port/ (use their install instructions)
  • install a nice font. i use & recommend lato for a modern look. duit will automatically pick it up through $font (through plan9port's fontsrv), e.g.: export font=/mnt/font/Lato-Regular/15a/font

you should now be able to run the code in examples/

devdraw is not yet available as a native binary for windows. for now, use the windows subsystem for linux (ubuntu) on windows along with Xming. see https://github.com/elrzn/acme-wsl for instructions.

created with duit

see https://github.com/mjl- for applications. applications created with duit by other developers:

  • be the first to add your application here! (:

more

# Packages

# Functions

Alert creates a new window that show text and a button labeled OK that closes the window.
AppdataDir returns the directory where the application can store its files, like configuration, inside os.UserConfigDir.
CenterUI returns a UI that shows ui horizontally centered, with space as padding.
KidsDraw draws a UI by drawing all its kids.
KidsFirstFocus delivers the FirstFocus request to the first leaf UI, and returns the location where the mouse should warp to.
KidsFocus delivers the Focus request to the first leaf UI, and returns the location where the mouse should warp to.
KidsKey delivers key event key to the UI at m.
KidsLayout is called by layout UIs before they do their own layouts.
KidsMark finds o in this UI subtree (self and kids), marks it as needing layout or draw (forLayout false), and returns whether it found and marked the UI.
KidsMouse delivers mouse event m to the UI at origM (often the same, but not in case button is held pressed).
KidsPrint calls Print on each kid UI.
NewBox returns a box containing all uis in its Kids field.
NewDUI creates a DUI for an application called name, and optional opts.
NewEdit returns an Edit initialized with f.
NewKids turns UIs into Kids containing those UIs.
NewMiddle returns a Middle set up with padding around the sides.
NewReverseBox returns a box containing all uis in original order in its Kids field, with the Reverse field set.
NewScroll returns a full-height scroll bar containing ui.
NSpace is a convenience function to create N identical spaces.
NSpaceXY is a convenience function to create N identical SpaceXY's.
PrintUI is a helper function UIs can use to implement UI.Print.
ReadImage decodes an image from f for use on display.
ReadImagePath is a convenience function that opens path and calls ReadImage.
SpacePt returns a space with p.X for left/right and p.Y for top/bottom.
SpaceXY returns a space with x for left/right and y for top/bottom.

# Constants

regardless of lowDPI/hiDPI, won't be scaled.
Mouse buttons, see draw.Mouse.Buttons.
Mouse buttons, see draw.Mouse.Buttons.
Mouse buttons, see draw.Mouse.Buttons.
wheel up.
wheel down.
UI and its children do not need layout/draw.
UI itself needs layout/draw; kids will also get a UI.Layout/UI.Draw call, with force set.
UI itself does not need layout/draw, but one of its children does, so pass the call on.
FitNormal lays out over full available width.
FitSlim lays out only as much as needed.
Align to the left by default, for example in a grid.
An error occurred that may be recovered from.
Call the function.
Key typed.
Mouse movement and/or button changes.
window was resized, reattach; does not have/need a field in Input.
in lowDPI pixels.
Align vertically in the middle by default, for example in a box (line) or grid.

# Variables

LowDPI padding, drawn with a distinct color when in vi modes.

# Structs

Box keeps elements on a line as long as they fit, then moves on to the next line.
Button with text and optional icon with a click function.
Buttongroup shows multiple joined buttons, with one of them active.
Checkbox holds a true/false value.
Colors represents the style in one state of the UI.
Colorset is typically used to style buttons.
Cursor represents the current editing location, and optionally text selection.
DUI represents a window and all UI state for that window.
DUIOpts are options for creating a new DUI.
Edit is a text editor inspired by acme, with vi key bindings.
EditColors hold all the colors used for rendering an Edit.
Event is returned by handlers, such as click or key handlers.
Field is a single line text field.
Grid lays out other UIs in a table-like grid.
Gridlist is a table-like list of selectable values.
Gridrow is used for each row in a Gridlist.
Icon is a single codepoint in the given font.
Image shows an image.
Input is an input event that is typically passed into DUI through Input().
Kid holds a UI and its layout/draw state.
Label draws multiline text in a single font.: Keys: cmd-c, copy text \n, like button1 click, calls the Click function.
List shows values, allowing for single or multiple selection, with callbacks when the selection changes.
ListValue is used for values in a List.
Middle lays out a single child in the middle of the available space, both vertically and horizontally.
Pick makes it possible to create responsive UI layouts.
Place contains other UIs it can position absolute, possibly on top of each other.
Radiobutton is typically part of a group of radiobuttons, with exactly one of them selected.
Result holds the effects of a mouse/key event, as implement by UIs.
Scroll shows a part of its single child, typically a box, and lets you scroll the content.
Space represents the padding or margin on a UI element.
Split is a horizontal or vertical split of the available space, with 1 or more UIs.
Tabs has a Buttongroup and displays only the active selected UI.

# Interfaces

EditReader provides a reader to the current contents of an Edit.
SeekReaderAt is used as a source for edits.
UI is the interface implemented by a user interface element.

# Type aliases

Gridfit is the layout strategy for a Gridlist.
Halign represents horizontal align of elements in a Grid.
InputType presents the type of an input event.
RadiobuttonGroup is the group of all possible radiobuttons of which only one can be selected.
State represents the layout/draw state of the UI of a Kid.
Valign represents vertical align of elements in a Grid, or in a Box.