Compare commits

...

2 Commits

Author SHA1 Message Date
Sasha Koshka afe0ed33ca Swap precision of individual operations 2022-11-23 21:42:55 -05:00
Sasha Koshka 2f2c381d71 Added "encompass" key 2022-11-23 21:33:37 -05:00
1 changed files with 36 additions and 5 deletions

41
main.go
View File

@ -83,12 +83,17 @@ func onPress (button stone.Button, modifiers stone.Modifiers) {
}, modifiers.Alt, false, false)
redraw()
application.Draw()
case '\\':
insertOperation('?', false, true)
redraw()
application.Draw()
case
'+', '-', '*', '/', 'p', 'P', '%', '|', '~', '&', '^', 'm',
'l', 'r':
insertOperation(rune(button), modifiers.Alt)
insertOperation(rune(button), modifiers.Alt, false)
redraw()
application.Draw()
@ -237,6 +242,15 @@ func onPress (button stone.Button, modifiers stone.Modifiers) {
redraw()
application.Draw()
case 'z':
switch selectedExpression.(type) {
case *Operation, nil:
operation := selectedExpression.(*Operation)
operation.floating = !operation.floating
}
redraw()
application.Draw()
case 'Z':
showFloat = !showFloat
redraw()
@ -244,9 +258,10 @@ func onPress (button stone.Button, modifiers stone.Modifiers) {
}
}
func insertOperation (symbol rune, swap bool) {
func insertOperation (symbol rune, swap, encompass bool) {
var opcode Opcode
switch (symbol) {
case '?': opcode = OpcodeUnknown
case '+': opcode = OpcodeAdd
case '-': opcode = OpcodeSubtract
case '*': opcode = OpcodeMultiply
@ -263,6 +278,23 @@ func insertOperation (symbol rune, swap bool) {
case 'm': opcode = OpcodeMean
}
newExpression := Operation { opcode: opcode, floating: showFloat }
if encompass {
if selectedExpression == nil { return }
parent := selectedExpression.Parent()
newExpression.Adopt(selectedExpression)
if parent == nil {
expressionRoot = &newExpression
} else {
parent.Swap(selectedExpression, &newExpression)
}
selectedExpression = &newExpression
return
}
operation, isOperation := selectedExpression.(*Operation)
if isOperation {
if operation.opcode == OpcodeUnknown || swap {
@ -270,9 +302,8 @@ func insertOperation (symbol rune, swap bool) {
return
}
}
newExpression := &Operation { opcode: opcode, floating: showFloat }
insertGeneric(newExpression, swap, false, true)
insertGeneric(&newExpression, swap, false, true)
}
func insertNumber (value int64, swap, before bool) {