Jelajahi Sumber

SVI Добавление компонентов WUI; 100.0%

SVI 1 tahun lalu
induk
melakukan
3d2cfd218e
3 mengubah file dengan 74 tambahan dan 0 penghapusan
  1. 42 0
      wui/wlabel/wlabel.go
  2. 31 0
      wui/wlabel/wlabel_test.go
  3. 1 0
      wui/wtypes/iwui_label.go

+ 42 - 0
wui/wlabel/wlabel.go

@@ -0,0 +1,42 @@
+// package wlabel -- WUI метка
+package wlabel
+
+import (
+	"strings"
+
+	"gitp78su.ipnodns.ru/svi/kern/wui/wtext"
+	. "gitp78su.ipnodns.ru/svi/kern/wui/wtypes"
+	"gitp78su.ipnodns.ru/svi/kern/wui/wwidget"
+)
+
+// WuiLabel -- WUI метка
+type WuiLabel struct {
+	IWuiWidget
+	text IWuiText
+}
+
+// NewWuiLabel -- возвращает новую метку
+func NewWuiLabel(text string) *WuiLabel {
+	sf := &WuiLabel{
+		IWuiWidget: wwidget.NewWuiWidget(),
+		text:       wtext.NewWuiText(text),
+	}
+	_ = IWuiLabel(sf)
+	return sf
+}
+
+// Text -- возвращает текст метки
+func (sf *WuiLabel) Text() IWuiText {
+	return sf.text
+}
+
+const (
+	strBeg = `<div id="{.id}">{.txt}</div>`
+)
+
+// Html -- возвращает HTML-представление текста
+func (sf *WuiLabel) Html() string {
+	strRes := strings.ReplaceAll(strBeg, "{.id}", sf.Id())
+	strRes = strings.ReplaceAll(strRes, "{.txt}", sf.text.Get())
+	return strRes
+}

+ 31 - 0
wui/wlabel/wlabel_test.go

@@ -0,0 +1,31 @@
+package wlabel
+
+import (
+	"testing"
+)
+
+type tester struct {
+	t *testing.T
+}
+
+func TestWuiLabel(t *testing.T) {
+	sf := &tester{
+		t: t,
+	}
+	sf.new()
+}
+
+// Создаёт новую метку
+func (sf *tester) new() {
+	sf.t.Log("new")
+	lbl := NewWuiLabel("test_lbl")
+	if lbl == nil {
+		sf.t.Fatalf("new(): WuiLabel==nil")
+	}
+	if txt := lbl.Text(); txt == nil {
+		sf.t.Fatalf("new(): txt==nil")
+	}
+	if html := lbl.Html(); html == "" {
+		sf.t.Fatalf("new(): html is empty")
+	}
+}

+ 1 - 0
wui/wtypes/iwui_label.go

@@ -2,6 +2,7 @@ package wtypes
 
 // IWuiLabel -- текстовая метка
 type IWuiLabel interface {
+	IWuiWidget
 	// Text -- возвращает текст метки
 	Text() IWuiText
 }