int x = 0;
if (row_.isRTL()) {
int const normal_x = nestMargin() + changebarMargin();
- x = min(normal_x, row_.left_margin - size - Inset::TEXT_TO_INSET_OFFSET);
+ x = min(normal_x, row_.left_margin - size - Inset::textOffset(pi_.base.bv));
} else {
int const normal_x = tm_.width() - row_.right_margin
- - size - Inset::TEXT_TO_INSET_OFFSET;
+ - size - Inset::textOffset(pi_.base.bv);
x = max(normal_x, row_.width());
}
// the begining/end of row. However, it will not work if
// the caret has a ridiculous width like 6. (see ticket
// #10797)
- pi.pain.fillRectangle(max(row_x, 0) - Inset::TEXT_TO_INSET_OFFSET,
+ pi.pain.fillRectangle(max(row_x, 0) - Inset::textOffset(pi.base.bv),
y - row.ascent(),
- width() + 2 * Inset::TEXT_TO_INSET_OFFSET,
+ width() + 2 * Inset::textOffset(pi.base.bv),
row.height(), pi.background_color);
}
/// https://www.mail-archive.com/lyx-devel@lists.lyx.org/msg199001.html
virtual Inset * editXY(Cursor & cur, int x, int y);
+ /// The default margin inside text insets
+ static int textOffset(BufferView const *) { return 4; }
+ ///
+ virtual int topOffset(BufferView const *bv) const { return textOffset(bv); }
+ ///
+ virtual int bottomOffset(BufferView const *bv) const { return textOffset(bv); }
+ ///
+ virtual int leftOffset(BufferView const *bv) const { return textOffset(bv); }
+ ///
+ virtual int rightOffset(BufferView const *bv) const { return textOffset(bv); }
+
/// compute the size of the object returned in dim
virtual void metrics(MetricsInfo & mi, Dimension & dim) const = 0;
/// draw inset and update (xo, yo)-cache
virtual ColorCode backgroundColor(PainterInfo const &) const;
///
virtual ColorCode labelColor() const;
- //
- enum { TEXT_TO_INSET_OFFSET = 4 };
/// Determine the action of backspace and delete: do we select instead of
/// deleting if not already selected?
mi.base.font = mi.base.bv->buffer().params().getFont().fontInfo();
labelwidth_ = theFontMetrics(mi.base.font).width(full_label_);
// add some space to separate the label from the inset text
- labelwidth_ += 2 * TEXT_TO_INSET_OFFSET;
+ labelwidth_ += leftOffset(mi.base.bv) + rightOffset(mi.base.bv);
dim.wid = labelwidth_;
Dimension textdim;
// Correct for button and label width
void InsetCaption::drawBackground(PainterInfo & pi, int x, int y) const
{
TextMetrics & tm = pi.base.bv->textMetrics(&text());
- int const h = tm.height() + 2 * TEXT_TO_INSET_OFFSET;
- int const yy = y - TEXT_TO_INSET_OFFSET - tm.ascent();
+ int const h = tm.height() + topOffset(pi.base.bv) + bottomOffset(pi.base.bv);
+ int const yy = y - topOffset(pi.base.bv) - tm.ascent();
pi.pain.fillRectangle(x, yy, labelwidth_, h, pi.backgroundColor(this));
}
FontInfo tmpfont = pi.base.font;
pi.base.font = pi.base.bv->buffer().params().getFont().fontInfo();
pi.base.font.setColor(pi.textColor(pi.base.font.color()).baseColor);
- int const xx = x + TEXT_TO_INSET_OFFSET;
+ int const xx = x + leftOffset(pi.base.bv);
pi.pain.text(xx, y, full_label_, pi.base.font);
InsetText::draw(pi, x + labelwidth_, y);
pi.base.font = tmpfont;
FontInfo labelfont(getLabelfont());
labelfont.realize(sane_font);
theFontMetrics(labelfont).buttonText(
- buttonLabel(bv), TEXT_TO_INSET_OFFSET, dim.wid, dim.asc, dim.des);
+ buttonLabel(bv), Inset::textOffset(&bv), dim.wid, dim.asc, dim.des);
return dim;
}
dim.des = max(dim.des - textdim.asc + dim.asc, textdim.des);
dim.asc = textdim.asc;
} else {
- dim.des += textdim.height() + TEXT_TO_INSET_OFFSET;
+ dim.des += textdim.height() + topOffset(mi.base.bv);
dim.wid = max(dim.wid, textdim.wid);
}
}
labelfont.realize(pi.base.font);
pi.pain.buttonText(x, y, buttonLabel(bv), labelfont,
view_[&bv].mouse_hover_ ? Color_buttonhoverbg : Color_buttonbg,
- Color_buttonframe, TEXT_TO_INSET_OFFSET);
+ Color_buttonframe, Inset::textOffset(pi.base.bv));
// Draw the change tracking cue on the label, unless RowPainter already
// takes care of it.
if (canPaintChange(bv))
// Colour the frame according to the change type. (Like for tables.)
Color colour = pi.change.changed() ? pi.change.color()
: Color_foreground;
- const int xx1 = x + TEXT_TO_INSET_OFFSET - 1;
- const int xx2 = x + textdim.wid - TEXT_TO_INSET_OFFSET + 1;
+ const int xx1 = x + leftOffset(pi.base.bv) - 1;
+ const int xx2 = x + textdim.wid - rightOffset(pi.base.bv) + 1;
pi.pain.line(xx1, y + desc - 4,
xx1, y + desc, colour);
if (status_ == Open)
dim.wid = max(dim.wid, 4);
dim.asc = max(dim.asc, 4);
- dim.asc += TEXT_TO_INSET_OFFSET;
- dim.des += TEXT_TO_INSET_OFFSET;
+ dim.asc += topOffset(mi.base.bv);
+ dim.des += bottomOffset(mi.base.bv);
// insert a one pixel gap
dim.wid += 1;
Dimension dim_dummy;
// | | | |
// x1 x2 x3 x4
- x = x + TEXT_TO_INSET_OFFSET;
+ x += leftOffset(pi.base.bv);
int const x1 = x;
int const x2 = x + arrow_size;
- int const x4 = x + dim.wid - 2 * TEXT_TO_INSET_OFFSET;
+ int const x4 = x + dim.wid - leftOffset(pi.base.bv) - rightOffset(pi.base.bv);
int const x3 = x4 - arrow_size;
int const y2 = y + (dim.des - dim.asc) / 2;
dim.wid = max(dim.wid, 4);
dim.asc = max(dim.asc, 4);
- dim.asc += TEXT_TO_INSET_OFFSET;
- dim.des += TEXT_TO_INSET_OFFSET;
+ dim.asc += topOffset(mi.base.bv);
+ dim.des += bottomOffset(mi.base.bv);
// insert a one pixel gap
dim.wid += 1;
Dimension dim_dummy;
void InsetTableCell::metrics(MetricsInfo & mi, Dimension & dim) const
{
TextMetrics & tm = mi.base.bv->textMetrics(&text());
+ int const horiz_offset = leftOffset(mi.base.bv) + rightOffset(mi.base.bv);
// Hand font through to contained lyxtext:
tm.font_.fontInfo() = mi.base.font;
- mi.base.textwidth -= 2 * TEXT_TO_INSET_OFFSET;
+ mi.base.textwidth -= horiz_offset;
// This can happen when a layout has a left and right margin,
// and the view is made very narrow. We can't do better than
tm.metrics(mi, dim, mi.base.textwidth, false);
else
tm.metrics(mi, dim, 0, false);
- mi.base.textwidth += 2 * TEXT_TO_INSET_OFFSET;
- dim.asc += TEXT_TO_INSET_OFFSET;
- dim.des += TEXT_TO_INSET_OFFSET;
- dim.wid += 2 * TEXT_TO_INSET_OFFSET;
+ mi.base.textwidth += horiz_offset;
+ dim.asc += topOffset(mi.base.bv);
+ dim.des += bottomOffset(mi.base.bv);
+ dim.wid += horiz_offset;
}
tabular.cell_info[r][c].decimal_width = decimal_width;
// with LYX_VALIGN_BOTTOM the descent is relative to the last par
- // = descent of text in last par + TEXT_TO_INSET_OFFSET:
+ // = descent of text in last par + bottomOffset:
int const lastpardes = tm.last().second->descent()
- + TEXT_TO_INSET_OFFSET;
+ + bottomOffset(mi.base.bv);
int offset = 0;
switch (tabular.getVAlignment(cell)) {
case Tabular::LYX_VALIGN_TOP:
{
TextMetrics const & tm = bv.textMetrics(&text_);
Dimension dim = tm.dim();
- dim.wid += 2 * TEXT_TO_INSET_OFFSET;
- dim.des += TEXT_TO_INSET_OFFSET;
- dim.asc += TEXT_TO_INSET_OFFSET;
+ dim.wid += leftOffset(&bv) + rightOffset(&bv);
+ dim.des += bottomOffset(&bv);
+ dim.asc += topOffset(&bv);
return dim;
}
//lyxerr << "InsetText::metrics: width: " << mi.base.textwidth << endl;
+ int const horiz_offset = leftOffset(mi.base.bv) + rightOffset(mi.base.bv);
+
// Hand font through to contained lyxtext:
tm.font_.fontInfo() = mi.base.font;
- mi.base.textwidth -= 2 * TEXT_TO_INSET_OFFSET;
+ mi.base.textwidth -= horiz_offset;
// This can happen when a layout has a left and right margin,
// and the view is made very narrow. We can't do better than
tm.metrics(mi, dim, mi.base.textwidth);
else
tm.metrics(mi, dim);
- mi.base.textwidth += 2 * TEXT_TO_INSET_OFFSET;
- dim.asc += TEXT_TO_INSET_OFFSET;
- dim.des += TEXT_TO_INSET_OFFSET;
- dim.wid += 2 * TEXT_TO_INSET_OFFSET;
+ mi.base.textwidth += horiz_offset;
+ dim.asc += topOffset(mi.base.bv);
+ dim.des += bottomOffset(mi.base.bv);
+ dim.wid += horiz_offset;
}
{
TextMetrics & tm = pi.base.bv->textMetrics(&text_);
- int const w = tm.width() + TEXT_TO_INSET_OFFSET;
- int const yframe = y - TEXT_TO_INSET_OFFSET - tm.ascent();
- int const h = tm.height() + 2 * TEXT_TO_INSET_OFFSET;
- int const xframe = x + TEXT_TO_INSET_OFFSET / 2;
+ int const horiz_offset = leftOffset(pi.base.bv) + rightOffset(pi.base.bv);
+ int const w = tm.width() + (horiz_offset - horiz_offset / 2);
+ int const yframe = y - topOffset(pi.base.bv) - tm.ascent();
+ int const h = tm.height() + topOffset(pi.base.bv) + bottomOffset(pi.base.bv);
+ int const xframe = x + leftOffset(pi.base.bv) / 2;
bool change_drawn = false;
if (pi.full_repaint)
pi.pain.fillRectangle(xframe, yframe, w, h,
pi.backgroundColor(this, false));
// The change tracking cue must not be inherited
Changer dummy2 = make_change(pi.change, Change());
- tm.draw(pi, x + TEXT_TO_INSET_OFFSET, y);
+ tm.draw(pi, x + leftOffset(pi.base.bv), y);
}
if (drawFrame_) {
void InsetText::cursorPos(BufferView const & bv,
CursorSlice const & sl, bool boundary, int & x, int & y) const
{
- x = bv.textMetrics(&text_).cursorX(sl, boundary) + TEXT_TO_INSET_OFFSET;
+ x = bv.textMetrics(&text_).cursorX(sl, boundary) + leftOffset(&bv);
y = bv.textMetrics(&text_).cursorY(sl, boundary);
}
font.decSize();
frontend::FontMetrics const & fm = theFontMetrics(font);
- fm.buttonText(text_, Inset::TEXT_TO_INSET_OFFSET, dim.wid, dim.asc, dim.des);
+ fm.buttonText(text_, Inset::textOffset(mi.base.bv), dim.wid, dim.asc, dim.des);
dim_ = dim;
}
if (editable_) {
pi.pain.buttonText(x, y, text_, font,
renderState() ? Color_buttonhoverbg : Color_buttonbg,
- Color_buttonframe, Inset::TEXT_TO_INSET_OFFSET);
+ Color_buttonframe, Inset::textOffset(pi.base.bv));
} else {
pi.pain.buttonText(x, y, text_, font,
Color_commandbg, Color_commandframe,
- Inset::TEXT_TO_INSET_OFFSET);
+ Inset::textOffset(pi.base.bv));
}
}
bool const image_ready = displayGraphic(params_) && readyToDisplay(loader_);
if (image_ready) {
- dim.wid = loader_.image()->width() + 2 * Inset::TEXT_TO_INSET_OFFSET;
+ dim.wid = loader_.image()->width() + 2 * Inset::textOffset(mi.base.bv);
dim.asc = loader_.image()->height();
dim_ = dim;
return;
{
// This will draw the graphics. If the graphics has not been
// loaded yet, we draw just a rectangle.
- int const x1 = x + Inset::TEXT_TO_INSET_OFFSET;
+ int const x1 = x + Inset::textOffset(pi.base.bv);
int const y1 = y - dim_.asc;
- int const w = dim_.wid - 2 * Inset::TEXT_TO_INSET_OFFSET;
+ int const w = dim_.wid - 2 * Inset::textOffset(pi.base.bv);
int const h = dim_.height();
if (displayGraphic(params_) && readyToDisplay(loader_))
pi.pain.image(x, y - dim_.asc, dim_.wid, dim_.height(),
*image);
} else {
- int const offset = Inset::TEXT_TO_INSET_OFFSET;
+ int const offset = Inset::textOffset(pi.base.bv);
pi.pain.rectangle(x + offset,
y - dim_.asc,