CursorInput inserts the specified string at the current cursor position
(s string)
| 183 | |
| 184 | // CursorInput inserts the specified string at the current cursor position |
| 185 | func (ed *Edit) CursorInput(s string) { |
| 186 | |
| 187 | if text.StrCount(ed.text) >= ed.MaxLength { |
| 188 | return |
| 189 | } |
| 190 | |
| 191 | // Set new text with included input |
| 192 | var newText string |
| 193 | if ed.col < text.StrCount(ed.text) { |
| 194 | newText = text.StrInsert(ed.text, s, ed.col) |
| 195 | } else { |
| 196 | newText = ed.text + s |
| 197 | } |
| 198 | |
| 199 | // Checks if new text exceeds edit width |
| 200 | width, _ := ed.Label.font.MeasureText(newText) |
| 201 | if float32(width)+editMarginX+float32(1) >= ed.Label.ContentWidth() { |
| 202 | return |
| 203 | } |
| 204 | |
| 205 | ed.text = newText |
| 206 | ed.col++ |
| 207 | |
| 208 | ed.Dispatch(OnChange, nil) |
| 209 | ed.redraw(ed.focus) |
| 210 | } |
| 211 | |
| 212 | // redraw redraws the text showing the caret if specified |
| 213 | func (ed *Edit) redraw(caret bool) { |
no test coverage detected