Created
April 6, 2020 18:59
-
-
Save montyr75/8e2ef7e1591e4446dc1b7b6a082c4f46 to your computer and use it in GitHub Desktop.
Calculate grid position in 1D model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// If you have an array or string containing cell data for a "grid", | |
// you can calculate x and y coords using division and the row length. | |
// define the row length in the virtual grid | |
const rowLength = 8; | |
// create a 1D model representing the "grid" | |
final onScreenKeyboard = 'abcde123fghij456klmno789pqrst.@0uvwxyz_/^ '; | |
// this function will return the grid position of the given content (content must be unique) | |
Point getPos(String grid, String content) { | |
final contentIndex = grid.indexOf(content); | |
return Point(contentIndex ~/ rowLength, contentIndex % rowLength); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment