Skip to content

Commit ca5aa94

Browse files
committed
Added more font options
1 parent 8c788f3 commit ca5aa94

File tree

1 file changed

+87
-33
lines changed

1 file changed

+87
-33
lines changed

lua/tabbed_window.lua

Lines changed: 87 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ Exposed functions:
1111
1212
init (context) -- call once (from OnPluginInstall), supply:
1313
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
1820
context.tab_filler -- gap between tabs
1921
context.can_move -- can window be dragged around?
2022
context.active_tab -- the currently active tab
@@ -23,37 +25,65 @@ Exposed functions:
2325
draw_window (context, which_tab) -- draws the window with which_tab as the active tab
2426
hide_window (context) -- hides this window
2527
save_state (context) -- for saving the window position (call from OnPluginSaveState)
28+
29+
Exposed variables:
30+
31+
VERSION -- version of this module
2632
2733
--]]
2834

29-
3035
module (..., package.seeall)
3136

37+
VERSION = 1.1 -- -- for querying by plugins
38+
3239
require "movewindow" -- load the movewindow.lua module
3340

3441
local default_context = {
3542

3643
-- window ID
3744
win = "tabbed_window_" .. GetUniqueID (),
3845

39-
-- font for text
40-
font = {
46+
-- font for inactive tab text
47+
tabfont = {
4148
id = "fn",
4249
name = "Lucida Console",
4350
size = 10, -- points
4451
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+
4776
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
5787
}, -- end of colours
5888

5989
-- miniwindow size
@@ -80,7 +110,9 @@ local default_context = {
80110

81111
} -- end of default_context
82112

83-
113+
-- -------------------------------------------------------------------------------
114+
-- init - initialize this module ready for use (do once)
115+
-- -------------------------------------------------------------------------------
84116
function init (context)
85117

86118
-- make copy of colours, sizes etc.
@@ -102,14 +134,20 @@ function init (context)
102134
context [k] = context [k] or v
103135
end -- if table or not
104136
end -- for
137+
138+
if next (context.tabs) == nil then
139+
ColourNote ("orange", "", "Warning: no tabs define for tabbed window")
140+
end -- if
105141

106142
-- 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
108144

109145
-- save a bit of typing
110146
local windowinfo = context.windowinfo
111147
local win = context.win
112-
local font = context.font
148+
local tabfont = context.tabfont
149+
local activefont = context.activefont
150+
local titlefont = context.titlefont
113151
local window = context.window
114152
local colours = context.colours
115153

@@ -123,10 +161,14 @@ function init (context)
123161
windowinfo.window_flags,
124162
colours.background)
125163

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
128170

129-
context.client_bottom = context.window.height - context.font.height - 8
171+
context.client_bottom = context.window.height - context.tabfont.height - 8
130172

131173
end -- init
132174

@@ -145,7 +187,9 @@ function draw_window (context, whichTab)
145187
-- save a bit of typing
146188
local windowinfo = context.windowinfo
147189
local win = context.win
148-
local font = context.font
190+
local tabfont = context.tabfont
191+
local activefont = context.activefont
192+
local titlefont = context.titlefont
149193
local window = context.window
150194
local colours = context.colours
151195
local tabs = context.tabs
@@ -157,11 +201,11 @@ function draw_window (context, whichTab)
157201
WindowDeleteAllHotspots (win)
158202

159203
-- 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)
161205

162206
-- add the drag handler so they can move the window around
163207
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)
165209
end -- if can move the window
166210

167211
local thisTab = tabs [whichTab]
@@ -172,10 +216,10 @@ function draw_window (context, whichTab)
172216
end -- no such tab
173217

174218
-- 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)
176220

177221
-- 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)
179223

180224
-- frame window
181225
WindowRectOp (win, miniwin.rect_frame, 0, 0, 0, 0, colours.frame)
@@ -201,13 +245,23 @@ function draw_window (context, whichTab)
201245
end -- mouse_down_function_name
202246

203247
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+
206256
-- tab background
207257
WindowRectOp (win, miniwin.rect_fill, left, client_bottom, left + tab_width + tab_filler, window.height - 1, colours.tab)
208258

209259
-- 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
211265

212266
-- draw upper line if not active tab
213267
if k ~= whichTab then
@@ -243,7 +297,7 @@ function draw_window (context, whichTab)
243297
-- call handler to draw rest of window
244298
local handler = thisTab.handler
245299
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)
247301
else
248302
ColourNote ("orange", "", "No tab handler for " .. thisTab.name)
249303
end -- if

0 commit comments

Comments
 (0)