File: testwidget.go

package info (click to toggle)
golang-github-gcla-gowid 1.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,456 kB
  • sloc: makefile: 4
file content (62 lines) | stat: -rw-r--r-- 1,624 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright 2019-2022 Graham Clark. All rights reserved.  Use of this source
// code is governed by the MIT license that can be found in the LICENSE
// file.

// Package text provides a text field widget.
package text

import (
	"fmt"

	"github.com/gcla/gowid"
	tcell "github.com/gdamore/tcell/v2"
)

//======================================================================

type Widget1 struct {
	I int
}

func (w *Widget1) RenderSize(size gowid.IRenderSize, focus gowid.Selector, app gowid.IApp) gowid.IRenderBox {
	if focus.Focus {
		return New(fmt.Sprintf("%df", w.I)).RenderSize(size, focus, app)
	} else {
		return New(fmt.Sprintf("%d ", w.I)).RenderSize(size, focus, app)
	}
}

func (w *Widget1) Render(size gowid.IRenderSize, focus gowid.Selector, app gowid.IApp) gowid.ICanvas {
	if focus.Focus {
		return New(fmt.Sprintf("%df", w.I)).Render(size, focus, app)
	} else {
		return New(fmt.Sprintf("%d ", w.I)).Render(size, focus, app)
	}
}

func (w *Widget1) UserInput(ev interface{}, size gowid.IRenderSize, focus gowid.Selector, app gowid.IApp) bool {

	switch ev := ev.(type) {
	case *tcell.EventKey:
		if focus.Focus {
			return New(fmt.Sprintf("%df", w.I)).UserInput(ev, size, focus, app)
		} else {
			return New(fmt.Sprintf("%d ", w.I)).UserInput(ev, size, focus, app)
		}
	case *tcell.EventMouse:
		// Take all mouse input so I can test clicking in different columns changing the focus
		return true
	}

	return false
}

func (w *Widget1) Selectable() bool {
	return true
}

//======================================================================
// Local Variables:
// mode: Go
// fill-column: 110
// End: