File: framefocus.go

package info (click to toggle)
termshark 2.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 1,800 kB
  • sloc: sh: 98; makefile: 9
file content (89 lines) | stat: -rw-r--r-- 1,892 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Copyright 2019-2021 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 framefocus provides a very specific widget to apply a frame around the widget in focus
// and an empty frame if not.
package framefocus

import (
	"runtime"

	"github.com/gcla/gowid"
	"github.com/gcla/gowid/widgets/framed"
	"github.com/gcla/gowid/widgets/holder"
	"github.com/gcla/gowid/widgets/isselected"
)

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

type Widget struct {
	*isselected.Widget
	h *holder.Widget
}

func New(w gowid.IWidget) *Widget {
	h := holder.New(w)

	noFocusFrame := framed.SpaceFrame
	noFocusFrame.T = 0
	noFocusFrame.B = 0

	return &Widget{
		Widget: isselected.New(
			framed.New(h, framed.Options{
				Frame: noFocusFrame,
			}),
			framed.NewUnicodeAlt2(h),
			framed.NewUnicode(h),
		),
		h: h,
	}
}

func NewSlim(w gowid.IWidget) *Widget {
	h := holder.New(w)

	noFocusFrame := framed.SpaceFrame
	selectedFrame := framed.UnicodeAlt2Frame
	focusFrame := framed.UnicodeFrame
	if runtime.GOOS == "windows" {
		selectedFrame = framed.UnicodeFrame
		focusFrame = framed.UnicodeAlt2Frame
	}
	noFocusFrame.T = 0
	noFocusFrame.B = 0
	selectedFrame.T = 0
	selectedFrame.B = 0
	focusFrame.T = 0
	focusFrame.B = 0

	return &Widget{
		Widget: isselected.New(
			framed.New(h, framed.Options{
				Frame: noFocusFrame,
			}),
			framed.New(h, framed.Options{
				Frame: selectedFrame,
			}),
			framed.New(h, framed.Options{
				Frame: focusFrame,
			}),
		),
		h: h,
	}
}

func (w *Widget) SubWidget() gowid.IWidget {
	return w.h.SubWidget()
}

func (w *Widget) SetSubWidget(wi gowid.IWidget, app gowid.IApp) {
	w.h.SetSubWidget(wi, app)
}

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