Skip to content

Latest commit

 

History

History
925 lines (616 loc) · 12.3 KB

widgets.md

File metadata and controls

925 lines (616 loc) · 12.3 KB

Widgets

BaseWidget

renderable BaseWidget
Fields
  • sensitive: bool = true
  • sizeRequest: tuple[x, y: int] = (-1, -1)
  • tooltip: string = ""
Setters
  • margin: int
  • margin: Margin

Window

renderable Window of BaseWidget
Fields
  • All fields from BaseWidget
  • title: string
  • titlebar: Widget
  • defaultSize: tuple[width, height: int] = (800, 600)
  • child: Widget
Events
  • close: proc ()
Adders
Example
Window:
  Label(text = "Hello, world")

Box

renderable Box of BaseWidget
Fields
  • All fields from BaseWidget
  • orient: Orient
  • spacing: int
  • children: seq[BoxChild[Widget]]
  • style: set[BoxStyle]
Adders
  • All adders from BaseWidget
  • add
    • expand = true
    • hAlign = AlignFill
    • vAlign = AlignFill
Example
Box:
  orient = OrientX
  Label(text = "Label")
  Button(text = "Button") {.expand: false.}
Box:
  orient = OrientY
  margin = 12
  spacing = 6
  for it in 0 ..< 5:
    Label(text = "Label " & $it)
HeaderBar {.addTitlebar.}:
  Box {.addLeft.}:
    style = {BoxLinked}
    for it in 0 ..< 5:
      Button {.expand: false.}:
        text = "Button " & $it
        proc clicked() =
          echo it

Overlay

renderable Overlay of BaseWidget
Fields
  • All fields from BaseWidget
  • child: Widget
  • overlays: seq[OverlayChild[Widget]]
Adders
  • All adders from BaseWidget
  • add
  • addOverlay
    • hAlign = AlignFill
    • vAlign = AlignFill

Label

renderable Label of BaseWidget
Fields
  • All fields from BaseWidget
  • text: string
  • xAlign: float = 0.5
  • yAlign: float = 0.5
  • ellipsize: EllipsizeMode
  • wrap: bool = false
  • useMarkup: bool = false
  • style: set[LabelStyle]
Example
Label:
  text = "Hello, world!"
  xAlign = 0.0
  ellipsize = EllipsizeEnd
Label:
  text = "Test ".repeat(50)
  wrap = true
Label:
  text = "<b>Bold</b>, <i>Italic</i>, <span font=\"20\">Font Size</span>"
  useMarkup = true

Icon

renderable Icon of BaseWidget
Fields
  • All fields from BaseWidget
  • name: string
  • pixelSize: int = -1
Example
Icon:
  name = "list-add-symbolic"
Icon:
  name = "object-select-symbolic"
  pixelSize = 100

Button

renderable Button of BaseWidget
Fields
  • All fields from BaseWidget
  • style: set[ButtonStyle]
  • child: Widget
  • shortcut: string
Setters
  • text: string
  • icon: string
Events
  • clicked: proc ()
Adders
Example
Button:
  icon = "list-add-symbolic"
  style = {ButtonSuggested}
  proc clicked() =
    echo "clicked"
Button:
  text = "Delete"
  style = {ButtonDestructive}
Button:
  text = "Inactive Button"
  sensitive = false
Button:
  text = "Copy"
  shortcut = "<Ctrl>C"
  proc clicked() =
    app.writeClipboard("Hello, world!")

HeaderBar

renderable HeaderBar of BaseWidget
Fields
  • All fields from BaseWidget
  • title: Widget
  • showTitleButtons: bool = true
  • left: seq[Widget]
  • right: seq[Widget]
Adders
  • All adders from BaseWidget
  • addTitle
  • addLeft
  • addRight
Example
Window:
  title = "Title"
  HeaderBar {.addTitlebar.}:
    Button {.addLeft.}:
      icon = "list-add-symbolic"
    Button {.addRight.}:
      icon = "open-menu-symbolic"

ScrolledWindow

renderable ScrolledWindow of BaseWidget
Fields
Adders

Entry

renderable Entry of BaseWidget
Fields
  • All fields from BaseWidget
  • text: string
  • placeholder: string
  • width: int = -1
  • maxWidth: int = -1
  • xAlign: float = 0.0
  • visibility: bool = true
  • invisibleChar: Rune = '*'.Rune
  • style: set[EntryStyle]
Events
  • changed: proc (text: string)
  • activate: proc ()
Example
Entry:
  text = app.text
  proc changed(text: string) =
    app.text = text
Entry:
  text = app.query
  placeholder = "Search..."
  proc changed(query: string) =
    app.query = query

  proc activate() =
    ## Runs when enter is pressed
    echo app.query
Entry:
  placeholder = "Password"
  visibility = false
  invisibleChar = '*'.Rune

Paned

renderable Paned of BaseWidget
Fields
  • All fields from BaseWidget
  • orient: Orient
  • initialPosition: int
  • first: PanedChild[Widget]
  • second: PanedChild[Widget]
Adders
  • All adders from BaseWidget
  • add
    • resize = true
    • shrink = false
Example
Paned:
  initialPosition = 200
  Box(orient = OrientY) {.resize: false.}:
    Label(text = "Sidebar")
  Box(orient = OrientY) {.resize: true.}:
    Label(text = "Content")

CustomWidget

renderable CustomWidget of BaseWidget
Fields
  • All fields from BaseWidget
  • focusable: bool
  • events: CustomWidgetEvents
