From 0693bc02fb6935dba60a85759462c2c82472c3d8 Mon Sep 17 00:00:00 2001 From: Grimsace Date: Tue, 10 Feb 2026 08:49:31 -0600 Subject: [PATCH] changed layout --- calculations.go | 29 ++++++++++++++++++++++ main.go | 66 ++++++++++++++++++++++++------------------------- 2 files changed, 62 insertions(+), 33 deletions(-) diff --git a/calculations.go b/calculations.go index 799ee95..731b9ff 100644 --- a/calculations.go +++ b/calculations.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "math" "math/rand" "regexp" "sort" @@ -233,6 +234,34 @@ func (p *parser) parseTerm() (float64, error) { // parseFactor handles parentheses and unary operators (highest precedence) func (p *parser) parseFactor() (float64, error) { + left, err := p.parsePower() + if err != nil { + return 0, err + } + + for { + p.skipWhitespace() + if p.pos >= len(p.expr) { + break + } + + if p.expr[p.pos] == '^' { + p.pos++ + right, err := p.parseFactor() + if err != nil { + return 0, err + } + left = math.Pow(left, right) + } else { + break + } + } + + return left, nil +} + +// parsePower handles parentheses and unary operators +func (p *parser) parsePower() (float64, error) { p.skipWhitespace() if p.pos >= len(p.expr) { diff --git a/main.go b/main.go index 9a569fd..b7a6457 100644 --- a/main.go +++ b/main.go @@ -27,6 +27,12 @@ func main() { // Dice buttons for quick input diceButtonsContainer := container.NewGridWithColumns(5, + widget.NewButton("H", func() { + diceInputEntry.SetText(diceInputEntry.Text + "H") + }), + widget.NewButton("dX", func() { + diceInputEntry.SetText(diceInputEntry.Text + "dX") + }), widget.NewButton("d4", func() { diceInputEntry.SetText(diceInputEntry.Text + "d4") }), @@ -36,6 +42,9 @@ func main() { widget.NewButton("d8", func() { diceInputEntry.SetText(diceInputEntry.Text + "d8") }), + widget.NewButton("L", func() { + diceInputEntry.SetText(diceInputEntry.Text + "L") + }), widget.NewButton("d10", func() { diceInputEntry.SetText(diceInputEntry.Text + "d10") }), @@ -48,15 +57,6 @@ func main() { widget.NewButton("d100", func() { diceInputEntry.SetText(diceInputEntry.Text + "d100") }), - widget.NewButton("dx", func() { - diceInputEntry.SetText(diceInputEntry.Text + "dx") - }), - widget.NewButton("H", func() { - diceInputEntry.SetText(diceInputEntry.Text + "H") - }), - widget.NewButton("L", func() { - diceInputEntry.SetText(diceInputEntry.Text + "L") - }), ) // Roll button @@ -79,32 +79,29 @@ func main() { rollButton.Importance = widget.HighImportance // Calculator-style number buttons - numberButtonsContainer := container.NewGridWithColumns(4, - widget.NewButton("AC", func() { - diceInputEntry.SetText("") - outputDisplay.Text = "0" - outputDisplay.Refresh() - }), - widget.NewButton("()", func() { - // TODO: Implement parenthesis logic - }), - widget.NewButton("%", func() { - diceInputEntry.SetText(diceInputEntry.Text + "%") - }), - widget.NewButton("÷", func() { - diceInputEntry.SetText(diceInputEntry.Text + "/") - }), + numberButtonsContainer := container.NewGridWithColumns(5, createCalcButton("7", diceInputEntry), createCalcButton("8", diceInputEntry), createCalcButton("9", diceInputEntry), - widget.NewButton("x", func() { + widget.NewButton("*", func() { diceInputEntry.SetText(diceInputEntry.Text + "*") }), + widget.NewButton("⌫", func() { + text := diceInputEntry.Text + if len(text) > 0 { + diceInputEntry.SetText(text[:len(text)-1]) + } + }), createCalcButton("4", diceInputEntry), createCalcButton("5", diceInputEntry), createCalcButton("6", diceInputEntry), - widget.NewButton("-", func() { - diceInputEntry.SetText(diceInputEntry.Text + "-") + widget.NewButton("/", func() { + diceInputEntry.SetText(diceInputEntry.Text + "/") + }), + widget.NewButton("C", func() { + diceInputEntry.SetText("") + outputDisplay.Text = "0" + outputDisplay.Refresh() }), createCalcButton("1", diceInputEntry), createCalcButton("2", diceInputEntry), @@ -112,15 +109,18 @@ func main() { widget.NewButton("+", func() { diceInputEntry.SetText(diceInputEntry.Text + "+") }), - createCalcButton("0", diceInputEntry), + widget.NewButton("📊", func() { + // TODO: Implement statistics logic + }), widget.NewButton(".", func() { diceInputEntry.SetText(diceInputEntry.Text + ".") }), - widget.NewButton("⌫", func() { - text := diceInputEntry.Text - if len(text) > 0 { - diceInputEntry.SetText(text[:len(text)-1]) - } + createCalcButton("0", diceInputEntry), + widget.NewButton("^", func() { + diceInputEntry.SetText(diceInputEntry.Text + "^") + }), + widget.NewButton("-", func() { + diceInputEntry.SetText(diceInputEntry.Text + "-") }), rollButton, )