ericoporto / ImGi

AGS Script Module for Immediate Gui (based on rxi's Microui)
https://www.adventuregamestudio.co.uk/forums/index.php?topic=58842.0
Other
2 stars 2 forks source link

Support moving the text cursor on textboxes #13

Open ericoporto opened 3 years ago

ericoporto commented 3 years ago

This was done in https://github.com/mierenhoop/microui/commit/fd120b6440a7836abd02c8dd7529729b6a14d6de

May be interesting to replicate here and see if it works!

ericoporto commented 3 years ago

This code is not exactly production ready actually so it may require more experiments

I played around a bit and got something more or less

    /* handle text input */
    int len = buf.Length;
    int n = _min(bufsz - len - 1,  this.input_text.Length);
    if(n > 0)
    {
      String before_cur = buf.Substring(0, this.input_cursor);
      String after_cur = buf.Substring(this.input_cursor, buf.Length - this.input_cursor);
      before_cur = before_cur.Append(this.input_text.Truncate(n));
      buf = before_cur;
      buf = buf.Append(after_cur);
      res.state = res.state | eImGi_Res_Change;
    }

Still need to think more before doing this. I think Snarky has this working in AGS Script somewhere that I could take a look and see how he accomplished it.

ericoporto commented 3 years ago

Snarky has a very useful implementation for AGS going on here: https://github.com/messengerbag/TextField/blob/master/TextField.asc

There are probably useful things I could borrow - adapting for ImGi needs.