Fix ColorButton font

- We've added a new "font" attribute in <style>s elements.
- Fonts aren't reset when we refresh the theme. This must be fixed in a future version when the theme can be completely reloaded.
This commit is contained in:
David Capello 2017-03-08 18:53:36 -03:00
parent ff01a08b9e
commit 94dcfa7f35
12 changed files with 39 additions and 28 deletions

View File

@ -1010,7 +1010,7 @@
<style id="new_frame_button" extends="mini_button">
</style>
<style id="color_button" extends="mini_button" border="5">
<style id="color_button" extends="mini_button" border="5" font="mini">
</style>
<style id="splitter">

View File

@ -15,7 +15,6 @@
#include "app/color_utils.h"
#include "app/modules/editors.h"
#include "app/modules/gfx.h"
#include "app/modules/gui.h"
#include "app/ui/color_bar.h"
#include "app/ui/color_popup.h"
#include "app/ui/editor/editor.h"
@ -52,11 +51,9 @@ ColorButton::ColorButton(const app::Color& color,
, m_dependOnLayer(false)
, m_canPinSelector(canPinSelector)
{
this->setFocusStop(true);
setup_mini_font(this);
setStyle(SkinTheme::instance()->newStyles.colorButton());
setFocusStop(true);
initTheme();
UIContext::instance()->add_observer(this);
}
@ -103,6 +100,12 @@ app::Color ColorButton::getColorByPosition(const gfx::Point& pos)
return m_color;
}
void ColorButton::onInitTheme(InitThemeEvent& ev)
{
ButtonBase::onInitTheme(ev);
setStyle(SkinTheme::instance()->newStyles.colorButton());
}
bool ColorButton::onProcessMessage(Message* msg)
{
switch (msg->type()) {

View File

@ -15,6 +15,10 @@
#include "obs/signal.h"
#include "ui/button.h"
namespace ui {
class InitThemeEvent;
}
namespace app {
class ColorPopup;
@ -41,6 +45,7 @@ namespace app {
protected:
// Events
void onInitTheme(ui::InitThemeEvent& ev) override;
bool onProcessMessage(ui::Message* msg) override;
void onSizeHint(ui::SizeHintEvent& ev) override;
void onPaint(ui::PaintEvent& ev) override;

View File

@ -340,12 +340,13 @@ void SkinTheme::loadXml(const std::string& skinId)
if (sizeStr)
size = std::strtol(sizeStr, nullptr, 10);
if (id == "default") {
m_defaultFont = fontData->getFont(size);
}
else if (id == "mini") {
m_miniFont = fontData->getFont(size);
}
she::Font* font = fontData->getFont(size);
m_themeFonts[idStr] = font;
if (id == "default")
m_defaultFont = font;
else if (id == "mini")
m_miniFont = font;
}
xmlFont = xmlFont->NextSiblingElement();
@ -669,6 +670,15 @@ void SkinTheme::loadXml(const std::string& skinId)
style->setPadding(padding*guiscale());
}
// Font
{
const char* fontId = xmlStyle->Attribute("font");
if (fontId) {
she::Font* font = m_themeFonts[fontId];
style->setFont(font);
}
}
TiXmlElement* xmlLayer = xmlStyle->FirstChildElement();
while (xmlLayer) {
const std::string layerName = xmlLayer->Value();

View File

@ -142,6 +142,7 @@ namespace app {
StyleSheet m_stylesheet;
std::map<std::string, ui::Style*> m_styles;
std::map<std::string, FontData*> m_fonts;
std::map<std::string, she::Font*> m_themeFonts;
she::Font* m_defaultFont;
she::Font* m_miniFont;
};

View File

@ -42,12 +42,6 @@ void removeWidget(Widget* widget)
widgets->erase(it);
}
void resetFontAllWidgets()
{
for (auto widget : *widgets)
widget->resetFont();
}
void reinitThemeForAllWidgets()
{
// Reinitialize the theme of each widget

View File

@ -31,7 +31,6 @@ namespace ui {
void addWidget(Widget* widget);
void removeWidget(Widget* widget);
void resetFontAllWidgets();
void reinitThemeForAllWidgets();
} // namespace details

View File

@ -23,6 +23,7 @@ Style::Style(const Style* base)
, m_margin(base ? base->margin(): Style::UndefinedBorder())
, m_border(base ? base->border(): Style::UndefinedBorder())
, m_padding(base ? base->padding(): Style::UndefinedBorder())
, m_font(nullptr)
{
if (base)
m_layers = base->layers();

View File

@ -19,6 +19,7 @@
#include <vector>
namespace she {
class Font;
class Surface;
}
@ -98,12 +99,14 @@ namespace ui {
const gfx::Border& margin() const { return m_margin; }
const gfx::Border& border() const { return m_border; }
const gfx::Border& padding() const { return m_padding; }
she::Font* font() const { return m_font; }
const Layers& layers() const { return m_layers; }
void setId(const std::string& id) { m_id = id; }
void setMargin(const gfx::Border& value) { m_margin = value; }
void setBorder(const gfx::Border& value) { m_border = value; }
void setPadding(const gfx::Border& value) { m_padding = value; }
void setFont(she::Font* font) { m_font = font; }
void addLayer(const Layer& layer);
private:
@ -113,6 +116,7 @@ namespace ui {
gfx::Border m_margin;
gfx::Border m_border;
gfx::Border m_padding;
she::Font* m_font;
};
} // namespace ui

View File

@ -91,8 +91,6 @@ void Theme::regenerate()
onRegenerate();
details::resetFontAllWidgets();
// TODO We cannot reinitialize all widgets because this mess all
// child spacing, border, etc. But it could be good to change the
// uiscale() and get the new look without the need to restart the

View File

@ -162,11 +162,6 @@ she::Font* Widget::font() const
return m_font;
}
void Widget::resetFont()
{
m_font = nullptr;
}
void Widget::setBgColor(gfx::Color color)
{
m_bgColor = color;
@ -188,6 +183,8 @@ void Widget::setStyle(Style* style)
m_style = style;
m_border = m_theme->calcBorder(this, style);
m_bgColor = m_theme->calcBgColor(this, m_style);
if (style->font())
m_font = style->font();
}
// ===============================================================

View File

@ -137,7 +137,6 @@ namespace ui {
// ===============================================================
she::Font* font() const;
void resetFont();
// Gets the background color of the widget.
gfx::Color bgColor() const {