From ec2bad004a96eb1c15ff11d457c2e5228a3233a3 Mon Sep 17 00:00:00 2001 From: patrick96 Date: Fri, 22 Nov 2019 00:01:40 +0100 Subject: [PATCH] fix(renderer): Correctly position right block if center is empty The issue was that it used the position of the center module to calculate the leftmost possible position of the block. However, if the center module is empty that position is disastrously wrong. Fixes #591 Fixes #1903 --- src/components/renderer.cpp | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/components/renderer.cpp b/src/components/renderer.cpp index ab803f2b..81d08b03 100644 --- a/src/components/renderer.cpp +++ b/src/components/renderer.cpp @@ -1,4 +1,5 @@ #include "components/renderer.hpp" + #include "cairo/context.hpp" #include "components/config.hpp" #include "events/signal.hpp" @@ -454,11 +455,25 @@ double renderer::block_x(alignment a) const { return std::max(base_pos - block_w(a) / 2.0, min_pos); } case alignment::RIGHT: { - double gap{0.0}; - if (block_w(alignment::LEFT) || block_w(alignment::CENTER)) { - gap = BLOCK_GAP; + /* + * The block immediately to the left of this block + * + * Generally the center block unless it is empty. + */ + alignment left_barrier = alignment::CENTER; + + if (block_w(alignment::CENTER) == 0) { + left_barrier = alignment::LEFT; } - return std::max(m_rect.width - block_w(a), block_x(alignment::CENTER) + gap + block_w(alignment::CENTER)); + + // The minimum x position this block can start at + double min_pos = block_x(left_barrier) + block_w(left_barrier); + + if (block_w(left_barrier) != 0) { + min_pos += BLOCK_GAP; + } + + return std::max(m_rect.width - block_w(a), min_pos); } default: return 0.0;