Press tab to view the end result in the readout instead!

This commit is contained in:
Sasha Koshka 2022-11-22 00:47:33 -05:00
parent fec0f3372e
commit a47445f494
2 changed files with 33 additions and 3 deletions

24
draw.go
View File

@ -11,6 +11,13 @@ func clear (x, y, width, height int) {
}} }}
} }
func fillColor (x, y, width, height int, color stone.Color) {
for yy := 0; yy < height; yy ++ {
for xx := 0; xx < width; xx ++ {
application.SetColor(xx + x, yy + y, color)
}}
}
func redraw () { func redraw () {
width, _ := application.Size() width, _ := application.Size()
showLeftColumn = width > 44 showLeftColumn = width > 44
@ -61,13 +68,30 @@ func drawInput () {
func drawNumberReadouts () { func drawNumberReadouts () {
_, height := application.Size() _, height := application.Size()
indicatorY := height - 12
application.SetDot(0, indicatorY)
fmt.Fprint(application, "sel fin")
fillColor(0, indicatorY, 10, 1, stone.ColorDim)
if showEndResult {
fillColor(4, indicatorY, 3, 1, stone.ColorBlue)
} else {
fillColor(0, indicatorY, 3, 1, stone.ColorBlue)
}
clear(0, height - 10, 25, 10) clear(0, height - 10, 25, 10)
var number int64 var number int64
var err error var err error
if showEndResult {
if expressionRoot != nil {
number, err = expressionRoot.Solution()
}
} else {
if selectedExpression != nil { if selectedExpression != nil {
number, err = selectedExpression.Solution() number, err = selectedExpression.Solution()
} }
}
if err != nil { if err != nil {
application.SetDot((25 - len(err.Error())) / 2, height - 6) application.SetDot((25 - len(err.Error())) / 2, height - 6)

View File

@ -15,10 +15,11 @@ var application = &stone.Application { }
var expressionRoot Expression var expressionRoot Expression
var inputBuffer stone.DamageBuffer var inputBuffer stone.DamageBuffer
var showLeftColumn bool var showLeftColumn bool
var showEndResult bool
func main () { func main () {
application.SetTitle("MathPan") application.SetTitle("MathPan")
application.SetSize(64, 10) application.SetSize(64, 12)
icon, _, err := image.Decode(bytes.NewReader(iconBytes)) icon, _, err := image.Decode(bytes.NewReader(iconBytes))
if err != nil { panic(err) } if err != nil { panic(err) }
@ -80,6 +81,11 @@ func onPress (button stone.Button, modifiers stone.Modifiers) {
redraw() redraw()
application.Draw() application.Draw()
case stone.KeyTab:
showEndResult = !showEndResult
redraw()
application.Draw()
case stone.KeyDelete: case stone.KeyDelete:
if selectedExpression == nil { break } if selectedExpression == nil { break }
parent := selectedExpression.Parent() parent := selectedExpression.Parent()