Exemple #1
0
func (w *window) updateChildrenRect(rect tuikit.Rect) error {
	for i, v := range []*tuikit.TextView{w.userLabel, w.sysLabel, w.idleLabel} {
		w.AttachChild(v, tuikit.NewRect(0, i, rect.Width, 1))
	}
	for i, v := range []*tuikit.TextView{w.user, w.sys, w.idle} {
		w.AttachChild(v, tuikit.NewRect(8, i, rect.Width, 1))
	}
	return nil
}
Exemple #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
}