Add padding to text style

This commit is contained in:
David Capello 2013-12-11 01:35:40 -03:00
parent 4bd4aac429
commit 4e917fc81c
6 changed files with 48 additions and 4 deletions

View File

@ -359,7 +359,7 @@
<!-- timeline_layer -->
<style id="timeline_layer" base="timeline_box">
<text align="left" valign="middle" />
<text align="left" valign="middle" padding-left="4" />
</style>
<!-- timeline_empty_frame -->

View File

@ -606,6 +606,8 @@ void SkinTheme::onRegenerate()
PRINTF("- Rule '%s' for '%s'\n", ruleName.c_str(), style_id);
// TODO This code design to read styles could be improved.
const char* part_id = xmlRule->Attribute("part");
const char* color_id = xmlRule->Attribute("color");
@ -635,6 +637,16 @@ void SkinTheme::onRegenerate()
else if (ruleName == "text") {
if (color_id) (*style)[StyleSheet::textColorRule()] = css::Value(color_id);
if (align) (*style)[StyleSheet::textAlignRule()] = css::Value(align);
const char* padding_left = xmlRule->Attribute("padding-left");
const char* padding_top = xmlRule->Attribute("padding-top");
const char* padding_right = xmlRule->Attribute("padding-right");
const char* padding_bottom = xmlRule->Attribute("padding-bottom");
if (padding_left) (*style)[StyleSheet::paddingLeftRule()] = css::Value(strtol(padding_left, NULL, 10));
if (padding_top) (*style)[StyleSheet::paddingTopRule()] = css::Value(strtol(padding_top, NULL, 10));
if (padding_right) (*style)[StyleSheet::paddingRightRule()] = css::Value(strtol(padding_right, NULL, 10));
if (padding_bottom) (*style)[StyleSheet::paddingBottomRule()] = css::Value(strtol(padding_bottom, NULL, 10));
}
xmlRule = xmlRule->NextSiblingElement();

View File

@ -71,13 +71,14 @@ void TextRule::onPaint(ui::Graphics* g, const gfx::Rect& bounds, const char* tex
{
SkinTheme* theme = static_cast<SkinTheme*>(ui::CurrentTheme::get());
if (text)
if (text) {
g->drawString(text,
(ui::is_transparent(m_color) ?
theme->getColor(ThemeColor::Text):
m_color),
ui::ColorNone,
bounds, m_align);
gfx::Rect(bounds).shrink(m_padding), m_align);
}
}
void IconRule::onPaint(ui::Graphics* g, const gfx::Rect& bounds, const char* text)
@ -113,6 +114,10 @@ Rules::Rules(const css::Query& query) :
css::Value iconPart = query[StyleSheet::iconPartRule()];
css::Value textAlign = query[StyleSheet::textAlignRule()];
css::Value textColor = query[StyleSheet::textColorRule()];
css::Value paddingLeft = query[StyleSheet::paddingLeftRule()];
css::Value paddingTop = query[StyleSheet::paddingTopRule()];
css::Value paddingRight = query[StyleSheet::paddingRightRule()];
css::Value paddingBottom = query[StyleSheet::paddingBottomRule()];
css::Value none;
if (backgroundColor != none
@ -130,10 +135,17 @@ Rules::Rules(const css::Query& query) :
}
if (textAlign != none
|| textColor != none) {
|| textColor != none
|| paddingLeft != none
|| paddingTop != none
|| paddingRight != none
|| paddingBottom != none) {
m_text = new TextRule();
m_text->setAlign((int)textAlign.number());
m_text->setColor(StyleSheet::convertColor(textColor));
m_text->setPadding(gfx::Border(
paddingLeft.number(), paddingTop.number(),
paddingRight.number(), paddingBottom.number())*ui::jguiscale());
}
}

View File

@ -25,6 +25,7 @@
#include "css/compound_style.h"
#include "css/state.h"
#include "css/stateful_style.h"
#include "gfx/border.h"
#include "gfx/fwd.h"
#include "ui/color.h"
@ -74,6 +75,7 @@ namespace app {
void setAlign(int align) { m_align = align; }
void setColor(ui::Color color) { m_color = color; }
void setPadding(const gfx::Border& padding) { m_padding = padding; }
protected:
void onPaint(ui::Graphics* g, const gfx::Rect& bounds, const char* text) OVERRIDE;
@ -81,6 +83,7 @@ namespace app {
private:
int m_align;
ui::Color m_color;
gfx::Border m_padding;
};
class IconRule : public Rule {

View File

@ -38,6 +38,10 @@ css::Rule StyleSheet::m_iconAlignRule("icon-align");
css::Rule StyleSheet::m_iconPartRule("icon-part");
css::Rule StyleSheet::m_textAlignRule("text-align");
css::Rule StyleSheet::m_textColorRule("text-color");
css::Rule StyleSheet::m_paddingLeftRule("padding-left");
css::Rule StyleSheet::m_paddingTopRule("padding-top");
css::Rule StyleSheet::m_paddingRightRule("padding-right");
css::Rule StyleSheet::m_paddingBottomRule("padding-bottom");
StyleSheet::StyleSheet()
{
@ -48,6 +52,10 @@ StyleSheet::StyleSheet()
m_sheet->addRule(&m_iconPartRule);
m_sheet->addRule(&m_textAlignRule);
m_sheet->addRule(&m_textColorRule);
m_sheet->addRule(&m_paddingLeftRule);
m_sheet->addRule(&m_paddingTopRule);
m_sheet->addRule(&m_paddingRightRule);
m_sheet->addRule(&m_paddingBottomRule);
}
StyleSheet::~StyleSheet()

View File

@ -50,6 +50,10 @@ namespace app {
static css::Rule& iconPartRule() { return m_iconPartRule; }
static css::Rule& textAlignRule() { return m_textAlignRule; }
static css::Rule& textColorRule() { return m_textColorRule; }
static css::Rule& paddingLeftRule() { return m_paddingLeftRule; }
static css::Rule& paddingTopRule() { return m_paddingTopRule; }
static css::Rule& paddingRightRule() { return m_paddingRightRule; }
static css::Rule& paddingBottomRule() { return m_paddingBottomRule; }
css::Sheet& sheet() { return *m_sheet; }
@ -69,6 +73,11 @@ namespace app {
static css::Rule m_iconPartRule;
static css::Rule m_textAlignRule;
static css::Rule m_textColorRule;
static css::Rule m_paddingLeftRule;
static css::Rule m_paddingTopRule;
static css::Rule m_paddingRightRule;
static css::Rule m_paddingBottomRule;
css::Sheet* m_sheet;
StyleMap m_styles;
};