MCPcopy Index your code
hub / github.com/g3n/engine / CursorInput

Method CursorInput

gui/edit.go:185–210  ·  view source on GitHub ↗

CursorInput inserts the specified string at the current cursor position

(s string)

Source from the content-addressed store, hash-verified

183
184// CursorInput inserts the specified string at the current cursor position
185func (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
213func (ed *Edit) redraw(caret bool) {

Callers 1

onCharMethod · 0.95

Calls 6

redrawMethod · 0.95
StrCountFunction · 0.92
StrInsertFunction · 0.92
MeasureTextMethod · 0.80
ContentWidthMethod · 0.80
DispatchMethod · 0.65

Tested by

no test coverage detected