summaryrefslogtreecommitdiff
path: root/windowGeneric.go
blob: 967ca0af9c9863f9a1ffd36b5da79e6e5f747526 (plain)
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0

package main

import (
	"go.wit.com/lib/gadgets"
	"go.wit.com/log"

	"go.wit.com/gui"
)

type genericWindow struct {
	win    *gadgets.BasicWindow // the window widget itself
	box    *gui.Node            // the overall shelf
	shelf  *gui.Node            // the overall shelf
	stack  *gui.Node            // the first box is a shelf
	top    *gui.Node            // the first item in the stack is always a box
	group  *gui.Node            // the first item top box is always a group
	middle *gui.Node            // the middle box
	bottom *gui.Node            // the bottom box of the repolist window
}

func (r *genericWindow) Hidden() bool {
	if r == nil {
		return true
	}
	if r.win == nil {
		return true
	}
	return r.win.Hidden()
}

func (r *genericWindow) Toggle() {
	if r.Hidden() {
		r.Show()
	} else {
		r.Hide()
	}
}

func (r *genericWindow) Show() {
	if r == nil {
		return
	}
	if r.win == nil {
		return
	}
	r.win.Show()
}

func (r *genericWindow) Hide() {
	if r == nil {
		return
	}
	if r.win == nil {
		return
	}
	r.win.Hide()
}

func (r *genericWindow) Disable() {
	if r == nil {
		return
	}
	if r.box == nil {
		return
	}
	r.box.Disable()
}

func (r *genericWindow) Enable() {
	if r == nil {
		return
	}
	if r.box == nil {
		return
	}
	r.box.Enable()
}

func initGenericWindow(title string, grouptxt string) *genericWindow {
	gw := new(genericWindow)
	gw.win = gadgets.RawBasicWindow(title)
	gw.win.Make()

	gw.win.Custom = func() {
		log.Warn("Found Window close. setting hidden=true")
		// sets the hidden flag to false so Toggle() works
		gw.win.Hide()
	}
	gw.box = gw.win.Box()
	gw.shelf = gw.box
	gw.stack = gw.shelf.NewVerticalBox("STACKBOX") // a vertical box (like a stack of books)
	gw.top = gw.stack.Box()
	gw.group = gw.top.NewGroup(grouptxt)
	gw.middle = gw.stack.Box()
	gw.middle.Vertical()
	gw.bottom = gw.stack.Box()
	gw.Show()

	return gw
}