I encountered this while trying to understand the internals of fidgetty. Please note that I'm a newbie when it comes to understanding macros and AST processing.
Apologies for the long post - I am trying to give full context for my question.
First the context.
A couple of types from the cssgrid package are used by fidgetty: GridDir and Constraint.
In gridtypes.nim:
type
GridDir* = enum
dcol
drow
and in constraints.nim (the definition of Constraint is what matters):
ConstraintSizes* = enum
UiFrac
UiPerc
UiFixed
ConstraintSize* = object
case kind*: ConstraintSizes
of UiFrac:
frac*: UiScalar
of UiPerc:
perc*: UiScalar
of UiFixed:
coord*: UiScalar
Constraints* = enum
UiNone
UiValue
UiAuto
UiMin
UiMax
UiSum
UiMinMax
UiEnd
Constraint* = object
case kind*: Constraints
of UiNone:
discard
of UiValue:
value*: ConstraintSize
of UiAuto:
discard
of UiMin:
lmin, rmin*: ConstraintSize
of UiMax:
lmax, rmax*: ConstraintSize
of UiSum:
lsum, rsum*: ConstraintSize
of UiMinMax:
lmm, rmm*: ConstraintSize
of UiEnd:
discard
In fidgetty, fidget_dev/common.nim defines a CounterAxisSizingMode enum and a Node class:
CounterAxisSizingMode* = enum
csAuto
csFixed
# ...
Node* = ref object
# ...
cxSize*: array[GridDir, Constraint]
# ...
Note the enumeration symbol csAuto above.
Finally, the matter at hand.
In a number of places of fidgetty I see code like the last line in the following excerpt (from fidgetty/fidget_dev.nim). Note that current is a global Node object:
template node(kind: NodeKind, id: static string, inner, setup: untyped): untyped =
## Base template for node, frame, rectangle...
preNode(kind, atom(id))
setup
inner
postNode()
# ...
template frame*(id: static string, inner: untyped): untyped =
## Starts a new frame.
node(nkFrame, id, inner):
# boxSizeOf parent
current.cxSize = [csAuto(), csAuto()]
My question is about that last line. In the fidgetty code:
In the Nim Manual:
So it is a mystery to me what the expression csAuto() means.
Could someone please enlighten me?
The hazards of assumptions! :P
When I saw csAuto defined as an enum value in fidgetty, I didn't think to look outside of fidgetty for other definitions of the same name.
Thank you!