feat: Working on node builder

This commit is contained in:
2024-12-01 11:45:05 -05:00
parent 55d8888961
commit ff49b12198
20 changed files with 495 additions and 227 deletions

View File

@@ -0,0 +1,48 @@
import Rainbow
public extension NodeRepresentable {
@inlinable
func labelStyle(_ style: any NodeModifier) -> any NodeRepresentable {
return modifier(LabelStyleModifier(style))
}
@inlinable
func labelStyle(_ color: NamedColor) -> any NodeRepresentable {
return modifier(LabelStyleModifier(.color(color)))
}
@inlinable
func labelStyle(_ style: Style) -> any NodeRepresentable {
return modifier(LabelStyleModifier(.style(style)))
}
@inlinable
func labelStyle(_ styles: Style...) -> any NodeRepresentable {
return modifier(LabelStyleModifier(.style(styles)))
}
}
@usableFromInline
struct LabelStyleModifier: NodeModifier {
@usableFromInline
let modifier: any NodeModifier
@usableFromInline
init(_ modifier: any NodeModifier) {
self.modifier = modifier
}
@usableFromInline
func render(_ node: any NodeRepresentable) -> any NodeRepresentable {
if let node = node as? LabeledContent {
return LabeledContent(separator: node.separator) {
node.label.modifier(modifier)
} content: {
node.content
}
}
return node
}
}