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