wui_label.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // package wui_label -- WUI метка.
  2. package wui_label
  3. import (
  4. "strings"
  5. "gitp78su.ipnodns.ru/svi/kern/v4/d0"
  6. "gitp78su.ipnodns.ru/svi/kern/v4/d2/wui/wui_ctx"
  7. "gitp78su.ipnodns.ru/svi/kern/v4/d2/wui/wui_text"
  8. mWt "gitp78su.ipnodns.ru/svi/kern/v4/d2/wui/wui_types"
  9. "gitp78su.ipnodns.ru/svi/kern/v4/d2/wui/wui_widget"
  10. )
  11. // WuiLabel -- WUI метка.
  12. type WuiLabel struct {
  13. mWt.IWuiWidget
  14. owner *d0.LOwner
  15. text mWt.IWuiText
  16. }
  17. // NewWuiLabel -- возвращает новую метку.
  18. func NewWuiLabel(owner *d0.LOwner, text *d0.LTxt) *d0.Result[*WuiLabel] {
  19. sf := &WuiLabel{
  20. IWuiWidget: wui_widget.NewWuiWidget(owner),
  21. owner: owner,
  22. text: wui_text.NewWuiText(owner, text),
  23. }
  24. wCtx := wui_ctx.GetWuiCtx()
  25. wCtx.Set(sf.Id(), sf, "WUI-метка")
  26. _ = mWt.IWuiLabel(sf)
  27. return d0.ResOk(sf)
  28. }
  29. // Text -- возвращает текст метки.
  30. func (sf *WuiLabel) Text() mWt.IWuiText {
  31. return sf.text
  32. }
  33. const (
  34. strBeg = `<div id="{.id}">{.txt}</div>`
  35. )
  36. // Html -- возвращает HTML-представление текста.
  37. func (sf *WuiLabel) Html() *d0.LTxt {
  38. strRes := strings.ReplaceAll(strBeg, "{.id}", sf.Id().String())
  39. strRes = strings.ReplaceAll(strRes, "{.txt}", sf.text.String())
  40. return d0.LetTxt(sf.owner, strRes)
  41. }