Implemented rangeLimit for input / And NoErase#151
Conversation
Issue elcritch#149 - implemented rangeLimit as an int parameter for the insert proc - implemented overWrite as a boolean parameter for the insert proc - added NoErase to the delete/backspace logic of the input widget - fixed the updateInput override in tinput2.nim - ensured all tests pass in ttextboxes.nim
| proc overrideUpdateInput(this: Input, rune: Rune) {.slot.} = | ||
| let isDigit = rune <=% Rune('9') and rune.char in {'0'..'9'} | ||
| template currCharColon(): bool = this.text.runeAtCursor() == Rune(':') | ||
| this.skipSelectedRune() | ||
| if isDigit: | ||
| this.updateInput(rune) | ||
| this.text.insert(rune, overWrite = true, rangeLimit = 8) | ||
| onInit: | ||
| this.activate() | ||
|
|
||
| disconnect(this, doUpdateInput, this, updateInput) | ||
| connect(this, doUpdateInput, this, overrideUpdateInput) | ||
|
|
There was a problem hiding this comment.
I was getting double input per key press from the original code. This probably isn't the optimal solution, but I figured you could help with that.
There was a problem hiding this comment.
I was getting double input per key press from the original code. This probably isn't the optimal solution, but I figured you could help with that.
Ah yep that's the bit related to moving the connect's into initialize. This might not be a bad way to do it. It's more explicit for widget user, but maybe that's not bad.
Basically we just need to come up with a pattern that's fairly easy to follow.
There was a problem hiding this comment.
that's the bit related to moving the connect's into initialize.
Ahh right... too obvious. ;-]
Basically we just need to come up with a pattern that's fairly easy to follow.
Agreed. I think the before and after signals as proposed in #150 serves as a much more powerful pattern than what I've done here. That said, this seems to work as a temporary fix for tinput2.
There was a problem hiding this comment.
Good points, looks good for now. Let's see how it plays out. There's might be benefits to modifying the connect's like this. It's essentially just storing the state in a table in the input object. It's not a huge overhead.
Offset was being calculated relative to one side of the selection rather than the cursorPos.
Issue #149