123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- import sigui/[uibase, mouseArea, animations, dolars]
- type
- Switch* = ref object of Uiobj
- enabled*: Property[bool] = true.property
- isOn*: Property[bool]
- color*: Property[Col] = color(0, 0, 0).property
- registerComponent Switch
- method init*(this: Switch) =
- procCall this.super.init()
-
- this.isOn.changed.connectTo this, val:
- echo this
- this.makeLayout:
- w = 40
- h = 20
- - MouseArea() as mouse:
- this.fill(parent)
- this.mouseDownAndUpInside.connectTo root:
- if root.enabled[]:
- root.isOn[] = not root.isOn[]
- - UiRectBorder():
- this.fill(parent)
- this.binding radius: min(this.w[], this.h[]) / 2 - 2
- borderWidth = 2
- color = color(0.7, 0.7, 0.7)
- - UiRect():
- centerY = parent.center
- this.binding w: min(parent.w[], parent.h[]) - 8
- this.binding h: this.w[]
- this.binding radius: this.w[] / 2
- this.binding x:
- if root.isOn[]:
- parent.w[] - this.w[] - 4
- else:
- 4'f32
- this.binding color: root.color[]
- - this.x.transition(0.4's):
- easing = outCubicEasing
- this.newChildsObject = mouse
- when isMainModule:
- preview(clearColor = color(1, 1, 1), margin = 20, withWindow = proc: Uiobj =
- var r = Switch()
- init r
- r
- )
|