Make use of new stone fixes
This commit is contained in:
parent
3c2cf76df2
commit
fec0f3372e
2
go.mod
2
go.mod
@ -2,7 +2,7 @@ module git.tebibyte.media/sashakoshka/mathpan
|
||||
|
||||
go 1.19
|
||||
|
||||
require git.tebibyte.media/sashakoshka/stone v0.0.0-20221119230047-9a37fbf04a0d
|
||||
require git.tebibyte.media/sashakoshka/stone v0.0.0-20221122052135-ae514f5ae2db
|
||||
|
||||
require (
|
||||
github.com/BurntSushi/freetype-go v0.0.0-20160129220410-b763ddbfe298 // indirect
|
||||
|
4
go.sum
4
go.sum
@ -1,5 +1,5 @@
|
||||
git.tebibyte.media/sashakoshka/stone v0.0.0-20221119230047-9a37fbf04a0d h1:JLX1/Pvt+oWohUn6wlZgOdO+uf6ps410ynRowLvErao=
|
||||
git.tebibyte.media/sashakoshka/stone v0.0.0-20221119230047-9a37fbf04a0d/go.mod h1:ISnqmX6xvItOot3eW3YWLcNFeJrGpKetQGQniAjnU2A=
|
||||
git.tebibyte.media/sashakoshka/stone v0.0.0-20221122052135-ae514f5ae2db h1:2llsOVwxK5oK4E/RX21tzafQBc6N+H6MwRSQykCb6ss=
|
||||
git.tebibyte.media/sashakoshka/stone v0.0.0-20221122052135-ae514f5ae2db/go.mod h1:ISnqmX6xvItOot3eW3YWLcNFeJrGpKetQGQniAjnU2A=
|
||||
github.com/BurntSushi/freetype-go v0.0.0-20160129220410-b763ddbfe298 h1:1qlsVAQJXZHsaM8b6OLVo6muQUQd4CwkH/D3fnnbHXA=
|
||||
github.com/BurntSushi/freetype-go v0.0.0-20160129220410-b763ddbfe298/go.mod h1:D+QujdIlUNfa0igpNMk6UIvlb6C252URs4yupRUV4lQ=
|
||||
github.com/BurntSushi/graphics-go v0.0.0-20160129215708-b43f31a4a966 h1:lTG4HQym5oPKjL7nGs+csTgiDna685ZXjxijkne828g=
|
||||
|
38
main.go
38
main.go
@ -16,10 +16,6 @@ var expressionRoot Expression
|
||||
var inputBuffer stone.DamageBuffer
|
||||
var showLeftColumn bool
|
||||
|
||||
var inputState struct {
|
||||
alt bool
|
||||
}
|
||||
|
||||
func main () {
|
||||
application.SetTitle("MathPan")
|
||||
application.SetSize(64, 10)
|
||||
@ -31,13 +27,12 @@ func main () {
|
||||
application.OnStart(onStart)
|
||||
application.OnResize(redraw)
|
||||
application.OnPress(onPress)
|
||||
application.OnRelease(onRelease)
|
||||
|
||||
err = application.Run()
|
||||
if err != nil { panic(err) }
|
||||
}
|
||||
|
||||
func onPress (button stone.Button) {
|
||||
func onPress (button stone.Button, modifiers stone.Modifiers) {
|
||||
switch button {
|
||||
case stone.KeyUp:
|
||||
if selectedExpression == nil { break }
|
||||
@ -72,11 +67,8 @@ func onPress (button stone.Button) {
|
||||
redraw()
|
||||
application.Draw()
|
||||
|
||||
case stone.KeyLeftAlt, stone.KeyRightAlt:
|
||||
inputState.alt = true
|
||||
|
||||
case '[':
|
||||
insertGeneric(&Operation { })
|
||||
insertGeneric(&Operation { }, modifiers.Alt)
|
||||
redraw()
|
||||
application.Draw()
|
||||
|
||||
@ -84,7 +76,7 @@ func onPress (button stone.Button) {
|
||||
'+', '-', '*', '/', 'p', 'r', '%', '|', '~', '&', '^', 'm',
|
||||
'<', '>':
|
||||
|
||||
insertOperation(rune(button))
|
||||
insertOperation(rune(button), modifiers.Alt)
|
||||
redraw()
|
||||
application.Draw()
|
||||
|
||||
@ -142,7 +134,9 @@ func onPress (button stone.Button) {
|
||||
application.Draw()
|
||||
|
||||
case ' ':
|
||||
insertGeneric(&IntegerLiteral { displayRadix: 10 })
|
||||
insertGeneric (
|
||||
&IntegerLiteral { displayRadix: 10 },
|
||||
modifiers.Alt)
|
||||
redraw()
|
||||
application.Draw()
|
||||
|
||||
@ -163,7 +157,7 @@ func onPress (button stone.Button) {
|
||||
insertGeneric (&IntegerLiteral {
|
||||
displayRadix: 10,
|
||||
value: int64(value),
|
||||
})
|
||||
}, modifiers.Alt)
|
||||
|
||||
case *IntegerLiteral:
|
||||
integer := selectedExpression.(*IntegerLiteral)
|
||||
@ -214,15 +208,7 @@ func onPress (button stone.Button) {
|
||||
}
|
||||
}
|
||||
|
||||
func onRelease (button stone.Button) {
|
||||
switch button {
|
||||
case stone.KeyLeftAlt, stone.KeyRightAlt:
|
||||
inputState.alt = false
|
||||
println("alt up")
|
||||
}
|
||||
}
|
||||
|
||||
func insertOperation (symbol rune) {
|
||||
func insertOperation (symbol rune, swap bool) {
|
||||
var opcode Opcode
|
||||
switch (symbol) {
|
||||
case '+': opcode = OpcodeAdd
|
||||
@ -243,17 +229,17 @@ func insertOperation (symbol rune) {
|
||||
|
||||
operation, isOperation := selectedExpression.(*Operation)
|
||||
if isOperation {
|
||||
if operation.opcode == OpcodeUnknown || inputState.alt {
|
||||
if operation.opcode == OpcodeUnknown || swap {
|
||||
operation.opcode = opcode
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
newExpression := &Operation { opcode: opcode }
|
||||
insertGeneric(newExpression)
|
||||
insertGeneric(newExpression, swap)
|
||||
}
|
||||
|
||||
func insertGeneric (expression Expression) {
|
||||
func insertGeneric (expression Expression, swap bool) {
|
||||
defer func () {
|
||||
selectedExpression = expression
|
||||
} ()
|
||||
@ -267,7 +253,7 @@ func insertGeneric (expression Expression) {
|
||||
|
||||
parent := selectedExpression.Parent()
|
||||
|
||||
if inputState.alt {
|
||||
if swap {
|
||||
// if alt is held, swap the selected expression for the new one
|
||||
if parent == nil {
|
||||
expressionRoot = expression
|
||||
|
Loading…
Reference in New Issue
Block a user