danvim / Procal

2 stars 0 forks source link

Implement token insertion to input array #8

Closed danvim closed 7 years ago

danvim commented 7 years ago

Possible implementation

This is how Procal will handle key inputs.

class InputToken {
    String lexable; // "sqrt(", for parsing
    String display; // "√(", for displaying
    InputToken(String lexable, String display) {
        this.lexable = lexable;
        this.display = display;
    }
}
public static Map<String, InputToken> inputTokensMap = new HashMap<>();

inputTokensMap.put("square_root", new InputToken("sqrt(", "√("));
//rest of input tokens ...
public static List<InputToken> inputTokens = new ArrayList<>(); //for adding or removing tokens and to store them.
public static int cursorPos = 0; //where the cursor is

public static void removeInputTokenAt (int i) {/*...*/}
public static void addInputTokenAt (int i, String keyId) {/*...*/}
public static void updateMatrixDisplay () {/*...*/} //this is called by methods above to update the matrix display

//From key inputs, will be routed to methods above
public static void inputToken (String keyId) {/*...*/} //possible to handle both overwrite and insert mode, but for now, only do insert mode
public static void deleteToken (String keyId) {/*...*/} //from DEL button
dipsywong98 commented 7 years ago

add lexable to json?

danvim commented 7 years ago

@dipsywong98 no, why? but you can if you want