(text string, maxSize Vector, horizontalAlignment string, editable bool)
| 243 | } |
| 244 | |
| 245 | func (tr *TextRenderer) RenderText(text string, maxSize Vector, horizontalAlignment string, editable bool) *TextRendererResult { |
| 246 | |
| 247 | result := &TextRendererResult{} |
| 248 | |
| 249 | renderTexture := NewRenderTexture() |
| 250 | |
| 251 | result.Image = renderTexture |
| 252 | |
| 253 | renderTexture.RenderFunc = func() { |
| 254 | finalW := globals.GridSize |
| 255 | |
| 256 | x := 0 |
| 257 | y := 0 |
| 258 | |
| 259 | result.TextLines = [][]rune{} |
| 260 | result.LineSizes = []Vector{} |
| 261 | |
| 262 | line := []rune{} |
| 263 | |
| 264 | type renderPair struct { |
| 265 | Glyph *Glyph |
| 266 | Rect *sdl.FRect |
| 267 | } |
| 268 | |
| 269 | toRender := []*renderPair{} |
| 270 | |
| 271 | for i, c := range text { |
| 272 | |
| 273 | line = append(line, c) |
| 274 | |
| 275 | if c == '\n' { |
| 276 | |
| 277 | x = 0 |
| 278 | y += int(globals.GridSize) |
| 279 | result.TextLines = append(result.TextLines, line) |
| 280 | line = []rune{} |
| 281 | toRender = append(toRender, nil) |
| 282 | continue |
| 283 | |
| 284 | } else if c == ' ' && maxSize.X > 0 { |
| 285 | |
| 286 | end := strings.IndexAny(text[i+1:], " \n") |
| 287 | if len(text)-i < end || end < 0 { |
| 288 | end = len(text) - i |
| 289 | } |
| 290 | |
| 291 | nextStart := i |
| 292 | nextEnd := nextStart + end + 1 |
| 293 | |
| 294 | if nextStart > len(text) { |
| 295 | nextStart = len(text) |
| 296 | } |
| 297 | |
| 298 | if nextEnd > len(text) { |
| 299 | nextEnd = len(text) |
| 300 | } |
| 301 | |
| 302 | nextWord := text[nextStart:nextEnd] |
no test coverage detected