MCPcopy
hub / github.com/g3n/engine / SetImage

Method SetImage

gui/tabbar.go:495–526  ·  view source on GitHub ↗

SetImage sets the optional image of the Tab header

(imgfile string)

Source from the content-addressed store, hash-verified

493
494// SetImage sets the optional image of the Tab header
495func (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.

Callers 1

buildTabBarFunction · 0.45

Calls 8

NewImageFunction · 0.85
SetPaddingsFromMethod · 0.80
DisposeMethod · 0.65
HeightMethod · 0.65
RemoveMethod · 0.45
AddMethod · 0.45
recalcMethod · 0.45

Tested by

no test coverage detected