SetImage sets the optional image of the Tab header
(imgfile string)
| 493 | |
| 494 | // SetImage sets the optional image of the Tab header |
| 495 | func (tab *Tab) SetImage(imgfile string) error { |
| 496 | |
| 497 | // Remove previous icon if any |
| 498 | if tab.icon != nil { |
| 499 | tab.header.Remove(tab.icon) |
| 500 | tab.icon.Dispose() |
| 501 | tab.icon = nil |
| 502 | } |
| 503 | // Creates or updates image |
| 504 | if tab.image == nil { |
| 505 | // Creates image panel from file |
| 506 | img, err := NewImage(imgfile) |
| 507 | if err != nil { |
| 508 | return err |
| 509 | } |
| 510 | tab.image = img |
| 511 | tab.image.SetPaddingsFrom(&tab.styles.ImagePaddings) |
| 512 | tab.header.Add(tab.image) |
| 513 | } else { |
| 514 | err := tab.image.SetImage(imgfile) |
| 515 | if err != nil { |
| 516 | return err |
| 517 | } |
| 518 | } |
| 519 | // Scale image so its height is not greater than the Label height |
| 520 | if tab.image.Height() > tab.label.Height() { |
| 521 | tab.image.SetContentAspectHeight(tab.label.Height()) |
| 522 | } |
| 523 | // Needs to recalculate all Tabs because this Tab width will change |
| 524 | tab.tb.recalc() |
| 525 | return nil |
| 526 | } |
| 527 | |
| 528 | // SetPinned sets the tab pinned state. |
| 529 | // A pinned tab cannot be removed by the user because the close icon is not shown. |
no test coverage detected