SetView creates a new view with its top-left corner at (x0, y0) and the bottom-right one at (x1, y1). If a view with the same name already exists, its dimensions are updated; otherwise, the error ErrUnknownView is returned, which allows to assert if the View must be initialized. It checks if the pos
(name string, x0, y0, x1, y1 int, overlaps byte)
| 307 | // ErrUnknownView is returned, which allows to assert if the View must |
| 308 | // be initialized. It checks if the position is valid. |
| 309 | func (g *Gui) SetView(name string, x0, y0, x1, y1 int, overlaps byte) (*View, error) { |
| 310 | if name == "" { |
| 311 | return nil, errors.New("invalid name") |
| 312 | } |
| 313 | |
| 314 | if v, err := g.View(name); err == nil { |
| 315 | sizeChanged := v.x0 != x0 || v.x1 != x1 || v.y0 != y0 || v.y1 != y1 |
| 316 | |
| 317 | v.x0 = x0 |
| 318 | v.y0 = y0 |
| 319 | v.x1 = x1 |
| 320 | v.y1 = y1 |
| 321 | |
| 322 | if sizeChanged { |
| 323 | v.clearViewLines() |
| 324 | |
| 325 | if v.Editable { |
| 326 | cursorX, cursorY := v.TextArea.GetCursorXY() |
| 327 | newViewCursorX, newOriginX := updatedCursorAndOrigin(0, v.InnerWidth(), cursorX) |
| 328 | newViewCursorY, newOriginY := updatedCursorAndOrigin(0, v.InnerHeight(), cursorY) |
| 329 | |
| 330 | v.SetCursor(newViewCursorX, newViewCursorY) |
| 331 | v.SetOrigin(newOriginX, newOriginY) |
| 332 | } |
| 333 | } |
| 334 | |
| 335 | return v, nil |
| 336 | } |
| 337 | |
| 338 | g.Mutexes.ViewsMutex.Lock() |
| 339 | |
| 340 | v := NewView(name, x0, y0, x1, y1, g.outputMode) |
| 341 | v.BgColor, v.FgColor = g.BgColor, g.FgColor |
| 342 | v.SelBgColor, v.SelFgColor = g.SelBgColor, g.SelFgColor |
| 343 | v.Overlaps = overlaps |
| 344 | g.views = append(g.views, v) |
| 345 | |
| 346 | v.setOnSelectResult(g.onSelectSearchItem) |
| 347 | v.setRenderSearchStatus(g.renderSearchStatus) |
| 348 | |
| 349 | g.Mutexes.ViewsMutex.Unlock() |
| 350 | |
| 351 | return v, errors.Wrap(ErrUnknownView, 0) |
| 352 | } |
| 353 | |
| 354 | func (g *Gui) onSelectSearchItem(v *View, selectedLineIdx int) { |
| 355 | if g.onSelectSearchResultFunc != nil { |