@@ -11,10 +11,12 @@ Exposed functions:
11
11
12
12
init (context) -- call once (from OnPluginInstall), supply:
13
13
14
- context.win -- window ID for this tabbed window
15
- context.font -- table of font info (name, size, unicode)
16
- context.colours -- table of assorted colours (see below for examples)
17
- context.window -- table (width and height) of the desired window size
14
+ context.win -- window ID for this tabbed window
15
+ context.tabfont -- table of font info for non-active tabs (name, size, unicode, bold, italic)
16
+ context.activefont -- table of font info for the selected tab (name, size, unicode, bold, italic)
17
+ context.titlefont -- table of font info for the title bar (name, size, unicode, bold, italic)
18
+ context.colours -- table of assorted colours (see below for examples)
19
+ context.window -- table (width and height) of the desired window size
18
20
context.tab_filler -- gap between tabs
19
21
context.can_move -- can window be dragged around?
20
22
context.active_tab -- the currently active tab
@@ -23,37 +25,65 @@ Exposed functions:
23
25
draw_window (context, which_tab) -- draws the window with which_tab as the active tab
24
26
hide_window (context) -- hides this window
25
27
save_state (context) -- for saving the window position (call from OnPluginSaveState)
28
+
29
+ Exposed variables:
30
+
31
+ VERSION -- version of this module
26
32
27
33
--]]
28
34
29
-
30
35
module (... , package.seeall )
31
36
37
+ VERSION = 1.1 -- -- for querying by plugins
38
+
32
39
require " movewindow" -- load the movewindow.lua module
33
40
34
41
local default_context = {
35
42
36
43
-- window ID
37
44
win = " tabbed_window_" .. GetUniqueID (),
38
45
39
- -- font for text
40
- font = {
46
+ -- font for inactive tab text
47
+ tabfont = {
41
48
id = " fn" ,
42
49
name = " Lucida Console" ,
43
50
size = 10 , -- points
44
51
unicode = false , -- Unicode?
45
- }, -- end of font info
46
-
52
+ bold = false , -- make bold?
53
+ italic = false , -- make italic?
54
+ }, -- end of tabfont
55
+
56
+ -- font for active tab text
57
+ activefont = {
58
+ id = " fa" ,
59
+ name = " Lucida Console" ,
60
+ size = 10 , -- points
61
+ unicode = false , -- Unicode?
62
+ bold = false , -- make bold?
63
+ italic = false , -- make italic?
64
+ }, -- end of activefont
65
+
66
+ -- font for title text
67
+ titlefont = {
68
+ id = " ft" ,
69
+ name = " Lucida Console" ,
70
+ size = 12 , -- points
71
+ unicode = false , -- Unicode?
72
+ bold = true , -- make bold?
73
+ italic = false , -- make italic?
74
+ }, -- end of titlefont
75
+
47
76
colours = {
48
- background = ColourNameToRGB (" lightskyblue" ),
49
- frame = ColourNameToRGB (" mediumorchid" ),
50
- title_bar = ColourNameToRGB (" palegoldenrod" ),
51
- title = ColourNameToRGB (" mediumblue" ),
52
- tab = ColourNameToRGB (" green" ),
53
- tab_text = ColourNameToRGB (" white" ),
54
- upper_line = ColourNameToRGB (" lightgray" ),
55
- lower_line = ColourNameToRGB (" lightgray" ),
56
- vertical_line = ColourNameToRGB (" lightgray" ),
77
+ background = ColourNameToRGB (" lightskyblue" ), -- entire window background
78
+ frame = ColourNameToRGB (" mediumorchid" ), -- frame around window
79
+ title_bar = ColourNameToRGB (" palegoldenrod" ), -- behind the title
80
+ title = ColourNameToRGB (" mediumblue" ), -- title text
81
+ tab = ColourNameToRGB (" green" ), -- tab background
82
+ tab_text = ColourNameToRGB (" white" ), -- inactive tab text
83
+ active_tab_text = ColourNameToRGB (" lightgreen" ), -- active tab text
84
+ upper_line = ColourNameToRGB (" lightgray" ), -- line above tab text
85
+ lower_line = ColourNameToRGB (" lightgray" ), -- line below tab text
86
+ vertical_line = ColourNameToRGB (" lightgray" ), -- line between tabs
57
87
}, -- end of colours
58
88
59
89
-- miniwindow size
@@ -80,7 +110,9 @@ local default_context = {
80
110
81
111
} -- end of default_context
82
112
83
-
113
+ -- -------------------------------------------------------------------------------
114
+ -- init - initialize this module ready for use (do once)
115
+ -- -------------------------------------------------------------------------------
84
116
function init (context )
85
117
86
118
-- make copy of colours, sizes etc.
@@ -102,14 +134,20 @@ function init (context)
102
134
context [k ] = context [k ] or v
103
135
end -- if table or not
104
136
end -- for
137
+
138
+ if next (context .tabs ) == nil then
139
+ ColourNote (" orange" , " " , " Warning: no tabs define for tabbed window" )
140
+ end -- if
105
141
106
142
-- install the window movement handler, get back the window position
107
- context .windowinfo = movewindow .install (context .win , miniwin .pos_top_left ) -- default to top left
143
+ context .windowinfo = movewindow .install (context .win , miniwin .pos_top_left , 0 ) -- default to top left
108
144
109
145
-- save a bit of typing
110
146
local windowinfo = context .windowinfo
111
147
local win = context .win
112
- local font = context .font
148
+ local tabfont = context .tabfont
149
+ local activefont = context .activefont
150
+ local titlefont = context .titlefont
113
151
local window = context .window
114
152
local colours = context .colours
115
153
@@ -123,10 +161,14 @@ function init (context)
123
161
windowinfo .window_flags ,
124
162
colours .background )
125
163
126
- WindowFont (win , font .id , font .name , font .size , false , false , false , false , 0 , 0 ) -- normal
127
- font .height = WindowFontInfo (win , font .id , 1 ) -- height
164
+ WindowFont (win , tabfont .id , tabfont .name , tabfont .size , tabfont .bold , tabfont .italic , false , false , 0 , 0 )
165
+ tabfont .height = WindowFontInfo (win , tabfont .id , 1 ) -- height
166
+ WindowFont (win , activefont .id , activefont .name , activefont .size , activefont .bold , activefont .italic , false , false , 0 , 0 )
167
+ activefont .height = WindowFontInfo (win , activefont .id , 1 ) -- height
168
+ WindowFont (win , titlefont .id , titlefont .name , titlefont .size , titlefont .bold , titlefont .italic , false , false , 0 , 0 )
169
+ titlefont .height = WindowFontInfo (win , titlefont .id , 1 ) -- height
128
170
129
- context .client_bottom = context .window .height - context .font .height - 8
171
+ context .client_bottom = context .window .height - context .tabfont .height - 8
130
172
131
173
end -- init
132
174
@@ -145,7 +187,9 @@ function draw_window (context, whichTab)
145
187
-- save a bit of typing
146
188
local windowinfo = context .windowinfo
147
189
local win = context .win
148
- local font = context .font
190
+ local tabfont = context .tabfont
191
+ local activefont = context .activefont
192
+ local titlefont = context .titlefont
149
193
local window = context .window
150
194
local colours = context .colours
151
195
local tabs = context .tabs
@@ -157,11 +201,11 @@ function draw_window (context, whichTab)
157
201
WindowDeleteAllHotspots (win )
158
202
159
203
-- draw drag bar rectangle
160
- WindowRectOp (win , miniwin .rect_fill , 1 , 1 , 0 , font .height + 2 , colours .title_bar )
204
+ WindowRectOp (win , miniwin .rect_fill , 1 , 1 , 0 , titlefont .height + 2 , colours .title_bar )
161
205
162
206
-- add the drag handler so they can move the window around
163
207
if context .can_move then
164
- movewindow .add_drag_handler (win , 0 , 0 , 0 , font .height )
208
+ movewindow .add_drag_handler (win , 0 , 0 , 0 , titlefont .height )
165
209
end -- if can move the window
166
210
167
211
local thisTab = tabs [whichTab ]
@@ -172,10 +216,10 @@ function draw_window (context, whichTab)
172
216
end -- no such tab
173
217
174
218
-- find title width so we can center it
175
- local title_width = WindowTextWidth (win , font .id , thisTab .name , font .unicode )
219
+ local title_width = WindowTextWidth (win , titlefont .id , thisTab .name , titlefont .unicode )
176
220
177
221
-- draw title
178
- WindowText (win , font .id , thisTab .name , (window .width - title_width )/ 2 + 1 , 1 , 0 , 0 , colours .title , font .unicode )
222
+ WindowText (win , titlefont .id , thisTab .name , (window .width - title_width )/ 2 + 1 , 1 , 0 , 0 , colours .title , titlefont .unicode )
179
223
180
224
-- frame window
181
225
WindowRectOp (win , miniwin .rect_frame , 0 , 0 , 0 , 0 , colours .frame )
@@ -201,13 +245,23 @@ function draw_window (context, whichTab)
201
245
end -- mouse_down_function_name
202
246
203
247
for k , v in ipairs (tabs ) do
204
- local tab_width = WindowTextWidth (win , font .id , v .name , font .unicode )
205
-
248
+ local tab_width
249
+
250
+ if k == whichTab then
251
+ tab_width = WindowTextWidth (win , activefont .id , v .name , activefont .unicode )
252
+ else
253
+ tab_width = WindowTextWidth (win , tabfont .id , v .name , tabfont .unicode )
254
+ end -- if
255
+
206
256
-- tab background
207
257
WindowRectOp (win , miniwin .rect_fill , left , client_bottom , left + tab_width + tab_filler , window .height - 1 , colours .tab )
208
258
209
259
-- tab text
210
- WindowText (win , font .id , v .name , left + tab_filler / 2 , client_bottom + 4 , 0 , 0 , colours .tab_text , font .unicode )
260
+ if k == whichTab then
261
+ WindowText (win , activefont .id , v .name , left + tab_filler / 2 , client_bottom + 4 , 0 , 0 , colours .active_tab_text , activefont .unicode )
262
+ else
263
+ WindowText (win , tabfont .id , v .name , left + tab_filler / 2 , client_bottom + 4 , 0 , 0 , colours .tab_text , tabfont .unicode )
264
+ end -- if
211
265
212
266
-- draw upper line if not active tab
213
267
if k ~= whichTab then
@@ -243,7 +297,7 @@ function draw_window (context, whichTab)
243
297
-- call handler to draw rest of window
244
298
local handler = thisTab .handler
245
299
if handler then
246
- handler (win , 1 , font .height + 2 , window .width - 1 , client_bottom , context )
300
+ handler (win , 1 , titlefont .height + 2 , window .width - 1 , client_bottom , context )
247
301
else
248
302
ColourNote (" orange" , " " , " No tab handler for " .. thisTab .name )
249
303
end -- if
0 commit comments