diff --git a/src/group/group_layout_manager.cpp b/src/group/group_layout_manager.cpp index ad9aaad7c..a6b60d0ae 100644 --- a/src/group/group_layout_manager.cpp +++ b/src/group/group_layout_manager.cpp @@ -90,30 +90,26 @@ struct process_layout return; } - bound_box layout_box; - int middle_ifirst = safe_cast((member_boxes_.size() - 1) >> 1); - int top_i = 0; - int bottom_i = 0; - if (middle_ifirst % 2 == 0) + auto max_diff = layout.get_max_difference(); + auto layout_box = make_horiz_pair(0, 0.0, 0, x_margin, max_diff); + auto y_shift = 0.5 * layout_box.height(); + + for (size_t i = 2; i < member_boxes_.size(); i += 2) { - layout_box = make_horiz_pair(0, 0.0, 0, x_margin, layout.get_max_difference()); - top_i = middle_ifirst - 2; - bottom_i = middle_ifirst + 2; - } - else - { - top_i = middle_ifirst - 1; - bottom_i = middle_ifirst + 1; + auto y = layout_box.maxy() + y_margin; + auto pair_box = make_horiz_pair(i, y, 1, x_margin, max_diff); + layout_box.expand_to_include(pair_box); } - while (bottom_i >= 0 && top_i >= 0 && top_i < static_cast(member_offsets_.size())) - { - layout_box.expand_to_include(make_horiz_pair(static_cast(top_i), layout_box.miny() - y_margin, -1, x_margin, layout.get_max_difference())); - layout_box.expand_to_include(make_horiz_pair(static_cast(bottom_i), layout_box.maxy() + y_margin, 1, x_margin, layout.get_max_difference())); - top_i -= 2; - bottom_i += 2; - } + // layout_box.center corresponds to the center of the first row; + // shift offsets so that the whole group is centered vertically + y_shift -= 0.5 * layout_box.height(); + + for (auto & offset : member_offsets_) + { + offset.y += y_shift; + } } private: @@ -146,12 +142,12 @@ private: // stores corresponding offset, and returns modified bounding box bound_box box_offset_align(size_t i, double x, double y, int x_dir, int y_dir) const { - bound_box const& box = member_boxes_[i]; - pixel_position offset((x_dir == 0 ? x - input_origin_.x : x - (x_dir < 0 ? box.maxx() : box.minx())), - (y_dir == 0 ? y - input_origin_.y : y - (y_dir < 0 ? box.maxy() : box.miny()))); - - member_offsets_[i] = offset; - return bound_box(box.minx() + offset.x, box.miny() + offset.y, box.maxx() + offset.x, box.maxy() + offset.y); + auto box = member_boxes_[i]; + auto & offset = member_offsets_[i]; + offset.x = x - (x_dir == 0 ? input_origin_.x : (x_dir < 0 ? box.maxx() : box.minx())); + offset.y = y - (y_dir == 0 ? input_origin_.y : (y_dir < 0 ? box.maxy() : box.miny())); + box.move(offset.x, offset.y); + return box; } }; diff --git a/test/data-visual b/test/data-visual index 941db3d00..f9a3c203b 160000 --- a/test/data-visual +++ b/test/data-visual @@ -1 +1 @@ -Subproject commit 941db3d00920dc7aceaa6797096a7228bc7bac14 +Subproject commit f9a3c203b3657dd1748d788304f83a26efb6439f