changed layout
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user