Added text input example (non-working)
This commit is contained in:
		
							parent
							
								
									7dde0ad5a3
								
							
						
					
					
						commit
						872b36d172
					
				
							
								
								
									
										52
									
								
								examples/type/main.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										52
									
								
								examples/type/main.go
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,52 @@ | ||||
| package main | ||||
| 
 | ||||
| import "os" | ||||
| import "image" | ||||
| import _ "image/png" | ||||
| import "git.tebibyte.media/sashakoshka/stone" | ||||
| import _ "git.tebibyte.media/sashakoshka/stone/backends/x" | ||||
| 
 | ||||
| var application = &stone.Application { } | ||||
| var caret = 0 | ||||
| 
 | ||||
| func main () { | ||||
| 	application.SetTitle("hellorld") | ||||
| 	application.SetSize(32, 16) | ||||
| 
 | ||||
| 	iconFile16, err := os.Open("assets/scaffold16.png") | ||||
| 	if err != nil { panic(err) } | ||||
| 	icon16, _, err := image.Decode(iconFile16) | ||||
| 	if err != nil { panic(err) } | ||||
| 	iconFile16.Close() | ||||
| 	iconFile32, err := os.Open("assets/scaffold32.png") | ||||
| 	if err != nil { panic(err) } | ||||
| 	icon32, _, err := image.Decode(iconFile32) | ||||
| 	if err != nil { panic(err) } | ||||
| 	iconFile16.Close() | ||||
| 	 | ||||
| 	application.SetIcon([]image.Image { icon16, icon32 }) | ||||
| 	 | ||||
| 	channel, err := application.Run() | ||||
| 	if err != nil { panic(err) } | ||||
| 	 | ||||
| 	application.Draw() | ||||
| 
 | ||||
| 	for { | ||||
| 		event := <- channel | ||||
| 		switch event.(type) { | ||||
| 		case stone.EventQuit: | ||||
| 			os.Exit(0) | ||||
| 
 | ||||
| 		case stone.EventPress: | ||||
| 			event := event.(stone.EventPress) | ||||
| 			if stone.event.Printable() { | ||||
| 				application.SetRune(caret, 0, rune(stone.event)) | ||||
| 				caret ++ | ||||
| 				application.Draw() | ||||
| 			} | ||||
| 
 | ||||
| 		case stone.EventResize: | ||||
| 			application.Draw() | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user