package app// Condition represents a control structure for conditionally displaying UI// elements. It extends the UI interface to include methods for handling// conditional logic.typeConditioninterface {UI// ElseIf sets a UI element to be displayed when the given boolean // expression is true and all previous conditions have been false. // // expr: Boolean expression to evaluate. // elem: Function that returns the UI element to display.ElseIf(expr bool, elem func() UI) Condition// ElseIfSlice sets multiple UI elements to be displayed when the given // boolean expression is true and all previous conditions have been false. // // expr: Boolean expression to evaluate. // elems: Function that returns a slice of UI elements to display.ElseIfSlice(expr bool, elems func() []UI) Condition// Else sets a UI element to be displayed as a fallback when all previous // conditions have been false. // // elem: Function that returns the UI element to display.Else(elem func() UI) Condition// ElseSlice sets multiple UI elements to be displayed as a fallback when // all previous conditions have been false. // // expr: Boolean expression to evaluate. // elems: Function that returns a slice of UI elements to display.ElseSlice(elems func() []UI) Condition body() []UI}// If returns a Condition that will display the given UI element based on the// evaluation of the provided boolean expression.func ( bool, func() UI) Condition {returnIfSlice(, func() []UI {return []UI{()} })}// IfSlice returns a Condition that will display the given slice of UI elements// based on the evaluation of the provided boolean expression.func ( bool, func() []UI) Condition {if ! {returncondition{} }returncondition{children: FilterUIElems(()...),matched: true, }}type condition struct { children []UI matched bool}func ( condition) ( bool, func() UI) Condition {return .ElseIfSlice(, func() []UI {return []UI{()} })}func ( condition) ( bool, func() []UI) Condition {if .matched || ! {return } .children = FilterUIElems(()...) .matched = truereturn}func ( condition) ( func() UI) Condition {return .ElseSlice(func() []UI {return []UI{()} })}func ( condition) ( func() []UI) Condition {return .ElseIfSlice(true, )}func ( condition) () Value {returnnil}func ( condition) () bool {returnfalse}func ( condition) () []UI {return .children}func ( condition) () UI {returnnil}func ( condition) (UI) UI {returnnil}
The pages are generated with Goldsv0.8.7. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.