forked from DFHack/dfhack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwidget.lua
More file actions
57 lines (47 loc) · 1.83 KB
/
Copy pathwidget.lua
File metadata and controls
57 lines (47 loc) · 1.83 KB
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
local gui = require('gui')
------------
-- Widget --
------------
---@class widgets.Widget.frame
---@field l? integer Gap between the left edge of the frame and the parent.
---@field t? integer Gap between the top edge of the frame and the parent.
---@field r? integer Gap between the right edge of the frame and the parent.
---@field b? integer Gap between the bottom edge of the frame and the parent.
---@field w? integer Desired width
---@field h? integer Desired height
---@class widgets.Widget.inset
---@field l? integer Left margin
---@field t? integer Top margin
---@field r? integer Right margin
---@field b? integer Bottom margin
---@field x? integer Left/right margin (if `l` and/or `r` are ommited)
---@field y? integer Top/bottom margin (if `t` and/or `b` are ommited)
---@class widgets.Widget.attrs: gui.View.attrs
---@field frame? widgets.Widget.frame
---@field frame_inset? widgets.Widget.inset|integer
---@field frame_background? dfhack.pen
---@class widgets.Widget.attrs.partial: widgets.Widget.attrs
---@class widgets.Widget: gui.View
---@field super gui.View
---@field ATTRS widgets.Widget.attrs|fun(attributes: widgets.Widget.attrs.partial)
---@overload fun(init_table: widgets.Widget.attrs.partial): self
Widget = defclass(Widget, gui.View)
Widget.ATTRS {
frame = DEFAULT_NIL,
frame_inset = DEFAULT_NIL,
frame_background = DEFAULT_NIL,
}
---@param parent_rect { width: integer, height: integer }
---@return any
function Widget:computeFrame(parent_rect)
local sw, sh = parent_rect.width, parent_rect.height
return gui.compute_frame_body(sw, sh, self.frame, self.frame_inset)
end
---@param dc gui.Painter
---@param rect { x1: integer, y1: integer, x2: integer, y2: integer }
function Widget:onRenderFrame(dc, rect)
if self.frame_background then
dc:fill(rect, self.frame_background)
end
end
return Widget