added horizontal scroll

added the ability to scroll gorizontally, in two ways:
	- with a touchpad
	- holding "alt" and scrolling
also made the scroll senitivity configurable for both directions
master
Alessandro Mauri 3 years ago
parent a7df717cf0
commit a5e90420e8
  1. 4
      TODO
  2. 3
      data/core/config.lua
  3. 4
      data/core/rootview.lua
  4. 17
      data/core/view.lua
  5. 23
      src/api/system.c

@ -16,7 +16,7 @@
[ ] that command can be what is selected
[ ] console: accept input
[ ] doc: detect file changes with hash
[ ] add horizontal scroll
[x] add horizontal scroll
[ ] add a cross to close tab
[ ] add context menu to various things
[ ] document and selection context menu
@ -55,3 +55,5 @@
[ ] show hidden files config and binding
[ ] syntax: highlight FIXME TODO BUG FIX and IMPROVEMENT keywords
[ ] do not open doc in new tab if current tab has an unchanged document
[ ] doc: add auto close brackets and quotes
[ ] view: implement get_scrollable_size()

@ -4,7 +4,8 @@ config.project_scan_rate = 5
config.fps = 60
config.max_log_items = 80
config.message_timeout = 3
config.mouse_wheel_scroll = 50 * SCALE
config.mouse_wheel_scroll_y = 50 * SCALE
config.mouse_wheel_scroll_x = 30 * SCALE
config.file_size_limit = 10
config.ignore_files = "^%."
config.symbol_pattern = "[%a_][%w_]*"

@ -473,10 +473,10 @@ function RootView:on_mouse_moved(x, y, dx, dy)
end
function RootView:on_mouse_wheel(...)
function RootView:on_mouse_wheel(dy, dx)
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(...)
node.active_view:on_mouse_wheel(dy, dx)
end

@ -3,6 +3,7 @@ local config = require "core.config"
local style = require "core.style"
local common = require "core.common"
local Object = require "core.object"
local keymap = require "core.keymap"
local View = Object:extend()
@ -44,6 +45,7 @@ function View:get_name()
end
-- TODO: implement this
function View:get_scrollable_size()
return math.huge
end
@ -96,9 +98,14 @@ function View:on_text_input(text)
end
function View:on_mouse_wheel(y)
function View:on_mouse_wheel(y, x)
if self.scrollable then
self.scroll.to.y = self.scroll.to.y + y * -config.mouse_wheel_scroll
if keymap.modkeys['alt'] then
self.scroll.to.x = self.scroll.to.x + y * -config.mouse_wheel_scroll_x
else
self.scroll.to.y = self.scroll.to.y + y * -config.mouse_wheel_scroll_y
self.scroll.to.x = self.scroll.to.x + x * -config.mouse_wheel_scroll_x
end
end
end
@ -118,8 +125,10 @@ end
function View:clamp_scroll_position()
local max = self:get_scrollable_size() - self.size.y
self.scroll.to.y = common.clamp(self.scroll.to.y, 0, max)
local max_y = self:get_scrollable_size() - self.size.y
local max_x = self:get_scrollable_size() - self.size.x
self.scroll.to.y = common.clamp(self.scroll.to.y, 0, max_y)
self.scroll.to.x = common.clamp(self.scroll.to.x, 0, max_x)
end

@ -94,7 +94,7 @@ top:
return 2;
case SDL_MOUSEBUTTONDOWN:
if (e.button.button == 1)
if (e.button.button == 1)
SDL_CaptureMouse(1);
lua_pushstring(L, "mousepressed");
lua_pushstring(L, button_name(e.button.button));
@ -104,7 +104,7 @@ top:
return 5;
case SDL_MOUSEBUTTONUP:
if (e.button.button == 1)
if (e.button.button == 1)
SDL_CaptureMouse(0);
lua_pushstring(L, "mousereleased");
lua_pushstring(L, button_name(e.button.button));
@ -123,7 +123,8 @@ top:
case SDL_MOUSEWHEEL:
lua_pushstring(L, "mousewheel");
lua_pushnumber(L, e.wheel.y);
return 2;
lua_pushnumber(L, e.wheel.x);
return 3;
default:
goto top;
@ -189,7 +190,7 @@ static int f_set_window_mode(lua_State *L)
n == WIN_FULLSCREEN ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0);
if (n == WIN_NORMAL)
SDL_RestoreWindow(window);
if (n == WIN_MAXIMIZED)
if (n == WIN_MAXIMIZED)
SDL_MaximizeWindow(window);
return 0;
}
@ -226,7 +227,7 @@ static int f_chdir(lua_State *L)
{
const char *path = luaL_checkstring(L, 1);
int err = chdir(path);
if (err)
if (err)
luaL_error(L, "chdir() failed");
return 0;
}
@ -247,9 +248,9 @@ static int f_list_dir(lua_State *L)
int i = 1;
struct dirent *entry;
while ( (entry = readdir(dir)) ) {
if (strcmp(entry->d_name, "." ) == 0)
if (strcmp(entry->d_name, "." ) == 0)
continue;
if (strcmp(entry->d_name, "..") == 0)
if (strcmp(entry->d_name, "..") == 0)
continue;
lua_pushstring(L, entry->d_name);
lua_rawseti(L, -2, i);
@ -264,7 +265,7 @@ static int f_absolute_path(lua_State *L)
{
const char *path = luaL_checkstring(L, 1);
char *res = realpath(path, NULL);
if (!res)
if (!res)
return 0;
lua_pushstring(L, res);
free(res);
@ -339,7 +340,7 @@ static int f_exec(lua_State *L)
size_t len;
const char *cmd = luaL_checklstring(L, 1, &len);
char *buf = malloc(len + 32);
if (!buf)
if (!buf)
luaL_error(L, "buffer allocation failed");
sprintf(buf, "%s &", cmd);
int res = system(buf);
@ -357,7 +358,7 @@ static int f_fuzzy_match(lua_State *L)
int run = 0;
while (*str && *ptn) {
while (*str == ' ')
while (*str == ' ')
str++;
while (*ptn == ' ')
ptn++;
@ -371,7 +372,7 @@ static int f_fuzzy_match(lua_State *L)
}
str++;
}
if (*ptn)
if (*ptn)
return 0;
lua_pushnumber(L, score - (int) strlen(str));

Loading…
Cancel
Save