-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.lua
63 lines (58 loc) · 1.58 KB
/
init.lua
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
--- @sync entry
-- Toggle different views on/off: parent, current, preview
local function entry(st, job)
local args = job.args or job
local action = args[1]
if not action then
return
end
if st.view == nil then
st.old_parent = MANAGER.ratio.parent
st.old_current = MANAGER.ratio.current
st.old_preview = MANAGER.ratio.preview
-- Get current tab ratios
local all_old = st.old_parent + st.old_current + st.old_preview
local area = ui.Rect { x= 0, y = 0, w = all_old, h = 10 }
local tab = Tab:new(area, cx.active)
st.parent = tab._chunks[1].w
st.current = tab._chunks[2].w
st.preview = tab._chunks[3].w
st.layout = Tab.layout
st.view = true -- initialized
end
if action == "parent" then
if st.parent > 0 then
st.parent = 0
else
st.parent = st.old_parent
end
elseif action == "current" then
if st.current > 0 then
st.current = 0
else
st.current = st.old_current
end
elseif action == "preview" then
if st.preview > 0 then
st.preview = 0
else
st.preview = st.old_preview
end
else
return
end
Tab.layout = function(self)
local all = st.parent + st.current + st.preview
self._chunks = ui.Layout()
:direction(ui.Layout.HORIZONTAL)
:constraints({
ui.Constraint.Ratio(st.parent, all),
ui.Constraint.Ratio(st.current, all),
ui.Constraint.Ratio(st.preview, all),
})
:split(self._area)
end
ya.app_emit("resize", {})
end
local function enabled(st) return st.view ~= nil end
return { entry = entry, enabled = enabled }