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 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 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; } }
public void Calculator() { const string Numbers = "789456123"; const string Ops = "+-*/"; const nk_panel_flags F = nk_panel_flags.NK_WINDOW_BORDER | nk_panel_flags.NK_WINDOW_MOVABLE | nk_panel_flags.NK_WINDOW_NO_SCROLLBAR | nk_panel_flags.NK_WINDOW_TITLE | nk_panel_flags.NK_WINDOW_CLOSABLE | nk_panel_flags.NK_WINDOW_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); int Len = Buffer.Length; NuklearAPI.EditString(nk_edit_types.NK_EDIT_SIMPLE, Buffer, ref Len, (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; } }