beef331 / website

Code for the official Nim programming language website
https://nim-lang.org
19 stars 1 forks source link

This Month With Nim: uing #76

Closed neroist closed 1 year ago

neroist commented 1 year ago

Name: uing

Author: Jasmine

Posting: uing is a fork of ui that wraps libui-ng instead of the old and unmaintained libui library. I made this fork because libui seems to be abandoned (the most recent update to libui was 2 years ago), and ui hasn't been updated in a long time aswell (coincidentally, the most recent change also happens to be 2 years ago).

uing implements many things that ui doesn't have such as:

Uing's documentation is hosted here, and examples can be found here. For rawui, I suggest you look at libui-ng's official docs here: https://libui-ng.github.io/libui-ng/.

Here's a simple example:

import std/times

import uing

proc main = 
  let window = newWindow("Date / Time", 320, 240)
  window.margined = true

  let grid = newGrid(true)
  window.child = grid

  let
    dateTimeLabel = newLabel()
    dateLabel = newLabel()
    timeLabel = newLabel()

    dateTimePicker = newDateTimePicker() do (dt: DateTimePicker):
      dateTimeLabel.text = dt.time.format("ddd MMM d HH:mm:ss UUUU")

    datePicker = newDatePicker() do (dt: DateTimePicker):
      dateLabel.text = dt.time.format("yyyy-MM-dd")

    timePicker = newTimePicker() do (dt: DateTimePicker):
      timeLabel.text = dt.time.format("hh:mm:ss")

    nowButton = newButton("Now") do (_: Button): 
      timePicker.time = now()
      datePicker.time = now()

    epochButton = newButton("Unix epoch") do (_: Button):
      dateTimePicker.time = dateTime(1969, mDec, 31, 19)

  grid.add(dateTimePicker, 0, 0, 2, 1, true, AlignFill, false, AlignFill)
  grid.add(datePicker, 0, 1, 1, 1, true, AlignFill, false, AlignFill)
  grid.add(timePicker, 1, 1, 1, 1, true, AlignFill, false, AlignFill)

  grid.add(dateTimeLabel, 0, 2, 2, 1, true, AlignCenter, false, AlignFill)
  grid.add(dateLabel, 0, 3, 1, 1, true, AlignCenter, false, AlignFill)
  grid.add(timeLabel, 1, 3, 1, 1, true, AlignCenter, false, AlignFill)

  grid.add(nowButton, 0, 4, 1, 1, true, AlignFill, true, AlignEnd)
  grid.add(epochButton, 1, 4, 1, 1, true, AlignFill, true, AlignEnd)

  show window
  mainLoop()

init()
main()