]> git.lyx.org Git - lyx.git/blob - src/insets/RenderButton.cpp
Fix bug #7256. Reduce space around inset buttons by a pixel on each side.
[lyx.git] / src / insets / RenderButton.cpp
1 /**
2  * \file RenderButton.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Angus Leeming
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "RenderButton.h"
14
15 #include "MetricsInfo.h"
16
17 #include "frontends/FontMetrics.h"
18 #include "frontends/Painter.h"
19
20
21 namespace lyx {
22
23
24 RenderButton::RenderButton()
25         : editable_(false)
26 {}
27
28
29 RenderBase * RenderButton::clone(Inset const *) const
30 {
31         return new RenderButton(*this);
32 }
33
34
35 void RenderButton::update(docstring const & text, bool editable)
36 {
37         text_ = text;
38         editable_ = editable;
39 }
40
41
42 void RenderButton::metrics(MetricsInfo &, Dimension & dim) const
43 {
44         FontInfo font = sane_font;
45         font.decSize();
46         frontend::FontMetrics const & fm =
47                 theFontMetrics(font);
48
49         if (editable_)
50                 fm.buttonText(text_, dim.wid, dim.asc, dim.des);
51         else
52                 fm.rectText(text_, dim.wid, dim.asc, dim.des);
53
54         dim.wid += 2;
55         dim_ = dim;
56 }
57
58
59 void RenderButton::draw(PainterInfo & pi, int x, int y) const
60 {
61         // Draw it as a box with the LaTeX text
62         FontInfo font = sane_font;
63         font.setColor(Color_command);
64         font.decSize();
65
66         if (editable_) {
67                 pi.pain.buttonText(x + 1, y, text_, font, renderState());
68         } else {
69                 pi.pain.rectText(x + 1, y, text_, font,
70                                  Color_commandbg, Color_commandframe);
71         }
72 }
73
74
75 } // namespace lyx