changed layout

This commit is contained in:
Grimsace
2026-02-10 08:49:31 -06:00
parent 547638f38d
commit 0693bc02fb
2 changed files with 62 additions and 33 deletions
+29
View File
@@ -2,6 +2,7 @@ package main
import ( import (
"fmt" "fmt"
"math"
"math/rand" "math/rand"
"regexp" "regexp"
"sort" "sort"
@@ -233,6 +234,34 @@ func (p *parser) parseTerm() (float64, error) {
// parseFactor handles parentheses and unary operators (highest precedence) // parseFactor handles parentheses and unary operators (highest precedence)
func (p *parser) parseFactor() (float64, error) { 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() p.skipWhitespace()
if p.pos >= len(p.expr) { if p.pos >= len(p.expr) {
+33 -33
View File
@@ -27,6 +27,12 @@ func main() {
// Dice buttons for quick input // Dice buttons for quick input
diceButtonsContainer := container.NewGridWithColumns(5, 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() { widget.NewButton("d4", func() {
diceInputEntry.SetText(diceInputEntry.Text + "d4") diceInputEntry.SetText(diceInputEntry.Text + "d4")
}), }),
@@ -36,6 +42,9 @@ func main() {
widget.NewButton("d8", func() { widget.NewButton("d8", func() {
diceInputEntry.SetText(diceInputEntry.Text + "d8") diceInputEntry.SetText(diceInputEntry.Text + "d8")
}), }),
widget.NewButton("L", func() {
diceInputEntry.SetText(diceInputEntry.Text + "L")
}),
widget.NewButton("d10", func() { widget.NewButton("d10", func() {
diceInputEntry.SetText(diceInputEntry.Text + "d10") diceInputEntry.SetText(diceInputEntry.Text + "d10")
}), }),
@@ -48,15 +57,6 @@ func main() {
widget.NewButton("d100", func() { widget.NewButton("d100", func() {
diceInputEntry.SetText(diceInputEntry.Text + "d100") 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 // Roll button
@@ -79,32 +79,29 @@ func main() {
rollButton.Importance = widget.HighImportance rollButton.Importance = widget.HighImportance
// Calculator-style number buttons // Calculator-style number buttons
numberButtonsContainer := container.NewGridWithColumns(4, numberButtonsContainer := container.NewGridWithColumns(5,
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 + "/")
}),
createCalcButton("7", diceInputEntry), createCalcButton("7", diceInputEntry),
createCalcButton("8", diceInputEntry), createCalcButton("8", diceInputEntry),
createCalcButton("9", diceInputEntry), createCalcButton("9", diceInputEntry),
widget.NewButton("x", func() { widget.NewButton("*", func() {
diceInputEntry.SetText(diceInputEntry.Text + "*") diceInputEntry.SetText(diceInputEntry.Text + "*")
}), }),
widget.NewButton("⌫", func() {
text := diceInputEntry.Text
if len(text) > 0 {
diceInputEntry.SetText(text[:len(text)-1])
}
}),
createCalcButton("4", diceInputEntry), createCalcButton("4", diceInputEntry),
createCalcButton("5", diceInputEntry), createCalcButton("5", diceInputEntry),
createCalcButton("6", diceInputEntry), createCalcButton("6", diceInputEntry),
widget.NewButton("-", func() { widget.NewButton("/", func() {
diceInputEntry.SetText(diceInputEntry.Text + "-") diceInputEntry.SetText(diceInputEntry.Text + "/")
}),
widget.NewButton("C", func() {
diceInputEntry.SetText("")
outputDisplay.Text = "0"
outputDisplay.Refresh()
}), }),
createCalcButton("1", diceInputEntry), createCalcButton("1", diceInputEntry),
createCalcButton("2", diceInputEntry), createCalcButton("2", diceInputEntry),
@@ -112,15 +109,18 @@ func main() {
widget.NewButton("+", func() { widget.NewButton("+", func() {
diceInputEntry.SetText(diceInputEntry.Text + "+") diceInputEntry.SetText(diceInputEntry.Text + "+")
}), }),
createCalcButton("0", diceInputEntry), widget.NewButton("📊", func() {
// TODO: Implement statistics logic
}),
widget.NewButton(".", func() { widget.NewButton(".", func() {
diceInputEntry.SetText(diceInputEntry.Text + ".") diceInputEntry.SetText(diceInputEntry.Text + ".")
}), }),
widget.NewButton("", func() { createCalcButton("0", diceInputEntry),
text := diceInputEntry.Text widget.NewButton("^", func() {
if len(text) > 0 { diceInputEntry.SetText(diceInputEntry.Text + "^")
diceInputEntry.SetText(text[:len(text)-1]) }),
} widget.NewButton("-", func() {
diceInputEntry.SetText(diceInputEntry.Text + "-")
}), }),
rollButton, rollButton,
) )