wlabel.go 934 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // package wlabel -- WUI метка
  2. package wlabel
  3. import (
  4. "strings"
  5. "gitp78su.ipnodns.ru/svi/kern/wui/wtext"
  6. . "gitp78su.ipnodns.ru/svi/kern/wui/wtypes"
  7. "gitp78su.ipnodns.ru/svi/kern/wui/wwidget"
  8. )
  9. // WuiLabel -- WUI метка
  10. type WuiLabel struct {
  11. IWuiWidget
  12. text IWuiText
  13. }
  14. // NewWuiLabel -- возвращает новую метку
  15. func NewWuiLabel(text string) *WuiLabel {
  16. sf := &WuiLabel{
  17. IWuiWidget: wwidget.NewWuiWidget(),
  18. text: wtext.NewWuiText(text),
  19. }
  20. _ = IWuiLabel(sf)
  21. return sf
  22. }
  23. // Text -- возвращает текст метки
  24. func (sf *WuiLabel) Text() IWuiText {
  25. return sf.text
  26. }
  27. const (
  28. strBeg = `<div id="{.id}">{.txt}</div>`
  29. )
  30. // Html -- возвращает HTML-представление текста
  31. func (sf *WuiLabel) Html() string {
  32. strRes := strings.ReplaceAll(strBeg, "{.id}", sf.Id())
  33. strRes = strings.ReplaceAll(strRes, "{.txt}", sf.text.Get())
  34. return strRes
  35. }