2019-12-28 12:16:32 +01:00
|
|
|
local core = require "core"
|
|
|
|
local common = require "core.common"
|
2021-05-16 15:50:27 +02:00
|
|
|
local config = require "core.config"
|
2019-12-28 12:16:32 +01:00
|
|
|
local style = require "core.style"
|
|
|
|
local keymap = require "core.keymap"
|
|
|
|
local Object = require "core.object"
|
|
|
|
local View = require "core.view"
|
2020-12-06 00:57:27 +01:00
|
|
|
local CommandView = require "core.commandview"
|
2021-03-13 12:57:52 +01:00
|
|
|
local NagView = require "core.nagview"
|
2019-12-28 12:16:32 +01:00
|
|
|
local DocView = require "core.docview"
|
|
|
|
|
|
|
|
|
|
|
|
local EmptyView = View:extend()
|
|
|
|
|
2020-05-30 15:53:01 +02:00
|
|
|
local function draw_text(x, y, color)
|
|
|
|
local th = style.big_font:get_height()
|
2020-12-30 16:15:57 +01:00
|
|
|
local dh = 2 * th + style.padding.y * 2
|
|
|
|
local x1, y1 = x, y + (dh - th) / 2
|
|
|
|
x = renderer.draw_text(style.big_font, "Lite XL", x1, y1, color)
|
|
|
|
renderer.draw_text(style.font, "version " .. VERSION, x1, y1 + th, color)
|
2020-05-30 15:53:01 +02:00
|
|
|
x = x + style.padding.x
|
|
|
|
renderer.draw_rect(x, y, math.ceil(1 * SCALE), dh, color)
|
2019-12-28 12:16:32 +01:00
|
|
|
local lines = {
|
2020-05-30 10:11:42 +02:00
|
|
|
{ fmt = "%s to run a command", cmd = "core:find-command" },
|
|
|
|
{ fmt = "%s to open a file from the project", cmd = "core:find-file" },
|
2020-12-10 17:56:53 +01:00
|
|
|
{ fmt = "%s to change project folder", cmd = "core:change-project-folder" },
|
|
|
|
{ fmt = "%s to open a project folder", cmd = "core:open-project-folder" },
|
2019-12-28 12:16:32 +01:00
|
|
|
}
|
2020-05-30 15:53:01 +02:00
|
|
|
th = style.font:get_height()
|
2020-12-08 23:36:50 +01:00
|
|
|
y = y + (dh - (th + style.padding.y) * #lines) / 2
|
2020-05-30 15:53:01 +02:00
|
|
|
local w = 0
|
2019-12-28 12:16:32 +01:00
|
|
|
for _, line in ipairs(lines) do
|
|
|
|
local text = string.format(line.fmt, keymap.get_binding(line.cmd))
|
2020-05-30 15:53:01 +02:00
|
|
|
w = math.max(w, renderer.draw_text(style.font, text, x + style.padding.x, y, color))
|
|
|
|
y = y + th + style.padding.y
|
2019-12-28 12:16:32 +01:00
|
|
|
end
|
2020-05-30 15:53:01 +02:00
|
|
|
return w, dh
|
|
|
|
end
|
|
|
|
|
|
|
|
function EmptyView:draw()
|
|
|
|
self:draw_background(style.background)
|
|
|
|
local w, h = draw_text(0, 0, { 0, 0, 0, 0 })
|
|
|
|
local x = self.position.x + math.max(style.padding.x, (self.size.x - w) / 2)
|
|
|
|
local y = self.position.y + (self.size.y - h) / 2
|
|
|
|
draw_text(x, y, style.dim)
|
2019-12-28 12:16:32 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
local Node = Object:extend()
|
|
|
|
|
|
|
|
function Node:new(type)
|
|
|
|
self.type = type or "leaf"
|
|
|
|
self.position = { x = 0, y = 0 }
|
|
|
|
self.size = { x = 0, y = 0 }
|
|
|
|
self.views = {}
|
|
|
|
self.divider = 0.5
|
|
|
|
if self.type == "leaf" then
|
|
|
|
self:add_view(EmptyView())
|
|
|
|
end
|
2021-05-15 16:57:20 +02:00
|
|
|
self.hovered = {x = -1, y = -1 }
|
2021-02-27 15:29:18 +01:00
|
|
|
self.hovered_close = 0
|
2021-05-16 15:50:27 +02:00
|
|
|
self.tab_shift = 0
|
|
|
|
self.tab_offset = 1
|
|
|
|
self.tab_width = style.tab_width
|
2021-05-15 16:57:20 +02:00
|
|
|
self.move_towards = View.move_towards
|
2019-12-28 12:16:32 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function Node:propagate(fn, ...)
|
|
|
|
self.a[fn](self.a, ...)
|
|
|
|
self.b[fn](self.b, ...)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function Node:on_mouse_moved(x, y, ...)
|
|
|
|
if self.type == "leaf" then
|
2021-05-15 16:57:20 +02:00
|
|
|
self.hovered.x, self.hovered.y = x, y
|
2019-12-28 12:16:32 +01:00
|
|
|
self.active_view:on_mouse_moved(x, y, ...)
|
|
|
|
else
|
|
|
|
self:propagate("on_mouse_moved", x, y, ...)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function Node:on_mouse_released(...)
|
|
|
|
if self.type == "leaf" then
|
|
|
|
self.active_view:on_mouse_released(...)
|
|
|
|
else
|
|
|
|
self:propagate("on_mouse_released", ...)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function Node:consume(node)
|
|
|
|
for k, _ in pairs(self) do self[k] = nil end
|
|
|
|
for k, v in pairs(node) do self[k] = v end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
local type_map = { up="vsplit", down="vsplit", left="hsplit", right="hsplit" }
|
|
|
|
|
2021-02-15 12:18:43 +01:00
|
|
|
-- The "locked" argument below should be in the form {x = <boolean>, y = <boolean>}
|
|
|
|
-- and it indicates if the node want to have a fixed size along the axis where the
|
|
|
|
-- boolean is true. If not it will be expanded to take all the available space.
|
|
|
|
-- The "resizable" flag indicates if, along the "locked" axis the node can be resized
|
2021-02-27 12:13:11 +01:00
|
|
|
-- by the user. If the node is marked as resizable their view should provide a
|
|
|
|
-- set_target_size method.
|
2021-02-11 16:12:21 +01:00
|
|
|
function Node:split(dir, view, locked, resizable)
|
2020-05-19 13:58:41 +02:00
|
|
|
assert(self.type == "leaf", "Tried to split non-leaf node")
|
2021-02-15 12:18:43 +01:00
|
|
|
local node_type = assert(type_map[dir], "Invalid direction")
|
2020-05-19 13:58:41 +02:00
|
|
|
local last_active = core.active_view
|
2019-12-28 12:16:32 +01:00
|
|
|
local child = Node()
|
|
|
|
child:consume(self)
|
2021-02-15 12:18:43 +01:00
|
|
|
self:consume(Node(node_type))
|
2019-12-28 12:16:32 +01:00
|
|
|
self.a = child
|
|
|
|
self.b = Node()
|
|
|
|
if view then self.b:add_view(view) end
|
2020-05-19 13:58:41 +02:00
|
|
|
if locked then
|
2021-02-15 12:18:43 +01:00
|
|
|
assert(type(locked) == 'table')
|
2020-05-19 13:58:41 +02:00
|
|
|
self.b.locked = locked
|
2021-02-11 16:12:21 +01:00
|
|
|
self.b.resizable = resizable or false
|
2020-05-19 13:58:41 +02:00
|
|
|
core.set_active_view(last_active)
|
2019-12-28 12:16:32 +01:00
|
|
|
end
|
|
|
|
if dir == "up" or dir == "left" then
|
|
|
|
self.a, self.b = self.b, self.a
|
2021-02-09 18:41:32 +01:00
|
|
|
return self.a
|
2019-12-28 12:16:32 +01:00
|
|
|
end
|
2021-02-09 18:41:32 +01:00
|
|
|
return self.b
|
2019-12-28 12:16:32 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2021-02-27 23:55:36 +01:00
|
|
|
function Node:close_view(root, view)
|
|
|
|
local new_active_view = view == self.active_view
|
2019-12-28 12:16:32 +01:00
|
|
|
local do_close = function()
|
|
|
|
if #self.views > 1 then
|
2021-02-27 23:55:36 +01:00
|
|
|
local idx = self:get_view_idx(view)
|
2019-12-28 12:16:32 +01:00
|
|
|
table.remove(self.views, idx)
|
2021-02-27 23:55:36 +01:00
|
|
|
if new_active_view then
|
|
|
|
self:set_active_view(self.views[idx] or self.views[#self.views])
|
|
|
|
end
|
2019-12-28 12:16:32 +01:00
|
|
|
else
|
|
|
|
local parent = self:get_parent_node(root)
|
2020-04-12 12:14:49 +02:00
|
|
|
local is_a = (parent.a == self)
|
|
|
|
local other = parent[is_a and "b" or "a"]
|
2019-12-28 12:16:32 +01:00
|
|
|
if other:get_locked_size() then
|
|
|
|
self.views = {}
|
|
|
|
self:add_view(EmptyView())
|
|
|
|
else
|
|
|
|
parent:consume(other)
|
2020-04-12 12:14:49 +02:00
|
|
|
local p = parent
|
|
|
|
while p.type ~= "leaf" do
|
|
|
|
p = p[is_a and "a" or "b"]
|
|
|
|
end
|
|
|
|
p:set_active_view(p.active_view)
|
2020-12-15 13:30:49 +01:00
|
|
|
if self.is_primary_node then
|
|
|
|
p.is_primary_node = true
|
|
|
|
end
|
2019-12-28 12:16:32 +01:00
|
|
|
end
|
|
|
|
end
|
2020-05-19 13:58:41 +02:00
|
|
|
core.last_active_view = nil
|
2019-12-28 12:16:32 +01:00
|
|
|
end
|
2021-02-27 23:55:36 +01:00
|
|
|
view:try_close(do_close)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function Node:close_active_view(root)
|
|
|
|
self:close_view(root, self.active_view)
|
2019-12-28 12:16:32 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function Node:add_view(view)
|
2020-05-19 13:58:41 +02:00
|
|
|
assert(self.type == "leaf", "Tried to add view to non-leaf node")
|
|
|
|
assert(not self.locked, "Tried to add view to locked node")
|
2019-12-28 12:16:32 +01:00
|
|
|
if self.views[1] and self.views[1]:is(EmptyView) then
|
|
|
|
table.remove(self.views)
|
|
|
|
end
|
|
|
|
table.insert(self.views, view)
|
|
|
|
self:set_active_view(view)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function Node:set_active_view(view)
|
2020-05-19 13:58:41 +02:00
|
|
|
assert(self.type == "leaf", "Tried to set active view on non-leaf node")
|
2019-12-28 12:16:32 +01:00
|
|
|
self.active_view = view
|
2020-05-19 13:58:41 +02:00
|
|
|
core.set_active_view(view)
|
2019-12-28 12:16:32 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function Node:get_view_idx(view)
|
|
|
|
for i, v in ipairs(self.views) do
|
|
|
|
if v == view then return i end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function Node:get_node_for_view(view)
|
|
|
|
for _, v in ipairs(self.views) do
|
|
|
|
if v == view then return self end
|
|
|
|
end
|
|
|
|
if self.type ~= "leaf" then
|
|
|
|
return self.a:get_node_for_view(view) or self.b:get_node_for_view(view)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function Node:get_parent_node(root)
|
|
|
|
if root.a == self or root.b == self then
|
|
|
|
return root
|
|
|
|
elseif root.type ~= "leaf" then
|
|
|
|
return self:get_parent_node(root.a) or self:get_parent_node(root.b)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function Node:get_children(t)
|
|
|
|
t = t or {}
|
|
|
|
for _, view in ipairs(self.views) do
|
|
|
|
table.insert(t, view)
|
|
|
|
end
|
|
|
|
if self.a then self.a:get_children(t) end
|
|
|
|
if self.b then self.b:get_children(t) end
|
|
|
|
return t
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2021-05-17 12:14:01 +02:00
|
|
|
-- return the width including the padding space and separately
|
|
|
|
-- the padding space itself
|
|
|
|
local function get_scroll_button_width()
|
|
|
|
local w = style.icon_font:get_width(">")
|
|
|
|
local pad = w
|
|
|
|
return w + 2 * pad, pad
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2019-12-28 12:16:32 +01:00
|
|
|
function Node:get_divider_overlapping_point(px, py)
|
|
|
|
if self.type ~= "leaf" then
|
|
|
|
local p = 6
|
|
|
|
local x, y, w, h = self:get_divider_rect()
|
|
|
|
x, y = x - p, y - p
|
|
|
|
w, h = w + p * 2, h + p * 2
|
|
|
|
if px > x and py > y and px < x + w and py < y + h then
|
|
|
|
return self
|
|
|
|
end
|
|
|
|
return self.a:get_divider_overlapping_point(px, py)
|
|
|
|
or self.b:get_divider_overlapping_point(px, py)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2021-05-16 15:50:27 +02:00
|
|
|
function Node:get_visible_tabs_number()
|
|
|
|
return math.min(#self.views - self.tab_offset + 1, config.max_tabs)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2019-12-28 12:16:32 +01:00
|
|
|
function Node:get_tab_overlapping_point(px, py)
|
|
|
|
if #self.views == 1 then return nil end
|
2021-05-16 15:50:27 +02:00
|
|
|
local tabs_number = self:get_visible_tabs_number()
|
2021-05-17 12:14:01 +02:00
|
|
|
local x1, y1, w, h = self:get_tab_rect(self.tab_offset)
|
|
|
|
local x2, y2 = self:get_tab_rect(self.tab_offset + tabs_number)
|
|
|
|
if px >= x1 and py >= y1 and px < x2 and py < y1 + h then
|
|
|
|
return math.floor((px - x1) / w) + self.tab_offset
|
2019-12-28 12:16:32 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2021-02-27 17:19:47 +01:00
|
|
|
local function close_button_location(x, w)
|
2021-02-27 15:29:18 +01:00
|
|
|
local cw = style.icon_font:get_width("C")
|
|
|
|
local pad = style.padding.y
|
2021-02-27 17:19:47 +01:00
|
|
|
return x + w - pad - cw, cw, pad
|
2021-02-27 15:29:18 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2021-05-16 15:50:27 +02:00
|
|
|
function Node:get_scroll_button_index(px, py)
|
2021-05-28 15:35:46 +02:00
|
|
|
if #self.views == 1 then return end
|
2021-05-16 15:50:27 +02:00
|
|
|
for i = 1, 2 do
|
|
|
|
local x, y, w, h = self:get_scroll_button_rect(i)
|
|
|
|
if px >= x and px < x + w and py >= y and py < y + h then
|
|
|
|
return i
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2021-05-15 16:57:20 +02:00
|
|
|
function Node:tab_hovered_update(px, py)
|
2021-02-27 13:53:52 +01:00
|
|
|
local tab_index = self:get_tab_overlapping_point(px, py)
|
2021-05-15 16:57:20 +02:00
|
|
|
self.hovered_tab = tab_index
|
2021-05-16 15:50:27 +02:00
|
|
|
self.hovered_close = 0
|
2021-05-17 13:37:05 +02:00
|
|
|
self.hovered_scroll_button = 0
|
2021-02-27 15:29:18 +01:00
|
|
|
if tab_index then
|
2021-02-27 13:53:52 +01:00
|
|
|
local x, y, w, h = self:get_tab_rect(tab_index)
|
2021-02-27 17:19:47 +01:00
|
|
|
local cx, cw = close_button_location(x, w)
|
|
|
|
if px >= cx and px < cx + cw and py >= y and py < y + h then
|
2021-02-27 15:29:18 +01:00
|
|
|
self.hovered_close = tab_index
|
2021-05-16 15:50:27 +02:00
|
|
|
end
|
|
|
|
else
|
2021-05-17 13:37:05 +02:00
|
|
|
self.hovered_scroll_button = self:get_scroll_button_index(px, py) or 0
|
2021-02-27 13:53:52 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2019-12-28 12:16:32 +01:00
|
|
|
function Node:get_child_overlapping_point(x, y)
|
|
|
|
local child
|
|
|
|
if self.type == "leaf" then
|
|
|
|
return self
|
|
|
|
elseif self.type == "hsplit" then
|
|
|
|
child = (x < self.b.position.x) and self.a or self.b
|
|
|
|
elseif self.type == "vsplit" then
|
|
|
|
child = (y < self.b.position.y) and self.a or self.b
|
|
|
|
end
|
|
|
|
return child:get_child_overlapping_point(x, y)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2021-05-16 15:50:27 +02:00
|
|
|
function Node:get_scroll_button_rect(index)
|
2021-05-17 12:14:01 +02:00
|
|
|
local w, pad = get_scroll_button_width()
|
2021-05-16 15:50:27 +02:00
|
|
|
local h = style.font:get_height() + style.padding.y * 2
|
2021-05-17 12:14:01 +02:00
|
|
|
local x = self.position.x + (index == 1 and 0 or self.size.x - w)
|
|
|
|
return x, self.position.y, w, h, pad
|
2021-05-16 15:50:27 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2019-12-28 12:16:32 +01:00
|
|
|
function Node:get_tab_rect(idx)
|
2021-05-17 12:14:01 +02:00
|
|
|
local sbw = get_scroll_button_width()
|
2021-05-17 15:11:06 +02:00
|
|
|
local maxw = self.size.x - 2 * sbw
|
|
|
|
local x0 = self.position.x + sbw
|
|
|
|
local x1 = x0 + common.clamp(self.tab_width * (idx - 1) - self.tab_shift, 0, maxw)
|
|
|
|
local x2 = x0 + common.clamp(self.tab_width * idx - self.tab_shift, 0, maxw)
|
2019-12-28 12:16:32 +01:00
|
|
|
local h = style.font:get_height() + style.padding.y * 2
|
2021-05-17 15:11:06 +02:00
|
|
|
return x1, self.position.y, x2 - x1, h
|
2019-12-28 12:16:32 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function Node:get_divider_rect()
|
|
|
|
local x, y = self.position.x, self.position.y
|
|
|
|
if self.type == "hsplit" then
|
|
|
|
return x + self.a.size.x, y, style.divider_size, self.size.y
|
|
|
|
elseif self.type == "vsplit" then
|
|
|
|
return x, y + self.a.size.y, self.size.x, style.divider_size
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2021-02-15 00:36:39 +01:00
|
|
|
-- Return two values for x and y axis and each of them is either falsy or a number.
|
|
|
|
-- A falsy value indicate no fixed size along the corresponding direction.
|
2019-12-28 12:16:32 +01:00
|
|
|
function Node:get_locked_size()
|
|
|
|
if self.type == "leaf" then
|
|
|
|
if self.locked then
|
|
|
|
local size = self.active_view.size
|
2021-02-15 00:36:39 +01:00
|
|
|
-- The values below should be either a falsy value or a number
|
|
|
|
local sx = (self.locked and self.locked.x) and size.x
|
|
|
|
local sy = (self.locked and self.locked.y) and size.y
|
|
|
|
return sx, sy
|
2019-12-28 12:16:32 +01:00
|
|
|
end
|
|
|
|
else
|
|
|
|
local x1, y1 = self.a:get_locked_size()
|
|
|
|
local x2, y2 = self.b:get_locked_size()
|
2021-02-15 00:36:39 +01:00
|
|
|
-- The values below should be either a falsy value or a number
|
|
|
|
local sx, sy
|
|
|
|
if self.type == 'hsplit' then
|
|
|
|
if x1 and x2 then
|
|
|
|
local dsx = (x1 < 1 or x2 < 1) and 0 or style.divider_size
|
|
|
|
sx = x1 + x2 + dsx
|
|
|
|
end
|
|
|
|
sy = y1 or y2
|
|
|
|
else
|
|
|
|
if y1 and y2 then
|
|
|
|
local dsy = (y1 < 1 or y2 < 1) and 0 or style.divider_size
|
|
|
|
sy = y1 + y2 + dsy
|
|
|
|
end
|
|
|
|
sx = x1 or x2
|
2019-12-28 12:16:32 +01:00
|
|
|
end
|
2021-02-15 00:36:39 +01:00
|
|
|
return sx, sy
|
2019-12-28 12:16:32 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
local function copy_position_and_size(dst, src)
|
|
|
|
dst.position.x, dst.position.y = src.position.x, src.position.y
|
|
|
|
dst.size.x, dst.size.y = src.size.x, src.size.y
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
-- calculating the sizes is the same for hsplits and vsplits, except the x/y
|
|
|
|
-- axis are swapped; this function lets us use the same code for both
|
2021-02-15 00:36:39 +01:00
|
|
|
local function calc_split_sizes(self, x, y, x1, x2, y1, y2)
|
2019-12-28 12:16:32 +01:00
|
|
|
local n
|
2021-02-15 00:36:39 +01:00
|
|
|
local ds = ((x1 and x1 < 1) or (x2 and x2 < 1)) and 0 or style.divider_size
|
2019-12-28 12:16:32 +01:00
|
|
|
if x1 then
|
2020-05-01 17:15:28 +02:00
|
|
|
n = x1 + ds
|
2019-12-28 12:16:32 +01:00
|
|
|
elseif x2 then
|
2020-05-01 17:15:28 +02:00
|
|
|
n = self.size[x] - x2
|
2019-12-28 12:16:32 +01:00
|
|
|
else
|
|
|
|
n = math.floor(self.size[x] * self.divider)
|
|
|
|
end
|
|
|
|
self.a.position[x] = self.position[x]
|
|
|
|
self.a.position[y] = self.position[y]
|
|
|
|
self.a.size[x] = n - ds
|
|
|
|
self.a.size[y] = self.size[y]
|
|
|
|
self.b.position[x] = self.position[x] + n
|
|
|
|
self.b.position[y] = self.position[y]
|
|
|
|
self.b.size[x] = self.size[x] - n
|
|
|
|
self.b.size[y] = self.size[y]
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function Node:update_layout()
|
|
|
|
if self.type == "leaf" then
|
|
|
|
local av = self.active_view
|
|
|
|
if #self.views > 1 then
|
|
|
|
local _, _, _, th = self:get_tab_rect(1)
|
|
|
|
av.position.x, av.position.y = self.position.x, self.position.y + th
|
|
|
|
av.size.x, av.size.y = self.size.x, self.size.y - th
|
|
|
|
else
|
|
|
|
copy_position_and_size(av, self)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
local x1, y1 = self.a:get_locked_size()
|
|
|
|
local x2, y2 = self.b:get_locked_size()
|
|
|
|
if self.type == "hsplit" then
|
|
|
|
calc_split_sizes(self, "x", "y", x1, x2)
|
|
|
|
elseif self.type == "vsplit" then
|
|
|
|
calc_split_sizes(self, "y", "x", y1, y2)
|
|
|
|
end
|
|
|
|
self.a:update_layout()
|
|
|
|
self.b:update_layout()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2021-05-16 15:50:27 +02:00
|
|
|
function Node:scroll_tabs_to_visible()
|
|
|
|
local index = self:get_view_idx(self.active_view)
|
|
|
|
if index then
|
|
|
|
local tabs_number = self:get_visible_tabs_number()
|
|
|
|
if self.tab_offset > index then
|
|
|
|
self.tab_offset = index
|
|
|
|
elseif self.tab_offset + tabs_number - 1 < index then
|
|
|
|
self.tab_offset = index - tabs_number + 1
|
|
|
|
elseif tabs_number < config.max_tabs and self.tab_offset > 1 then
|
|
|
|
self.tab_offset = #self.views - config.max_tabs + 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function Node:scroll_tabs(dir)
|
|
|
|
local view_index = self:get_view_idx(self.active_view)
|
|
|
|
if dir == 1 then
|
|
|
|
if self.tab_offset > 1 then
|
|
|
|
self.tab_offset = self.tab_offset - 1
|
|
|
|
local last_index = self.tab_offset + self:get_visible_tabs_number() - 1
|
|
|
|
if view_index > last_index then
|
|
|
|
self:set_active_view(self.views[last_index])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
elseif dir == 2 then
|
|
|
|
local tabs_number = self:get_visible_tabs_number()
|
|
|
|
if self.tab_offset + tabs_number - 1 < #self.views then
|
|
|
|
self.tab_offset = self.tab_offset + 1
|
|
|
|
local view_index = self:get_view_idx(self.active_view)
|
|
|
|
if view_index < self.tab_offset then
|
|
|
|
self:set_active_view(self.views[self.tab_offset])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function Node:target_tab_width()
|
2021-05-19 10:09:40 +02:00
|
|
|
local n = self:get_visible_tabs_number()
|
|
|
|
local w = self.size.x - get_scroll_button_width() * 2
|
|
|
|
return common.clamp(style.tab_width, w / config.max_tabs, w / n)
|
2021-05-16 15:50:27 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2019-12-28 12:16:32 +01:00
|
|
|
function Node:update()
|
|
|
|
if self.type == "leaf" then
|
2021-05-16 15:50:27 +02:00
|
|
|
self:scroll_tabs_to_visible()
|
2019-12-28 12:16:32 +01:00
|
|
|
for _, view in ipairs(self.views) do
|
|
|
|
view:update()
|
|
|
|
end
|
2021-05-15 16:57:20 +02:00
|
|
|
self:tab_hovered_update(self.hovered.x, self.hovered.y)
|
2021-05-16 15:50:27 +02:00
|
|
|
local tab_width = self:target_tab_width()
|
|
|
|
self:move_towards("tab_shift", tab_width * (self.tab_offset - 1))
|
|
|
|
self:move_towards("tab_width", tab_width)
|
2019-12-28 12:16:32 +01:00
|
|
|
else
|
|
|
|
self.a:update()
|
|
|
|
self.b:update()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function Node:draw_tabs()
|
2021-05-16 15:50:27 +02:00
|
|
|
local x, y, w, h, scroll_padding = self:get_scroll_button_rect(1)
|
2019-12-28 12:16:32 +01:00
|
|
|
local ds = style.divider_size
|
2021-05-15 16:27:29 +02:00
|
|
|
local dots_width = style.font:get_width("…")
|
2019-12-28 12:16:32 +01:00
|
|
|
core.push_clip_rect(x, y, self.size.x, h)
|
|
|
|
renderer.draw_rect(x, y, self.size.x, h, style.background2)
|
|
|
|
renderer.draw_rect(x, y + h - ds, self.size.x, ds, style.divider)
|
|
|
|
|
2021-05-16 15:50:27 +02:00
|
|
|
if self.tab_offset > 1 then
|
2021-05-17 13:37:05 +02:00
|
|
|
local button_style = self.hovered_scroll_button == 1 and style.text or style.dim
|
2021-05-16 15:50:27 +02:00
|
|
|
common.draw_text(style.icon_font, button_style, "<", nil, x + scroll_padding, y, 0, h)
|
|
|
|
end
|
|
|
|
|
|
|
|
local tabs_number = self:get_visible_tabs_number()
|
|
|
|
if #self.views > self.tab_offset + tabs_number - 1 then
|
|
|
|
local xrb, yrb, wrb = self:get_scroll_button_rect(2)
|
2021-05-17 13:37:05 +02:00
|
|
|
local button_style = self.hovered_scroll_button == 2 and style.text or style.dim
|
2021-05-16 15:50:27 +02:00
|
|
|
common.draw_text(style.icon_font, button_style, ">", nil, xrb + scroll_padding, yrb, 0, h)
|
|
|
|
end
|
|
|
|
|
|
|
|
for i = self.tab_offset, self.tab_offset + tabs_number - 1 do
|
|
|
|
local view = self.views[i]
|
2019-12-28 12:16:32 +01:00
|
|
|
local x, y, w, h = self:get_tab_rect(i)
|
|
|
|
local text = view:get_name()
|
|
|
|
local color = style.dim
|
2021-03-09 14:24:14 +01:00
|
|
|
local padding_y = style.padding.y
|
|
|
|
renderer.draw_rect(x + w, y + padding_y, ds, h - padding_y * 2, style.dim)
|
2019-12-28 12:16:32 +01:00
|
|
|
if view == self.active_view then
|
|
|
|
color = style.text
|
|
|
|
renderer.draw_rect(x, y, w, h, style.background)
|
2021-03-09 14:24:14 +01:00
|
|
|
renderer.draw_rect(x + w, y, ds, h, style.divider)
|
|
|
|
renderer.draw_rect(x - ds, y, ds, h, style.divider)
|
2021-02-27 15:29:18 +01:00
|
|
|
end
|
2021-02-27 17:19:47 +01:00
|
|
|
local cx, cw, cspace = close_button_location(x, w)
|
2021-03-02 08:53:32 +01:00
|
|
|
local show_close_button = (view == self.active_view or i == self.hovered_tab)
|
|
|
|
if show_close_button then
|
2021-02-27 15:29:18 +01:00
|
|
|
local close_style = self.hovered_close == i and style.text or style.dim
|
2021-02-27 17:19:47 +01:00
|
|
|
common.draw_text(style.icon_font, close_style, "C", nil, cx, y, 0, h)
|
2019-12-28 12:16:32 +01:00
|
|
|
end
|
|
|
|
if i == self.hovered_tab then
|
|
|
|
color = style.text
|
|
|
|
end
|
2021-03-02 08:53:32 +01:00
|
|
|
local padx = style.padding.x
|
2021-05-15 16:27:29 +02:00
|
|
|
-- Normally we should substract "cspace" from text_avail_width and from the
|
|
|
|
-- clipping width. It is the padding space we give to the left and right of the
|
|
|
|
-- close button. However, since we are using dots to terminate filenames, we
|
|
|
|
-- choose to ignore "cspace" accepting that the text can possibly "touch" the
|
|
|
|
-- close button.
|
2021-05-15 14:49:16 +02:00
|
|
|
local text_avail_width = cx - x - padx
|
2021-05-15 16:27:29 +02:00
|
|
|
core.push_clip_rect(x, y, cx - x, h)
|
2021-03-02 08:53:32 +01:00
|
|
|
x, w = x + padx, w - padx * 2
|
2021-05-15 14:49:16 +02:00
|
|
|
local align = "center"
|
|
|
|
if style.font:get_width(text) > text_avail_width then
|
|
|
|
align = "left"
|
|
|
|
for i = 1, #text do
|
|
|
|
local reduced_text = text:sub(1, #text - i)
|
|
|
|
if style.font:get_width(reduced_text) + dots_width <= text_avail_width then
|
2021-05-15 16:27:29 +02:00
|
|
|
text = reduced_text .. "…"
|
2021-05-15 14:49:16 +02:00
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-06-03 14:34:10 +02:00
|
|
|
common.draw_text(style.font, color, text, align, x, y, w, h)
|
2019-12-28 12:16:32 +01:00
|
|
|
core.pop_clip_rect()
|
|
|
|
end
|
|
|
|
|
|
|
|
core.pop_clip_rect()
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function Node:draw()
|
|
|
|
if self.type == "leaf" then
|
|
|
|
if #self.views > 1 then
|
|
|
|
self:draw_tabs()
|
|
|
|
end
|
|
|
|
local pos, size = self.active_view.position, self.active_view.size
|
2020-05-01 17:15:28 +02:00
|
|
|
core.push_clip_rect(pos.x, pos.y, size.x + pos.x % 1, size.y + pos.y % 1)
|
2019-12-28 12:16:32 +01:00
|
|
|
self.active_view:draw()
|
|
|
|
core.pop_clip_rect()
|
|
|
|
else
|
|
|
|
local x, y, w, h = self:get_divider_rect()
|
|
|
|
renderer.draw_rect(x, y, w, h, style.divider)
|
|
|
|
self:propagate("draw")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2020-12-06 00:57:27 +01:00
|
|
|
function Node:is_empty()
|
|
|
|
if self.type == "leaf" then
|
|
|
|
return #self.views == 0
|
|
|
|
else
|
|
|
|
return self.a:is_empty() and self.b:is_empty()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function Node:close_all_docviews()
|
|
|
|
if self.type == "leaf" then
|
|
|
|
local i = 1
|
|
|
|
while i <= #self.views do
|
|
|
|
local view = self.views[i]
|
|
|
|
if view:is(DocView) and not view:is(CommandView) then
|
|
|
|
table.remove(self.views, i)
|
|
|
|
else
|
|
|
|
i = i + 1
|
|
|
|
end
|
|
|
|
end
|
2020-12-14 14:19:28 +01:00
|
|
|
if #self.views == 0 and self.is_primary_node then
|
2020-12-06 00:57:27 +01:00
|
|
|
self:add_view(EmptyView())
|
|
|
|
end
|
|
|
|
else
|
|
|
|
self.a:close_all_docviews()
|
|
|
|
self.b:close_all_docviews()
|
|
|
|
if self.a:is_empty() then
|
|
|
|
self:consume(self.b)
|
|
|
|
elseif self.b:is_empty() then
|
|
|
|
self:consume(self.a)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-05-06 15:35:40 +02:00
|
|
|
-- Returns true for nodes that accept either "proportional" resizes (based on the
|
|
|
|
-- node.divider) or "locked" resizable nodes (along the resize axis).
|
2021-02-15 00:36:39 +01:00
|
|
|
function Node:is_resizable(axis)
|
2021-02-11 17:15:27 +01:00
|
|
|
if self.type == 'leaf' then
|
2021-02-15 00:36:39 +01:00
|
|
|
return not self.locked or not self.locked[axis] or self.resizable
|
2021-02-11 17:15:27 +01:00
|
|
|
else
|
2021-02-15 00:36:39 +01:00
|
|
|
local a_resizable = self.a:is_resizable(axis)
|
|
|
|
local b_resizable = self.b:is_resizable(axis)
|
2021-02-11 17:15:27 +01:00
|
|
|
return a_resizable and b_resizable
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-12-28 12:16:32 +01:00
|
|
|
|
2021-05-06 15:35:40 +02:00
|
|
|
-- Return true iff it is a locked pane along the rezise axis and is
|
|
|
|
-- declared "resizable".
|
|
|
|
function Node:is_locked_resizable(axis)
|
|
|
|
return self.locked and self.locked[axis] and self.resizable
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2021-02-15 00:36:39 +01:00
|
|
|
function Node:resize(axis, value)
|
|
|
|
if self.type == 'leaf' then
|
2021-05-06 15:35:40 +02:00
|
|
|
-- If it is not locked we don't accept the
|
2021-02-15 12:18:43 +01:00
|
|
|
-- resize operation here because for proportional panes the resize is
|
|
|
|
-- done using the "divider" value of the parent node.
|
2021-05-06 15:35:40 +02:00
|
|
|
if self:is_locked_resizable(axis) then
|
2021-02-27 12:13:11 +01:00
|
|
|
return self.active_view:set_target_size(axis, value)
|
2021-02-15 00:36:39 +01:00
|
|
|
end
|
|
|
|
else
|
2021-05-06 15:35:40 +02:00
|
|
|
if self.type == (axis == "x" and "hsplit" or "vsplit") then
|
|
|
|
-- we are resizing a node that is splitted along the resize axis
|
|
|
|
if self.a:is_locked_resizable(axis) and self.b:is_locked_resizable(axis) then
|
|
|
|
local rem_value = value - self.a.size[axis]
|
|
|
|
if rem_value >= 0 then
|
|
|
|
return self.b.active_view:set_target_size(axis, rem_value)
|
|
|
|
else
|
|
|
|
self.b.active_view:set_target_size(axis, 0)
|
|
|
|
return self.a.active_view:set_target_size(axis, value)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
|
|
|
-- we are resizing a node that is splitted along the axis perpendicular
|
|
|
|
-- to the resize axis
|
|
|
|
local a_resizable = self.a:is_resizable(axis)
|
|
|
|
local b_resizable = self.b:is_resizable(axis)
|
|
|
|
if a_resizable and b_resizable then
|
|
|
|
self.a:resize(axis, value)
|
|
|
|
self.b:resize(axis, value)
|
|
|
|
end
|
2021-02-15 00:36:39 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2019-12-28 12:16:32 +01:00
|
|
|
local RootView = View:extend()
|
|
|
|
|
|
|
|
function RootView:new()
|
|
|
|
RootView.super.new(self)
|
|
|
|
self.root_node = Node()
|
|
|
|
self.deferred_draws = {}
|
|
|
|
self.mouse = { x = 0, y = 0 }
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function RootView:defer_draw(fn, ...)
|
|
|
|
table.insert(self.deferred_draws, 1, { fn = fn, ... })
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function RootView:get_active_node()
|
2020-05-19 13:58:41 +02:00
|
|
|
return self.root_node:get_node_for_view(core.active_view)
|
2019-12-28 12:16:32 +01:00
|
|
|
end
|
|
|
|
|
2020-12-28 23:35:52 +01:00
|
|
|
|
2020-12-14 14:19:28 +01:00
|
|
|
local function get_primary_node(node)
|
|
|
|
if node.is_primary_node then
|
2020-11-16 18:12:31 +01:00
|
|
|
return node
|
|
|
|
end
|
|
|
|
if node.type ~= "leaf" then
|
2020-12-14 14:19:28 +01:00
|
|
|
return get_primary_node(node.a) or get_primary_node(node.b)
|
2020-11-16 18:12:31 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-12-28 12:16:32 +01:00
|
|
|
|
2020-12-28 23:35:52 +01:00
|
|
|
function RootView:get_active_node_default()
|
|
|
|
local node = self.root_node:get_node_for_view(core.active_view)
|
2020-11-16 18:12:31 +01:00
|
|
|
if node.locked then
|
2020-12-14 14:19:28 +01:00
|
|
|
local default_view = self:get_primary_node().views[1]
|
2020-12-06 01:03:54 +01:00
|
|
|
assert(default_view, "internal error: cannot find original document node.")
|
2020-11-16 18:12:31 +01:00
|
|
|
core.set_active_view(default_view)
|
2020-05-22 16:43:47 +02:00
|
|
|
node = self:get_active_node()
|
|
|
|
end
|
2020-12-28 23:35:52 +01:00
|
|
|
return node
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function RootView:get_primary_node()
|
|
|
|
return get_primary_node(self.root_node)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function RootView:open_doc(doc)
|
|
|
|
local node = self:get_active_node_default()
|
2019-12-28 12:16:32 +01:00
|
|
|
for i, view in ipairs(node.views) do
|
|
|
|
if view.doc == doc then
|
|
|
|
node:set_active_view(node.views[i])
|
|
|
|
return view
|
|
|
|
end
|
|
|
|
end
|
|
|
|
local view = DocView(doc)
|
|
|
|
node:add_view(view)
|
|
|
|
self.root_node:update_layout()
|
|
|
|
view:scroll_to_line(view.doc:get_selection(), true, true)
|
|
|
|
return view
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2020-12-06 00:57:27 +01:00
|
|
|
function RootView:close_all_docviews()
|
|
|
|
self.root_node:close_all_docviews()
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2019-12-28 12:16:32 +01:00
|
|
|
function RootView:on_mouse_pressed(button, x, y, clicks)
|
|
|
|
local div = self.root_node:get_divider_overlapping_point(x, y)
|
|
|
|
if div then
|
|
|
|
self.dragged_divider = div
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local node = self.root_node:get_child_overlapping_point(x, y)
|
2021-05-17 13:37:05 +02:00
|
|
|
if node.hovered_scroll_button > 0 then
|
|
|
|
node:scroll_tabs(node.hovered_scroll_button)
|
2021-05-16 15:50:27 +02:00
|
|
|
return
|
|
|
|
end
|
2019-12-28 12:16:32 +01:00
|
|
|
local idx = node:get_tab_overlapping_point(x, y)
|
|
|
|
if idx then
|
2021-02-27 15:29:18 +01:00
|
|
|
if button == "middle" or node.hovered_close == idx then
|
2021-02-27 23:55:36 +01:00
|
|
|
node:close_view(self.root_node, node.views[idx])
|
|
|
|
else
|
2021-05-02 09:13:21 +02:00
|
|
|
self.dragged_node = idx
|
2021-02-27 23:55:36 +01:00
|
|
|
node:set_active_view(node.views[idx])
|
2019-12-28 12:16:32 +01:00
|
|
|
end
|
|
|
|
else
|
2020-05-19 13:58:41 +02:00
|
|
|
core.set_active_view(node.active_view)
|
2019-12-28 12:16:32 +01:00
|
|
|
node.active_view:on_mouse_pressed(button, x, y, clicks)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function RootView:on_mouse_released(...)
|
|
|
|
if self.dragged_divider then
|
|
|
|
self.dragged_divider = nil
|
|
|
|
end
|
2021-05-02 09:13:21 +02:00
|
|
|
if self.dragged_node then
|
|
|
|
self.dragged_node = nil
|
|
|
|
end
|
2019-12-28 12:16:32 +01:00
|
|
|
self.root_node:on_mouse_released(...)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2021-02-11 11:53:53 +01:00
|
|
|
local function resize_child_node(node, axis, value, delta)
|
2021-05-06 15:35:40 +02:00
|
|
|
local accept_resize = node.a:resize(axis, value)
|
|
|
|
if not accept_resize then
|
|
|
|
accept_resize = node.b:resize(axis, node.size[axis] - value)
|
|
|
|
end
|
2021-02-15 00:36:39 +01:00
|
|
|
if not accept_resize then
|
2021-02-11 11:53:53 +01:00
|
|
|
node.divider = node.divider + delta / node.size[axis]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2019-12-28 12:16:32 +01:00
|
|
|
function RootView:on_mouse_moved(x, y, dx, dy)
|
2021-03-13 12:57:52 +01:00
|
|
|
if core.active_view == core.nag_view then
|
2021-06-03 22:49:37 +02:00
|
|
|
core.request_cursor("arrow")
|
2021-03-13 12:57:52 +01:00
|
|
|
core.active_view:on_mouse_moved(x, y, dx, dy)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2019-12-28 12:16:32 +01:00
|
|
|
if self.dragged_divider then
|
2020-05-23 10:40:42 +02:00
|
|
|
local node = self.dragged_divider
|
|
|
|
if node.type == "hsplit" then
|
2021-02-20 20:13:25 +01:00
|
|
|
x = common.clamp(x, 0, self.root_node.size.x * 0.95)
|
2021-02-11 11:53:53 +01:00
|
|
|
resize_child_node(node, "x", x, dx)
|
|
|
|
elseif node.type == "vsplit" then
|
2021-03-06 23:05:04 +01:00
|
|
|
y = common.clamp(y, 0, self.root_node.size.y * 0.95)
|
2021-02-11 11:53:53 +01:00
|
|
|
resize_child_node(node, "y", y, dy)
|
2019-12-28 12:16:32 +01:00
|
|
|
end
|
2020-05-23 10:40:42 +02:00
|
|
|
node.divider = common.clamp(node.divider, 0.01, 0.99)
|
2019-12-28 12:16:32 +01:00
|
|
|
return
|
|
|
|
end
|
2021-05-06 15:35:40 +02:00
|
|
|
|
2019-12-28 12:16:32 +01:00
|
|
|
self.mouse.x, self.mouse.y = x, y
|
|
|
|
self.root_node:on_mouse_moved(x, y, dx, dy)
|
|
|
|
|
|
|
|
local node = self.root_node:get_child_overlapping_point(x, y)
|
|
|
|
local div = self.root_node:get_divider_overlapping_point(x, y)
|
2021-05-02 09:13:21 +02:00
|
|
|
local tab_index = node and node:get_tab_overlapping_point(x, y)
|
2021-05-16 15:50:27 +02:00
|
|
|
if node and node:get_scroll_button_index(x, y) then
|
2021-06-03 22:49:37 +02:00
|
|
|
core.request_cursor("arrow")
|
2021-05-16 15:50:27 +02:00
|
|
|
elseif div then
|
2021-02-15 00:36:39 +01:00
|
|
|
local axis = (div.type == "hsplit" and "x" or "y")
|
|
|
|
if div.a:is_resizable(axis) and div.b:is_resizable(axis) then
|
2021-06-03 22:49:37 +02:00
|
|
|
core.request_cursor(div.type == "hsplit" and "sizeh" or "sizev")
|
2021-02-11 11:53:53 +01:00
|
|
|
end
|
2021-05-02 09:13:21 +02:00
|
|
|
elseif tab_index then
|
2021-06-03 22:49:37 +02:00
|
|
|
core.request_cursor("arrow")
|
2021-05-02 09:13:21 +02:00
|
|
|
if self.dragged_node and self.dragged_node ~= tab_index then
|
|
|
|
local tab = node.views[self.dragged_node]
|
|
|
|
table.remove(node.views, self.dragged_node)
|
|
|
|
table.insert(node.views, tab_index, tab)
|
|
|
|
self.dragged_node = tab_index
|
|
|
|
end
|
2019-12-28 12:16:32 +01:00
|
|
|
else
|
2021-06-03 22:49:37 +02:00
|
|
|
core.request_cursor(node.active_view.cursor)
|
2019-12-28 12:16:32 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function RootView:on_mouse_wheel(...)
|
|
|
|
local x, y = self.mouse.x, self.mouse.y
|
|
|
|
local node = self.root_node:get_child_overlapping_point(x, y)
|
|
|
|
node.active_view:on_mouse_wheel(...)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function RootView:on_text_input(...)
|
|
|
|
core.active_view:on_text_input(...)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2020-11-21 16:36:13 +01:00
|
|
|
function RootView:on_focus_lost(...)
|
|
|
|
-- We force a redraw so documents can redraw without the cursor.
|
|
|
|
core.redraw = true
|
|
|
|
end
|
|
|
|
|
2019-12-28 12:16:32 +01:00
|
|
|
function RootView:update()
|
|
|
|
copy_position_and_size(self.root_node, self)
|
|
|
|
self.root_node:update()
|
|
|
|
self.root_node:update_layout()
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function RootView:draw()
|
|
|
|
self.root_node:draw()
|
|
|
|
while #self.deferred_draws > 0 do
|
|
|
|
local t = table.remove(self.deferred_draws)
|
|
|
|
t.fn(table.unpack(t))
|
|
|
|
end
|
2021-06-03 22:49:37 +02:00
|
|
|
if core.cursor_change_req then
|
|
|
|
system.set_cursor(core.cursor_change_req)
|
|
|
|
core.cursor_change_req = nil
|
|
|
|
end
|
2019-12-28 12:16:32 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
return RootView
|