Events
  • mousePressed: proc (event: ButtonEvent): bool
  • mouseReleased: proc (event: ButtonEvent): bool
  • mouseMoved: proc (event: MotionEvent): bool
  • scroll: proc (event: ScrollEvent): bool
  • keyPressed: proc (event: KeyEvent): bool
  • keyReleased: proc (event: KeyEvent): bool

DrawingArea

renderable DrawingArea of CustomWidget
Fields
Events
  • draw: proc (ctx: CairoContext; size: (int, int)): bool

GlArea

renderable GlArea of CustomWidget
Fields
  • All fields from CustomWidget
  • useEs: bool = false
  • requiredVersion: tuple[major, minor: int] = (4, 3)
  • hasDepthBuffer: bool = true
  • hasStencilBuffer: bool = false
Events
  • setup: proc (size: (int, int)): bool
  • render: proc (size: (int, int)): bool

ColorButton

renderable ColorButton of BaseWidget
Fields
  • All fields from BaseWidget
  • color: tuple[r, g, b, a: float] = (0.0, 0.0, 0.0, 1.0)
  • useAlpha: bool = false
Events
  • changed: proc (color: tuple[r, g, b, a: float])

Switch

renderable Switch of BaseWidget
Fields
Events
  • changed: proc (state: bool)
Example
Switch:
  state = app.state
  proc changed(state: bool) =
    app.state = state

ToggleButton

renderable ToggleButton of Button
Fields
  • All fields from Button
  • state: bool
Events
  • changed: proc (state: bool)
Example
ToggleButton:
  text = "Current State: " & $app.state
  state = app.state
  proc changed(state: bool) =
    app.state = state

LinkButton

renderable LinkButton of Button
Fields
  • All fields from Button
  • uri: string
  • visited: bool

CheckButton

renderable CheckButton of BaseWidget
Fields
Events
  • changed: proc (state: bool)
Example
CheckButton:
  state = app.state
  proc changed(state: bool) =
    app.state = state

Popover

renderable Popover of BaseWidget
Fields
Adders

PopoverMenu

renderable PopoverMenu of BaseWidget
Fields
  • All fields from BaseWidget
  • pages: Table[string, Widget]
Adders

MenuButton

renderable MenuButton of BaseWidget
Fields
  • All fields from BaseWidget
  • child: Widget
  • popover: Widget
  • style: set[ButtonStyle]
Setters
  • text: string
  • icon: string
Adders

ModelButton

renderable ModelButton of BaseWidget
Fields
  • All fields from BaseWidget
  • text: string
  • icon: string
  • menuName: string
Events
  • clicked: proc ()

Separator

renderable Separator of BaseWidget
Fields

TextView

renderable TextView of BaseWidget
Fields
  • All fields from BaseWidget
  • buffer: TextBuffer
  • monospace: bool = false
  • cursorVisible: bool = true
  • editable: bool = true
  • acceptsTab: bool = true
  • indent: int = 0
Events
  • changed: proc ()

ListBoxRow

renderable ListBoxRow of BaseWidget
Fields
Events
  • activate: proc ()
Adders
Example
ListBox:
  for it in 0 ..< 10:
    ListBoxRow {.addRow.}:
      proc activate() =
        echo it

      Label(text = $it)

ListBox

renderable ListBox of BaseWidget
Fields
  • All fields from BaseWidget
  • rows: seq[Widget]
  • selectionMode: SelectionMode
  • selected: HashSet[int]
Events
  • select: proc (rows: HashSet[int])
Adders
Example
ListBox:
  for it in 0 ..< 10:
    Label(text = $it)

FlowBoxChild

renderable FlowBoxChild of BaseWidget
Fields
Adders
Example
FlowBox:
  columns = 1 .. 5
  for it in 0 ..< 10:
    FlowBoxChild {.addChild.}:
      Label(text = $it)

FlowBox

renderable FlowBox of BaseWidget
Fields
  • All fields from BaseWidget
  • homogeneous: bool
  • rowSpacing: int
  • columnSpacing: int
  • columns: HSlice[int, int] = 1 .. 5
  • selectionMode: SelectionMode
  • children: seq[Widget]
Adders
Example
FlowBox:
  columns = 1 .. 5
  for it in 0 ..< 10:
    Label(text = $it)

Frame

renderable Frame of BaseWidget
Fields
  • All fields from BaseWidget
  • label: string
  • align: tuple[x, y: float] = (0.0, 0.0)
  • child: Widget
Adders
Example
Frame:
  label = "Frame Title"
  align = (0.2, 0.0)
  Label:
    text = "Content"

DialogButton

renderable DialogButton
Fields
  • text: string
  • response: DialogResponse
  • style: set[ButtonStyle]
Setters
  • res: DialogResponseKind

Dialog

renderable Dialog of Window
Fields
  • All fields from Window
  • buttons: seq[DialogButton]
Adders
  • All adders from Window
  • addButton

BuiltinDialog

renderable BuiltinDialog
Fields
  • title: string
  • buttons: seq[DialogButton]
Adders
  • addButton

FileChooserDialog

renderable FileChooserDialog of BuiltinDialog
Fields
  • All fields from BuiltinDialog
  • action: FileChooserAction
  • filename: string

ColorChooserDialog

renderable ColorChooserDialog of BuiltinDialog
Fields
  • All fields from BuiltinDialog
  • color: tuple[r, g, b, a: float] = (0.0, 0.0, 0.0, 1.0)
  • useAlpha: bool = false

MessageDialog

renderable MessageDialog of BuiltinDialog
Fields

AboutDialog

renderable AboutDialog of BaseWidget
Fields
  • All fields from BaseWidget
  • programName: string
  • logo: string
  • copyright: string
  • version: string
  • license: string
  • credits: seq[(string, seq[string])]