Ejemplo n.º 1
0
func newWindow() *window {
	w := &window{
		BaseView:  tuikit.NewBaseView(),
		userLabel: tuikit.NewTextView(),
		user:      tuikit.NewTextView(),
		sysLabel:  tuikit.NewTextView(),
		sys:       tuikit.NewTextView(),
		idleLabel: tuikit.NewTextView(),
		idle:      tuikit.NewTextView(),
	}
	w.userLabel.SetText("User: "******"System: ")
	w.idleLabel.SetText("Idle: ")
	w.SetUpdateChildrenRect(w.updateChildrenRect)
	return w
}
Ejemplo n.º 2
0
func (w *window) updateChildrenRect(rect tuikit.Rect) error {
	for _, v := range w.views {
		w.DetachChild(v)
	}

	ns := rect.Width * rect.Height
	diff := ns - len(w.views)
	if diff > 0 {
		for i := 0; i < diff; i++ {
			rs := newRandomString()
			tv := tuikit.NewTextView()

			go func() {
				for _ = range rs.Subscribe() {
					tv.SetText(rs.Get())
				}
			}()
			rs.startRandomness()

			w.randomStrings = append(w.randomStrings, rs)
			w.views = append(w.views, tv)
		}
	} else {
		for _, rs := range w.randomStrings[ns:] {
			rs.Dispose()
		}
		w.randomStrings = w.randomStrings[:ns]
		w.views = w.views[:ns]
	}

	for i, v := range w.views {
		dx := int(i % rect.Width)
		dy := int(i / rect.Width)
		w.AttachChild(v, tuikit.NewRect(dx, dy, 1, 1))
	}

	return nil
}