Skip to content

Instantly share code, notes, and snippets.

@ndugger
Last active February 21, 2020 15:05
Show Gist options
  • Save ndugger/4d39251e8f4a1074bed34e1c0d9a5fe2 to your computer and use it in GitHub Desktop.
Save ndugger/4d39251e8f4a1074bed34e1c0d9a5fe2 to your computer and use it in GitHub Desktop.
If I were to design a UI library in C# for the Unity engine... just a code sketch
public static class BackButton {
public static Component = new ComponentDelegate(BackButton.Render);
public struct Props {
public String Label;
public Integer Padding;
}
public static Render(BackButton.Props props) {
var handleClick = UseClickHandler();
return new[] {
Render(Button.Component, new Button.Props { OnClick = handleClick, ID = "MyButton" }, new[] {
Render(Icon.Component, new Icon.Props { Glyph = "BackArrow" }),
Render(Spacer.Component, new Spacer.Props { Size = props.Padding }),
Render(Text.Component, null, new[] {
props.Label
})
})
}
}
}
//////////////////////////////////////////////////////////////////////////////
public static class Root {
public struct Props {}
public static Component = new Delegate(Root.Render);
public static Render(Root.Props props) {
return new[] {
Render(BackButton.Component, new BackButton.Props { Label = "Backwards", Padding = 16 })
}
}
}
//////////////////////////////////////////////////////////////////////////////
Render(Root.Element)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment