Last active
February 21, 2020 15:05
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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