summaryrefslogtreecommitdiff
path: root/toolkit/andlabs/delete.go
blob: 82727febefbf55b440c3542b28c4687ce49e2411 (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
package main

// if you include more than just this import
// then your plugin might be doing something un-ideal (just a guess from 2023/02/27)
import "git.wit.org/wit/gui/toolkit"

// delete the child widget from the parent
// p = parent, c = child
func (n *node) destroy() {
	pId := n.parent.WidgetId
	cId := n.WidgetId
	log(logNow, "delete()", pId, cId)

	pt := n.parent.tk
	ct := n.tk
	if (ct == nil) {
		log(true, "delete FAILED (ct = mapToolkit[c] == nil) for c", pId, cId)
		// this pukes out a whole universe of shit
		// listMap()
		return
	}

	switch n.WidgetType {
	case toolkit.Button:
		log(true, "Should delete Button here:", n.Name)
		log(true, "Parent:")
		pt.Dump(true)
		log(true, "Child:")
		ct.Dump(true)
		if (pt.uiBox == nil) {
			log(true, "Don't know how to destroy this")
		} else {
			log(true, "Fuck it, destroy the whole box", n.parent.Name)
			// pt.uiBox.Destroy() // You have a bug: You cannot destroy a uiControl while it still has a parent.
			pt.uiBox.SetPadded(false)
			pt.uiBox.Delete(4)
			ct.uiButton.Disable()
			// ct.uiButton.Hide()
			ct.uiButton.Destroy()
		}

	case toolkit.Window:
		log(true, "Should delete Window here:", n.Name)
	default:
		log(true, "Fuckit, let's destroy a button")
		if (ct.uiButton != nil) {
			pt.uiBox.Delete(4)
			ct.uiButton.Destroy()
		}
	}
}