Implement proper layout of toolbar
This commit is contained in:
parent
5851a04098
commit
b836c2e1e6
|
@ -401,12 +401,8 @@ function core.init()
|
||||||
|
|
||||||
local cur_node = core.root_view.root_node
|
local cur_node = core.root_view.root_node
|
||||||
cur_node.is_primary_node = true
|
cur_node.is_primary_node = true
|
||||||
cur_node = cur_node:split("down", core.command_view, true)
|
cur_node = cur_node:split("down", core.command_view, {y = true})
|
||||||
local got_toolbar, ToolbarView = core.try(require, "plugins.toolbarview")
|
cur_node = cur_node:split("down", core.status_view, {y = true})
|
||||||
if got_toolbar then
|
|
||||||
cur_node = cur_node:split("up", ToolbarView(), true)
|
|
||||||
end
|
|
||||||
cur_node = cur_node:split("down", core.status_view, true)
|
|
||||||
|
|
||||||
core.project_scan_thread_id = core.add_thread(project_scan_thread)
|
core.project_scan_thread_id = core.add_thread(project_scan_thread)
|
||||||
command.add_defaults()
|
command.add_defaults()
|
||||||
|
|
|
@ -93,6 +93,7 @@ end
|
||||||
local type_map = { up="vsplit", down="vsplit", left="hsplit", right="hsplit" }
|
local type_map = { up="vsplit", down="vsplit", left="hsplit", right="hsplit" }
|
||||||
|
|
||||||
function Node:split(dir, view, locked, resizable)
|
function Node:split(dir, view, locked, resizable)
|
||||||
|
assert(type(locked) == 'table')
|
||||||
assert(self.type == "leaf", "Tried to split non-leaf node")
|
assert(self.type == "leaf", "Tried to split non-leaf node")
|
||||||
local type = assert(type_map[dir], "Invalid direction")
|
local type = assert(type_map[dir], "Invalid direction")
|
||||||
local last_active = core.active_view
|
local last_active = core.active_view
|
||||||
|
@ -255,20 +256,36 @@ function Node:get_divider_rect()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-- 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.
|
||||||
function Node:get_locked_size()
|
function Node:get_locked_size()
|
||||||
if self.type == "leaf" then
|
if self.type == "leaf" then
|
||||||
if self.locked then
|
if self.locked then
|
||||||
local size = self.active_view.size
|
local size = self.active_view.size
|
||||||
return size.x, size.y
|
-- 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
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
local x1, y1 = self.a:get_locked_size()
|
local x1, y1 = self.a:get_locked_size()
|
||||||
local x2, y2 = self.b:get_locked_size()
|
local x2, y2 = self.b:get_locked_size()
|
||||||
if x1 and x2 then
|
-- The values below should be either a falsy value or a number
|
||||||
local dsx = (x1 < 1 or x2 < 1) and 0 or style.divider_size
|
local sx, sy
|
||||||
local dsy = (y1 < 1 or y2 < 1) and 0 or style.divider_size
|
if self.type == 'hsplit' then
|
||||||
return x1 + x2 + dsx, y1 + y2 + dsy
|
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
|
||||||
end
|
end
|
||||||
|
return sx, sy
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -281,9 +298,9 @@ end
|
||||||
|
|
||||||
-- calculating the sizes is the same for hsplits and vsplits, except the x/y
|
-- 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
|
-- axis are swapped; this function lets us use the same code for both
|
||||||
local function calc_split_sizes(self, x, y, x1, x2)
|
local function calc_split_sizes(self, x, y, x1, x2, y1, y2)
|
||||||
local n
|
local n
|
||||||
local ds = (x1 and x1 < 1 or x2 and x2 < 1) and 0 or style.divider_size
|
local ds = ((x1 and x1 < 1) or (x2 and x2 < 1)) and 0 or style.divider_size
|
||||||
if x1 then
|
if x1 then
|
||||||
n = x1 + ds
|
n = x1 + ds
|
||||||
elseif x2 then
|
elseif x2 then
|
||||||
|
@ -421,17 +438,36 @@ function Node:close_all_docviews()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function Node:is_resizable()
|
function Node:is_resizable(axis)
|
||||||
if self.type == 'leaf' then
|
if self.type == 'leaf' then
|
||||||
return not self.locked or self.resizable
|
return not self.locked or not self.locked[axis] or self.resizable
|
||||||
else
|
else
|
||||||
local a_resizable = self.a:is_resizable()
|
local a_resizable = self.a:is_resizable(axis)
|
||||||
local b_resizable = self.b:is_resizable()
|
local b_resizable = self.b:is_resizable(axis)
|
||||||
return a_resizable and b_resizable
|
return a_resizable and b_resizable
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function Node:resize(axis, value)
|
||||||
|
if self.type == 'leaf' then
|
||||||
|
-- FIXME: repeated logic with Node:is_resizable()
|
||||||
|
if not self.locked or not self.locked[axis] or self.resizable then
|
||||||
|
local view = self.active_view
|
||||||
|
view.size[axis] = value
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
else
|
||||||
|
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
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
local RootView = View:extend()
|
local RootView = View:extend()
|
||||||
|
|
||||||
function RootView:new()
|
function RootView:new()
|
||||||
|
@ -529,13 +565,8 @@ end
|
||||||
|
|
||||||
|
|
||||||
local function resize_child_node(node, axis, value, delta)
|
local function resize_child_node(node, axis, value, delta)
|
||||||
if node.a.resizable then
|
local accept_resize = node.a:resize(axis, value) or node.b:resize(axis, node.size[axis] - value)
|
||||||
local view = node.a.active_view
|
if not accept_resize then
|
||||||
view.size[axis] = value
|
|
||||||
elseif node.b.resizable then
|
|
||||||
local view = node.b.active_view
|
|
||||||
view.size[axis] = node.size[axis] - value
|
|
||||||
else
|
|
||||||
node.divider = node.divider + delta / node.size[axis]
|
node.divider = node.divider + delta / node.size[axis]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -559,7 +590,8 @@ function RootView:on_mouse_moved(x, y, dx, dy)
|
||||||
local node = self.root_node:get_child_overlapping_point(x, y)
|
local node = self.root_node:get_child_overlapping_point(x, y)
|
||||||
local div = self.root_node:get_divider_overlapping_point(x, y)
|
local div = self.root_node:get_divider_overlapping_point(x, y)
|
||||||
if div then
|
if div then
|
||||||
if div.a:is_resizable() and div.b:is_resizable() then
|
local axis = (div.type == "hsplit" and "x" or "y")
|
||||||
|
if div.a:is_resizable(axis) and div.b:is_resizable(axis) then
|
||||||
system.set_cursor(div.type == "hsplit" and "sizeh" or "sizev")
|
system.set_cursor(div.type == "hsplit" and "sizeh" or "sizev")
|
||||||
end
|
end
|
||||||
elseif node:get_tab_overlapping_point(x, y) then
|
elseif node:get_tab_overlapping_point(x, y) then
|
||||||
|
|
|
@ -74,12 +74,6 @@ function ToolbarView:on_mouse_moved(px, py, ...)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- init
|
|
||||||
if false then
|
|
||||||
local view = ToolbarView()
|
|
||||||
local node = core.root_view:get_active_node()
|
|
||||||
node:split("up", view, true)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- register commands and keymap
|
-- register commands and keymap
|
||||||
--[[command.add(nil, {
|
--[[command.add(nil, {
|
||||||
|
|
|
@ -188,6 +188,9 @@ function TreeView:update()
|
||||||
if self.init_size then
|
if self.init_size then
|
||||||
self.size.x = dest
|
self.size.x = dest
|
||||||
self.init_size = false
|
self.init_size = false
|
||||||
|
-- FIXME: bring back the visibility toggle and animation
|
||||||
|
-- else
|
||||||
|
-- self:move_towards(self.size, "x", dest)
|
||||||
end
|
end
|
||||||
|
|
||||||
TreeView.super.update(self)
|
TreeView.super.update(self)
|
||||||
|
@ -249,7 +252,12 @@ end
|
||||||
-- init
|
-- init
|
||||||
local view = TreeView()
|
local view = TreeView()
|
||||||
local node = core.root_view:get_active_node()
|
local node = core.root_view:get_active_node()
|
||||||
local treeview_node = node:split("left", view, true, true)
|
local treeview_node = node:split("left", view, {x = true}, true)
|
||||||
|
|
||||||
|
local toolbar_plugin, ToolbarView = core.try(require, "plugins.toolbarview")
|
||||||
|
if toolbar_plugin then
|
||||||
|
treeview_node:split("down", ToolbarView(), {y = true})
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
-- register commands and keymap
|
-- register commands and keymap
|
||||||
|
|
Loading…
Reference in New Issue