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; } }