Skip to content

Commit ca0140f

Browse files
committed
implement <Foo>ToString() for better NodePrint()
1 parent 251d251 commit ca0140f

File tree

2 files changed

+211
-42
lines changed

2 files changed

+211
-42
lines changed

enums.go

+201-32
Original file line numberDiff line numberDiff line change
@@ -221,65 +221,234 @@ const (
221221
WrapWrapReverse
222222
)
223223

224-
func YGWrapToString(value Wrap) string {
225-
return ""
224+
// AlignToString returns string version of Align enum
225+
func AlignToString(value Align) string {
226+
switch value {
227+
case AlignAuto:
228+
return "auto"
229+
case AlignFlexStart:
230+
return "flex-start"
231+
case AlignCenter:
232+
return "center"
233+
case AlignFlexEnd:
234+
return "flex-end"
235+
case AlignStretch:
236+
return "stretch"
237+
case AlignBaseline:
238+
return "baseline"
239+
case AlignSpaceBetween:
240+
return "space-between"
241+
case AlignSpaceAround:
242+
return "space-around"
243+
}
244+
return "unknown"
226245
}
227246

228-
func YGAlignToString(value Align) string {
229-
return ""
247+
// DimensionToString returns string version of Dimension enum
248+
func DimensionToString(value Dimension) string {
249+
switch value {
250+
case DimensionWidth:
251+
return "width"
252+
case DimensionHeight:
253+
return "height"
254+
}
255+
return "unknown"
230256
}
231257

232-
func YGDimensionToString(value Dimension) string {
233-
return ""
258+
// DirectionToString returns string version of Direction enum
259+
func DirectionToString(value Direction) string {
260+
switch value {
261+
case DirectionInherit:
262+
return "inherit"
263+
case DirectionLTR:
264+
return "ltr"
265+
case DirectionRTL:
266+
return "rtl"
267+
}
268+
return "unknown"
234269
}
235270

236-
func YGDirectionToString(value Direction) string {
237-
return ""
271+
// DisplayToString returns string version of Display enum
272+
func DisplayToString(value Display) string {
273+
switch value {
274+
case DisplayFlex:
275+
return "flex"
276+
case DisplayNone:
277+
return "none"
278+
}
279+
return "unknown"
238280
}
239281

240-
func YGDisplayToString(value Display) string {
241-
return ""
282+
// EdgeToString returns string version of Edge enum
283+
func EdgeToString(value Edge) string {
284+
switch value {
285+
case EdgeLeft:
286+
return "left"
287+
case EdgeTop:
288+
return "top"
289+
case EdgeRight:
290+
return "right"
291+
case EdgeBottom:
292+
return "bottom"
293+
case EdgeStart:
294+
return "start"
295+
case EdgeEnd:
296+
return "end"
297+
case EdgeHorizontal:
298+
return "horizontal"
299+
case EdgeVertical:
300+
return "vertical"
301+
case EdgeAll:
302+
return "all"
303+
}
304+
return "unknown"
242305
}
243306

244-
func YGEdgeToString(value Edge) string {
245-
return ""
307+
// ExperimentalFeatureToString returns string version of ExperimentalFeature enum
308+
func ExperimentalFeatureToString(value ExperimentalFeature) string {
309+
switch value {
310+
case ExperimentalFeatureWebFlexBasis:
311+
return "web-flex-basis"
312+
}
313+
return "unknown"
246314
}
247-
func YGExperimentalFeatureToString(value ExperimentalFeature) string {
248-
return ""
315+
316+
// FlexDirectionToString returns string version of FlexDirection enum
317+
func FlexDirectionToString(value FlexDirection) string {
318+
switch value {
319+
case FlexDirectionColumn:
320+
return "column"
321+
case FlexDirectionColumnReverse:
322+
return "column-reverse"
323+
case FlexDirectionRow:
324+
return "row"
325+
case FlexDirectionRowReverse:
326+
return "row-reverse"
327+
}
328+
return "unknown"
249329
}
250330

251-
func YGFlexDirectionToString(value FlexDirection) string {
252-
return ""
331+
// JustifyToString returns string version of Justify enum
332+
func JustifyToString(value Justify) string {
333+
switch value {
334+
case JustifyFlexStart:
335+
return "flex-start"
336+
case JustifyCenter:
337+
return "center"
338+
case JustifyFlexEnd:
339+
return "flex-end"
340+
case JustifySpaceBetween:
341+
return "space-between"
342+
case JustifySpaceAround:
343+
return "space-around"
344+
}
345+
return "unknown"
253346
}
254347

255-
func YGJustifyToString(value Justify) string {
256-
return ""
348+
// LogLevelToString returns string version of LogLevel enum
349+
func LogLevelToString(value LogLevel) string {
350+
switch value {
351+
case LogLevelError:
352+
return "error"
353+
case LogLevelWarn:
354+
return "warn"
355+
case LogLevelInfo:
356+
return "info"
357+
case LogLevelDebug:
358+
return "debug"
359+
case LogLevelVerbose:
360+
return "verbose"
361+
case LogLevelFatal:
362+
return "fatal"
363+
}
364+
return "unknown"
257365
}
258366

259-
func YGLogLevelToString(value LogLevel) string {
260-
return ""
367+
// MeasureModeToString returns string version of MeasureMode enum
368+
func MeasureModeToString(value MeasureMode) string {
369+
switch value {
370+
case MeasureModeUndefined:
371+
return "undefined"
372+
case MeasureModeExactly:
373+
return "exactly"
374+
case MeasureModeAtMost:
375+
return "at-most"
376+
}
377+
return "unknown"
261378
}
262379

263-
func YGMeasureModeToString(value MeasureMode) string {
264-
return ""
380+
// NodeTypeToString returns string version of NodeType enum
381+
func NodeTypeToString(value NodeType) string {
382+
switch value {
383+
case NodeTypeDefault:
384+
return "default"
385+
case NodeTypeText:
386+
return "text"
387+
}
388+
return "unknown"
265389
}
266390

267-
func YGNodeTypeToString(value NodeType) string {
268-
return ""
391+
// OverflowToString returns string version of Overflow enum
392+
func OverflowToString(value Overflow) string {
393+
switch value {
394+
case OverflowVisible:
395+
return "visible"
396+
case OverflowHidden:
397+
return "hidden"
398+
case OverflowScroll:
399+
return "scroll"
400+
}
401+
return "unknown"
269402
}
270403

271-
func YGOverflowToString(value Overflow) string {
272-
return ""
404+
// PositionTypeToString returns string version of PositionType enum
405+
func PositionTypeToString(value PositionType) string {
406+
switch value {
407+
case PositionTypeRelative:
408+
return "relative"
409+
case PositionTypeAbsolute:
410+
return "absolute"
411+
}
412+
return "unknown"
273413
}
274414

275-
func YGPositionTypeToString(value PositionType) string {
276-
return ""
415+
// PrintOptionsToString returns string version of PrintOptions enum
416+
func PrintOptionsToString(value PrintOptions) string {
417+
switch value {
418+
case PrintOptionsLayout:
419+
return "layout"
420+
case PrintOptionsStyle:
421+
return "style"
422+
case PrintOptionsChildren:
423+
return "children"
424+
}
425+
return "unknown"
277426
}
278427

279-
func YGPrintOptionsToString(value PrintOptions) string {
280-
return ""
428+
// UnitToString returns string version of Unit enum
429+
func UnitToString(value Unit) string {
430+
switch value {
431+
case UnitUndefined:
432+
return "undefined"
433+
case UnitPoint:
434+
return "point"
435+
case UnitPercent:
436+
return "percent"
437+
case UnitAuto:
438+
return "auto"
439+
}
440+
return "unknown"
281441
}
282442

283-
func YGUnitToString(value Unit) string {
284-
return ""
443+
// WrapToString returns string version of Wrap enum
444+
func WrapToString(value Wrap) string {
445+
switch value {
446+
case WrapNoWrap:
447+
return "no-wrap"
448+
case WrapWrap:
449+
return "wrap"
450+
case WrapWrapReverse:
451+
return "wrap-reverse"
452+
}
453+
return "unknown"
285454
}

print.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func printEdges(node *Node, str string, edges []Value) {
5454
printNumberIfNotZero(node, str, &edges[EdgeLeft])
5555
} else {
5656
for edge := EdgeLeft; edge < EdgeCount; edge++ {
57-
buf := fmt.Sprintf("%s-%s", str, YGEdgeToString(edge))
57+
buf := fmt.Sprintf("%s-%s", str, EdgeToString(edge))
5858
printNumberIfNotZero(node, buf, &edges[edge])
5959
}
6060
}
@@ -83,22 +83,22 @@ func nodePrintInternal(node *Node, options PrintOptions, level int) {
8383
log(node,
8484
LogLevelDebug,
8585
"flex-direction: %s; ",
86-
YGFlexDirectionToString(node.Style.FlexDirection))
86+
FlexDirectionToString(node.Style.FlexDirection))
8787
}
8888
if node.Style.JustifyContent != nodeDefaults.Style.JustifyContent {
8989
log(node,
9090
LogLevelDebug,
9191
"justify-content: %s; ",
92-
YGJustifyToString(node.Style.JustifyContent))
92+
JustifyToString(node.Style.JustifyContent))
9393
}
9494
if node.Style.AlignItems != nodeDefaults.Style.AlignItems {
95-
log(node, LogLevelDebug, "align-items: %s; ", YGAlignToString(node.Style.AlignItems))
95+
log(node, LogLevelDebug, "align-items: %s; ", AlignToString(node.Style.AlignItems))
9696
}
9797
if node.Style.AlignContent != nodeDefaults.Style.AlignContent {
98-
log(node, LogLevelDebug, "align-content: %s; ", YGAlignToString(node.Style.AlignContent))
98+
log(node, LogLevelDebug, "align-content: %s; ", AlignToString(node.Style.AlignContent))
9999
}
100100
if node.Style.AlignSelf != nodeDefaults.Style.AlignSelf {
101-
log(node, LogLevelDebug, "align-self: %s; ", YGAlignToString(node.Style.AlignSelf))
101+
log(node, LogLevelDebug, "align-self: %s; ", AlignToString(node.Style.AlignSelf))
102102
}
103103

104104
printNumberIfNotUndefinedf(node, "flex-grow", node.Style.FlexGrow)
@@ -107,15 +107,15 @@ func nodePrintInternal(node *Node, options PrintOptions, level int) {
107107
printNumberIfNotUndefinedf(node, "flex", node.Style.Flex)
108108

109109
if node.Style.FlexWrap != nodeDefaults.Style.FlexWrap {
110-
log(node, LogLevelDebug, "flexWrap: %s; ", YGWrapToString(node.Style.FlexWrap))
110+
log(node, LogLevelDebug, "flexWrap: %s; ", WrapToString(node.Style.FlexWrap))
111111
}
112112

113113
if node.Style.Overflow != nodeDefaults.Style.Overflow {
114-
log(node, LogLevelDebug, "overflow: %s; ", YGOverflowToString(node.Style.Overflow))
114+
log(node, LogLevelDebug, "overflow: %s; ", OverflowToString(node.Style.Overflow))
115115
}
116116

117117
if node.Style.Display != nodeDefaults.Style.Display {
118-
log(node, LogLevelDebug, "display: %s; ", YGDisplayToString(node.Style.Display))
118+
log(node, LogLevelDebug, "display: %s; ", DisplayToString(node.Style.Display))
119119
}
120120

121121
printEdges(node, "margin", node.Style.Margin[:])
@@ -133,7 +133,7 @@ func nodePrintInternal(node *Node, options PrintOptions, level int) {
133133
log(node,
134134
LogLevelDebug,
135135
"position: %s; ",
136-
YGPositionTypeToString(node.Style.PositionType))
136+
PositionTypeToString(node.Style.PositionType))
137137
}
138138

139139
printEdgeIfNotUndefined(node, "left", node.Style.Position[:], EdgeLeft)

0 commit comments

Comments
 (0)