Skip to content

Commit

Permalink
added helper type to set/toggle bools
Browse files Browse the repository at this point in the history
  • Loading branch information
Nimaoth committed Sep 8, 2024
1 parent f3bef27 commit b3954ed
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/scripting_api.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import std/[algorithm, sequtils, sugar, strutils]
import std/[algorithm, sequtils, sugar, strutils, options]
import misc/custom_unicode

when defined(nimscript):
Expand Down Expand Up @@ -37,6 +37,26 @@ type ScrollBehaviour* = enum
ScrollToMargin = "ScrollToMargin"
TopOfScreen = "TopOfScreen"

type ToggleBool* = enum False, True, Toggle

converter toToggleBool*(b: bool): ToggleBool =
if b:
True
else:
False

func getBool*(b: ToggleBool): Option[bool] =
case b
of False: false.some
of True: true.some
of Toggle: bool.none

func applyTo*(b: ToggleBool, to: var bool) =
case b
of False: to = false
of True: to = true
of Toggle: to = not to

type Selections* = seq[Selection]

proc normalize*(self: var Selections) =
Expand Down

0 comments on commit b3954ed

Please sign in to comment.