From e5a4c3d4c9e7996225682f66121e1f1b93fce6c9 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Sat, 17 Aug 2013 14:37:24 +0100 Subject: Find the top y value of selections for indicator pos. --- desktop/treeview.c | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) (limited to 'desktop/treeview.c') diff --git a/desktop/treeview.c b/desktop/treeview.c index 49402ff8e..8f26b32aa 100644 --- a/desktop/treeview.c +++ b/desktop/treeview.c @@ -517,6 +517,33 @@ static inline treeview_node * treeview_node_next(treeview_node *node, bool full) } +/* Find y position of the top of a node + * + * \param tree Treeview object to delete node from + * \param node Node to get position of + * \return node's y position + */ +static int treeview_node_y(treeview *tree, treeview_node *node) +{ + treeview_node *n; + int y = 0; + + assert(tree != NULL); + assert(tree->root != NULL); + + n = treeview_node_next(tree->root, false); + + while (n != NULL && n != node) { + y += (node->type == TREE_NODE_ENTRY) ? + node->height : tree_g.line_height; + + n = treeview_node_next(n, false); + } + + return y; +} + + /* Walk a treeview subtree, calling a callback at each node (depth first) * * \param root Root to walk tree from (doesn't get a callback call) @@ -1895,6 +1922,7 @@ static bool treeview_set_move_indicator(treeview *tree, bool need_redraw, treeview_node *target, int node_height, int node_y, int mouse_y, struct rect *rect) { + treeview_node *orig = target; enum treeview_target_pos target_pos; int mouse_pos = mouse_y - node_y; int x; @@ -1903,9 +1931,6 @@ static bool treeview_set_move_indicator(treeview *tree, bool need_redraw, assert(tree->root != NULL); assert(tree->root->children != NULL); - node_y += (tree_g.line_height - - treeview_res[TREE_RES_ARROW].height + 1) / 2; - if (target->flags & TREE_NODE_SELECTED) { /* Find top selected ancestor */ while (target->parent && @@ -1968,12 +1993,20 @@ static bool treeview_set_move_indicator(treeview *tree, bool need_redraw, } } + /* Offset for ABOVE / BELOW */ if (target_pos == TV_TARGET_ABOVE) { + if (target != orig) { + node_y = treeview_node_y(tree, target); + } node_y -= (tree_g.line_height + 1) / 2; } else if (target_pos == TV_TARGET_BELOW) { node_y += node_height - (tree_g.line_height + 1) / 2; } + /* Oftsets are all relative to centred (INSIDE) */ + node_y += (tree_g.line_height - + treeview_res[TREE_RES_ARROW].height + 1) / 2; + if (target != NULL) { x = target->inset + tree_g.move_offset; } else { -- cgit v1.2.3