summary refs log tree commit diff stats
path: root/lib/ui/tab.go
diff options
context:
space:
mode:
Diffstat (limited to 'lib/ui/tab.go')
-rw-r--r--lib/ui/tab.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/ui/tab.go b/lib/ui/tab.go
index 61d544a..0061472 100644
--- a/lib/ui/tab.go
+++ b/lib/ui/tab.go
@@ -126,6 +126,19 @@ func (tabs *Tabs) removeHistory(index int) {
 	tabs.history = newHist
 }
 
+func (tabs *Tabs) MouseEvent(event tcell.Event) {
+	switch event := event.(type) {
+	case *tcell.EventMouse:
+		if event.Buttons()&tcell.Button1 != 0 {
+			x, y := event.Position()
+			selectedTab, ok := tabs.TabStrip.Clicked(x, y)
+			if ok {
+				tabs.Select(selectedTab)
+			}
+		}
+	}
+}
+
 // TODO: Color repository
 func (strip *TabStrip) Draw(ctx *Context) {
 	x := 0
@@ -151,6 +164,21 @@ func (strip *TabStrip) OnInvalidate(onInvalidate func(d Drawable)) {
 	strip.onInvalidateStrip = onInvalidate
 }
 
+func (strip *TabStrip) Clicked(mouseX int, mouseY int) (int, bool) {
+	x := 0
+	if mouseY == 0 {
+		for i, tab := range strip.Tabs {
+			trunc := runewidth.Truncate(tab.Name, 32, "…")
+			length := len(trunc) + 2
+			if x <= mouseX && mouseX < x+length {
+				return i, true
+			}
+			x += length
+		}
+	}
+	return 0, false
+}
+
 func (content *TabContent) Children() []Drawable {
 	children := make([]Drawable, len(content.Tabs))
 	for i, tab := range content.Tabs {
beam@wmii.de> 2006-07-10 16:38:18 +0200 committer Anselm R. Garbe <garbeam@wmii.de> 2006-07-10 16:38:18 +0200 initial import' href='/acidbong/suckless/dwm/commit/README?h=4.4&id=1076f2b6b3d3751d5d5db6fcb9ac8c247e04e893'>1076f2b
650a1fb ^
01a8d44 ^
650a1fb ^
1076f2b
650a1fb ^
1076f2b
650a1fb ^
1076f2b

650a1fb ^
1076f2b
eff4478 ^
1076f2b
7b5638f ^

98c6a92 ^
98c6a92 ^

02cea3b ^
7b5638f ^
2b66f7a ^
98c6a92 ^
7b5638f ^
1076f2b

dc5c070 ^

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