[LyX/master] Fix cell background drawing for non-centered aligned cells
Juergen Spitzmueller
spitz at lyx.org
Thu May 7 11:05:45 UTC 2026
commit d470d4224baed5ee84b24cbbef4e2fd2d7c4d7aa
Author: Juergen Spitzmueller <spitz at lyx.org>
Date: Thu May 7 13:05:11 2026 +0200
Fix cell background drawing for non-centered aligned cells
---
src/insets/InsetTabular.cpp | 27 +++++++++++++++++++++++++--
src/insets/InsetTabular.h | 4 ++++
2 files changed, 29 insertions(+), 2 deletions(-)
diff --git a/src/insets/InsetTabular.cpp b/src/insets/InsetTabular.cpp
index a2cb633a53..51df839cde 100644
--- a/src/insets/InsetTabular.cpp
+++ b/src/insets/InsetTabular.cpp
@@ -1333,7 +1333,7 @@ int Tabular::cellWidth(idx_type cell) const
int w = 0;
col_type const span = columnSpan(cell);
col_type const col = cellColumn(cell);
- for(col_type c = col; c < col + span ; ++c)
+ for (col_type c = col; c < col + span ; ++c)
w += column_info[c].width;
return w;
}
@@ -4966,7 +4966,29 @@ void InsetTableCell::draw(PainterInfo & pi, int x, int y) const
int const w = width;
int const h = mr_rows * (tm.height() + 2 * topOffset(pi.base.bv) + bottomOffset(pi.base.bv) + Painter::thin_line);
int const yframe = y - mr_rows * (tm.ascent()) - mr_rows * (Painter::thin_line) - topOffset(pi.base.bv);
- int const xframe = (isVarwidth) ? x : x - (w - tm.width()) / 2 + leftOffset(pi.base.bv);
+ // xframe depends on alignment if not varwidth
+ int xframe = x;
+ switch (contentAlign) {
+ case LYX_ALIGN_CENTER:
+ xframe = (isVarwidth) ? x
+ : x - text_h_offset;
+ break;
+ case LYX_ALIGN_NONE:
+ case LYX_ALIGN_BLOCK:
+ case LYX_ALIGN_LEFT:
+ xframe = x - leftOffset(pi.base.bv);
+ break;
+ case LYX_ALIGN_RIGHT:
+ xframe = (isVarwidth) ? x + rightOffset(pi.base.bv) + Painter::thin_line
+ : x - text_h_offset;
+ break;
+ case LYX_ALIGN_DECIMAL:
+ xframe = x - text_h_offset;
+ break;
+ case LYX_ALIGN_LAYOUT:
+ case LYX_ALIGN_SPECIAL:
+ break;
+ }
if (pi.full_repaint)
pi.pain.fillRectangle(xframe, yframe, w, h,
@@ -5328,6 +5350,7 @@ void InsetTabular::draw(PainterInfo & pi, int x, int y) const
drawCellLines(pi, nx, yy, r, idx);
nx += tabular.cellWidth(idx);
pi.selected = original_selection_state;
+ tabular.cell_info[r][c].inset->setTextHOffset(tabular.textHOffset(tabular.cellIndex(r, c)));
tabular.cell_info[r][c].inset->setWidth(tabular.cellWidth(tabular.cellIndex(r, c)));
}
diff --git a/src/insets/InsetTabular.h b/src/insets/InsetTabular.h
index f0a450446d..0b7c106cbb 100644
--- a/src/insets/InsetTabular.h
+++ b/src/insets/InsetTabular.h
@@ -84,6 +84,8 @@ public:
///
void setWidth(int i) { width = i; }
///
+ void setTextHOffset(int i) { text_h_offset = i; }
+ ///
void setContentAlignment(LyXAlignment al) { contentAlign = al; }
///
void setBackgroundColor(std::string const & col) { background_color = col; }
@@ -151,6 +153,8 @@ private:
///
int width = 0;
///
+ int text_h_offset = 0;
+ ///
bool isCaptionRow = false;
///
LyXAlignment contentAlign = LYX_ALIGN_CENTER;
More information about the lyx-cvs
mailing list