about summary refs log tree commit diff stats
path: root/src/ui/titlebar.h
blob: bc4e6a57c749f25aaf926722505b90dad4b2a05a (plain) (blame)
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
/*
 * titlebar.h
 *
 * Copyright (C) 2012 - 2014 James Booth <boothj5@gmail.com>
 *
 * This file is part of Profanity.
 *
 * Profanity is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Profanity is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Profanity.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#ifndef UI_TITLEBAR_H
#define UI_TITLEBAR_H

void create_title_bar(void);
void title_bar_update_virtual(void);
void title_bar_resize(void);
void title_bar_console(void);
void title_bar_set_presence(contact_presence_t presence);
void title_bar_set_recipient(const char * const from);
void title_bar_set_typing(gboolean is_typing);

#endif
' href='/akspecs/aerc/commit/ui/context.go?h=0.6.0&id=8c8c21f3ffef1a7083405c45221576858d1af5d5'>8c8c21f ^
80e891a ^
6728a11 ^
80e891a ^
8c8c21f ^
6728a11 ^
80e891a ^
8c8c21f ^
80e891a ^
bcd03c4 ^
8c8c21f ^

80e891a ^


8c8c21f ^

80e891a ^

8c8c21f ^

80e891a ^
5b2e3a0 ^
80e891a ^
8c8c21f ^
80e891a ^
8c8c21f ^




8c8c21f ^




80e891a ^
8c8c21f ^




5b2e3a0 ^
8c8c21f ^



80e891a ^

5b2e3a0 ^
6728a11 ^
8c8c21f ^
5b2e3a0 ^
8c8c21f ^



5b2e3a0 ^

8c8c21f ^

80e891a ^





d35213e ^




8c8c21f ^
bcd03c4 ^









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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126




             

                                        
                                       



                                                               



                                 

 
                             

                                                


                             

                                                

 
                                 

                                       


                                  

                                        

 
                                                                                    
                                                            
                                            


                                                                  
                                                  
                           
                                                                                     
         
                                                       
                                                                                   
         
                                                                  
                                                                            

 


                                                                   

                                                                         

                                                        

 
                                                       
                                              
                                            
 
                                      




                                                                         




                                
                                 




                                       
                                                                 



                                 

                                                                        
                                                    
                                             
                                               
                                                                         



                                 

                                         

 





                                                                                 




                                               
 









                                                                  
package ui

import (
	"fmt"

	"github.com/gdamore/tcell"
	"github.com/gdamore/tcell/views"
	"github.com/mattn/go-runewidth"
)

// A context allows you to draw in a sub-region of the terminal
type Context struct {
	screen    tcell.Screen
	viewport  *views.ViewPort
	x, y      int
	onPopover func(*Popover)
}

func (ctx *Context) X() int {
	x, _, _, _ := ctx.viewport.GetPhysical()
	return x
}

func (ctx *Context) Y() int {
	_, y, _, _ := ctx.viewport.GetPhysical()
	return y
}

func (ctx *Context) Width() int {
	width, _ := ctx.viewport.Size()
	return width
}

func (ctx *Context) Height() int {
	_, height := ctx.viewport.Size()
	return height
}

func NewContext(width, height int, screen tcell.Screen, p func(*Popover)) *Context {
	vp := views.NewViewPort(screen, 0, 0, width, height)
	return &Context{screen, vp, 0, 0, p}
}

func (ctx *Context) Subcontext(x, y, width, height int) *Context {
	vp_width, vp_height := ctx.viewport.Size()
	if x < 0 || y < 0 {
		panic(fmt.Errorf("Attempted to create context with negative offset"))
	}
	if x+width > vp_width || y+height > vp_height {
		panic(fmt.Errorf("Attempted to create context larger than parent"))
	}
	vp := views.NewViewPort(ctx.viewport, x, y, width, height)
	return &Context{ctx.screen, vp, ctx.x + x, ctx.y + y, ctx.onPopover}
}

func (ctx *Context) SetCell(x, y int, ch rune, style tcell.Style) {
	width, height := ctx.viewport.Size()
	if x >= width || y >= height {
		panic(fmt.Errorf("Attempted to draw outside of context"))
	}
	crunes := []rune{}
	ctx.viewport.SetContent(x, y, ch, crunes, style)
}

func (ctx *Context) Printf(x, y int, style tcell.Style,
	format string, a ...interface{}) int {
	width, height := ctx.viewport.Size()

	if x >= width || y >= height {
		panic(fmt.Errorf("Attempted to draw outside of context"))
	}

	str := fmt.Sprintf(format, a...)

	old_x := x

	newline := func() bool {
		x = old_x
		y++
		return y < height
	}
	for _, ch := range str {
		switch ch {
		case '\n':
			if !newline() {
				return runewidth.StringWidth(str)
			}
		case '\r':
			x = old_x
		default:
			crunes := []rune{}
			ctx.viewport.SetContent(x, y, ch, crunes, style)
			x += runewidth.RuneWidth(ch)
			if x == old_x+width {
				if !newline() {
					return runewidth.StringWidth(str)
				}
			}
		}
	}

	return runewidth.StringWidth(str)
}

func (ctx *Context) Fill(x, y, width, height int, rune rune, style tcell.Style) {
	vp := views.NewViewPort(ctx.viewport, x, y, width, height)
	vp.Fill(rune, style)
}

func (ctx *Context) SetCursor(x, y int) {
	ctx.screen.ShowCursor(ctx.x+x, ctx.y+y)
}

func (ctx *Context) HideCursor() {
	ctx.screen.HideCursor()
}

func (ctx *Context) Popover(x, y, width, height int, d Drawable) {
	ctx.onPopover(&Popover{
		x:       ctx.x + x,
		y:       ctx.y + y,
		width:   width,
		height:  height,
		content: d,
	})
}