Skip to content

Commit

Permalink
bugfix: incorrect gaps on move
Browse files Browse the repository at this point in the history
  • Loading branch information
mattkae committed Dec 29, 2023
1 parent 04b1c6a commit ed6e9a1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,9 @@ bool Node::move_node(int from, int to) {

void Node::insert_node(std::shared_ptr<Node> node, int index)
{
auto position = new_node_position(index);
auto area_with_gaps = new_node_position(index);
node->parent = shared_from_this();
node->set_rectangle(position);
node->set_rectangle(get_logic_area_from_visible(area_with_gaps, gap_x, gap_y));
sub_nodes.insert(sub_nodes.begin() + index, node);
}

Expand Down Expand Up @@ -442,6 +442,20 @@ geom::Rectangle Node::get_visible_area(geom::Rectangle const& logical_area, int
};
}

geom::Rectangle Node::get_logic_area_from_visible(const geom::Rectangle &visible_area, int gap_x, int gap_y)
{
return {
geom::Point{
visible_area.top_left.x.as_int() - gap_x,
visible_area.top_left.y.as_int() - gap_y
},
geom::Size{
visible_area.size.width.as_int() + 2 * gap_x,
visible_area.size.height.as_int() + 2 * gap_y
}
};
}

std::shared_ptr<Node> Node::find_where(std::function<bool(std::shared_ptr<Node>)> func)
{
for (auto node : sub_nodes)
Expand Down
1 change: 1 addition & 0 deletions src/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class Node : public std::enable_shared_from_this<Node>
void translate_by(int x, int y);

static geom::Rectangle get_visible_area(geom::Rectangle const& logical_area, int gap_x, int gap_y);
static geom::Rectangle get_logic_area_from_visible(geom::Rectangle const& visible_area, int gap_x, int gap_y);
std::shared_ptr<Node> find_where(std::function<bool(std::shared_ptr<Node>)> func);

int get_gap_x() { return gap_x; }
Expand Down

0 comments on commit ed6e9a1

Please sign in to comment.