summaryrefslogtreecommitdiff
path: root/node.c
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2021-02-27 23:15:43 -0500
committerLeo Tenenbaum <pommicket@gmail.com>2021-02-27 23:15:43 -0500
commit7089b92ff5606f1e9b934e2236b0295dcab922ae (patch)
tree41980ac3ef408fd8b89509a3b1670cd903feff22 /node.c
parent2db1e71ace9d9a91e35ef57c3901c7ebae8f82f0 (diff)
start tab moving
Diffstat (limited to 'node.c')
-rw-r--r--node.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/node.c b/node.c
index 0def1e4..b203529 100644
--- a/node.c
+++ b/node.c
@@ -96,6 +96,7 @@ static void node_join(Ted *ted, Node *node) {
}
static void node_close(Ted *ted, u16 node_idx) {
+ ted->dragging_tab_node = NULL;
ted->resizing_split = NULL;
assert(node_idx < TED_MAX_NODES);
@@ -146,6 +147,8 @@ static void node_close(Ted *ted, u16 node_idx) {
// close tab, WITHOUT checking for unsaved changes!
// returns true if the node is still open
static bool node_tab_close(Ted *ted, Node *node, u16 index) {
+ ted->dragging_tab_node = NULL;
+
u16 ntabs = (u16)arr_len(node->tabs);
assert(index < ntabs);
if (ntabs == 1) {
@@ -195,8 +198,13 @@ static void node_frame(Ted *ted, Node *node, Rect r) {
if (rect_contains_point(tab_bar_rect, click)) {
// click on tab to switch to it
u16 tab_index = (u16)((click.x - r.pos.x) / tab_width);
- ted->active_node = node;
- node_switch_to_tab(ted, node, tab_index);
+ if (tab_index >= 0 && tab_index < arr_len(node->tabs)) {
+ ted->active_node = node;
+ node_switch_to_tab(ted, node, tab_index);
+ ted->dragging_tab_node = node;
+ ted->dragging_tab_idx = tab_index;
+ ted->dragging_tab_origin = click;
+ }
}
}
for (u16 c = 0; c < ted->nmouse_clicks[SDL_BUTTON_MIDDLE]; ++c) {
@@ -229,6 +237,11 @@ static void node_frame(Ted *ted, Node *node, Rect r) {
char const *path = buffer_get_filename(buffer);
char const *filename = path_filename(path);
Rect tab_rect = rect(V2(r.pos.x + tab_width * i, r.pos.y), V2(tab_width, tab_bar_height));
+
+ if (node == ted->dragging_tab_node && i == ted->dragging_tab_idx) {
+ // make tab follow mouse
+ tab_rect.pos = v2_add(tab_rect.pos, v2_sub(ted->mouse_pos, ted->dragging_tab_origin));
+ }
// tab border
gl_geometry_rect_border(tab_rect, border_thickness, colors[COLOR_BORDER]);