void PaintTag(FMLTag Tag) { FMLAttributes Attrib = Tag.Attributes; switch (Tag.TagName) { case "root": { PaintTags(Tag.Children); break; } case "window": { NkPanelFlags Flags = NkPanelFlags.BorderTitle; if (Attrib.GetAttribute("minimizable", true)) { Flags |= NkPanelFlags.Minimizable; } if (Attrib.GetAttribute("movable", false)) { Flags |= NkPanelFlags.Movable; } if (Attrib.GetAttribute("resizable", false)) { Flags |= NkPanelFlags.Scalable; } float X = Attrib.GetAttribute("x", 0.0f); float Y = Attrib.GetAttribute("y", 0.0f); float W = Attrib.GetAttribute("width", 50.0f); float H = Attrib.GetAttribute("height", 50.0f); NuklearAPI.Window(Attrib.GetAttribute("title", "Window"), X, Y, W, H, Flags, () => { NuklearAPI.LayoutRowDynamic(35); PaintTags(Tag.Children); }); break; } case "button": { if (NuklearAPI.ButtonLabel(Attrib.GetAttribute("text", "Button"))) { } break; } default: throw new InvalidOperationException("Unknown tag name " + Tag.TagName); } }
public static bool Group(string Name, string Title, NkPanelFlags Flags, Action A) { bool Res = true; if (Nuklear.nk_group_begin_titled(Ctx, Name, Title, (uint)Flags) != 0) { A?.Invoke(); } else { Res = false; } Nuklear.nk_group_end(Ctx); return(Res); }
public static void NuklearDraw(int X, int Y) { const NkPanelFlags Flags = NkPanelFlags.BorderTitle | NkPanelFlags.MovableScalable | NkPanelFlags.ClosableMinimizable; const string ConWindowName = "GConsole"; if (Open) { NuklearAPI.Window(ConWindowName, X, Y, 600, 400, Flags, () => { NkRect Bounds = NuklearAPI.WindowGetBounds(); if (Bounds.H > 85) { NuklearAPI.LayoutRowDynamic(Bounds.H - 85); NuklearAPI.Group("Console_OutBufferGroup", 0, () => { NuklearAPI.LayoutRowDynamic(12); for (int i = 0; i < OutBuffer.Length; i++) { GConsoleEntry E = OutBuffer[i]; if (E.Msg != null) { NuklearAPI.LabelColored(E.Msg, E.Clr); } } }); } NuklearAPI.LayoutRowDynamic(); if (NuklearAPI.EditString(NkEditTypes.Field, InBuffer).HasFlag(NkEditEvents.Active) && NuklearAPI.IsKeyPressed(NkKeys.Enter)) { SendInput(InBuffer.ToString()); InBuffer.Clear(); } }); if (NuklearAPI.WindowIsHidden(ConWindowName)) { NuklearAPI.WindowClose(ConWindowName); Open = false; } } }
static void TestWindow(float X, float Y) { const NkPanelFlags Flags = NkPanelFlags.BorderTitle | NkPanelFlags.MovableScalable | NkPanelFlags.Minimizable | NkPanelFlags.ScrollAutoHide; NuklearAPI.Window("Test Window", X, Y, 200, 200, Flags, () => { NuklearAPI.LayoutRowDynamic(35); for (int i = 0; i < 5; i++) { if (NuklearAPI.ButtonLabel("Some Button " + i)) { Console.WriteLine("You pressed button " + i); } } if (NuklearAPI.ButtonLabel("Exit")) { Environment.Exit(0); } }); }
static void ConsoleThing(int X, int Y, StringBuilder OutBuffer, StringBuilder InBuffer) { const NkPanelFlags Flags = NkPanelFlags.BorderTitle | NkPanelFlags.MovableScalable | NkPanelFlags.Minimizable; NuklearAPI.Window("Console", X, Y, 300, 300, Flags, () => { NkRect Bounds = NuklearAPI.WindowGetBounds(); NuklearAPI.LayoutRowDynamic(Bounds.H - 85); NuklearAPI.EditString(NkEditTypes.Editor | (NkEditTypes)(NkEditFlags.GotoEndOnActivate), OutBuffer); NuklearAPI.LayoutRowDynamic(); if (NuklearAPI.EditString(NkEditTypes.Field, InBuffer).HasFlag(NkEditEvents.Active) && NuklearAPI.IsKeyPressed(NkKeys.Enter)) { string Txt = InBuffer.ToString().Trim(); InBuffer.Clear(); if (Txt.Length > 0) { OutBuffer.AppendLine(Txt); } } }); }
public static bool Group(string Name, NkPanelFlags Flags, Action A) => Group(Name, Name, Flags, A);
public static bool Window(string Title, float X, float Y, float W, float H, NkPanelFlags Flags, Action A) => Window(Title, Title, X, Y, W, H, Flags, A);
public static bool Window(string Name, string Title, float X, float Y, float W, float H, NkPanelFlags Flags, Action A) { bool Res = true; if (Nuklear.nk_begin_titled(Ctx, Name, Title, new NkRect(X, Y, W, H), (uint)Flags) != 0) { A?.Invoke(); } else { Res = false; } Nuklear.nk_end(Ctx); return(Res); }
public void Calculator() { const string Numbers = "789456123"; const string Ops = "+-*/"; const NkPanelFlags F = NkPanelFlags.Border | NkPanelFlags.Movable | NkPanelFlags.NoScrollbar | NkPanelFlags.Title | NkPanelFlags.Closable | NkPanelFlags.Minimizable; bool Solve = false; string BufferStr; NuklearAPI.Window(Name, X, Y, 180, 250, F, () => { NuklearAPI.LayoutRowDynamic(35, 1); Buffer.Clear(); Buffer.AppendFormat("{0:0.00}", Current); NuklearAPI.EditString(NkEditTypes.Simple, Buffer, (ref nk_text_edit TextBox, uint Rune) => { char C = (char)Rune; if (char.IsNumber(C)) { return(1); } return(0); }); BufferStr = Buffer.ToString().Trim(); if (BufferStr.Length > 0) { if (float.TryParse(BufferStr, out float CurFloat)) { Current = CurFloat; } } NuklearAPI.LayoutRowDynamic(35, 4); for (int i = 0; i < 16; i++) { if (i == 12) { if (NuklearAPI.ButtonLabel("C")) { A = B = 0; Op = ' '; Set = false; CurrentThingy = CurrentThing.A; } if (NuklearAPI.ButtonLabel("0")) { Current = Current * 10; Op = ' '; } if (NuklearAPI.ButtonLabel("=")) { Solve = true; Prev = Op; Op = ' '; } } else if (((i + 1) % 4) != 0) { int NumIdx = (i / 4) * 3 + i % 4; if (NumIdx < Numbers.Length && NuklearAPI.ButtonText(Numbers[NumIdx])) { Current = Current * 10 + int.Parse(Numbers[NumIdx].ToString()); Set = false; } } else if (NuklearAPI.ButtonText(Ops[i / 4])) { if (!Set) { if (CurrentThingy != CurrentThing.B) { CurrentThingy = CurrentThing.B; } else { Prev = Op; Solve = true; } } Op = Ops[i / 4]; Set = true; } } if (Solve) { if (Prev == '+') { A = A + B; } else if (Prev == '-') { A = A - B; } else if (Prev == '*') { A = A * B; } else if (Prev == '/') { A = A / B; } CurrentThingy = CurrentThing.A; if (Set) { CurrentThingy = CurrentThing.B; } B = 0; Set = false; } }); if (NuklearAPI.WindowIsClosed(Name) || NuklearAPI.WindowIsHidden(Name)) { Open = false; } }