Convert news items to new theme styles

This commit is contained in:
David Capello 2017-03-10 19:23:43 -03:00
parent 4b60806556
commit 36ee5a39c8
3 changed files with 63 additions and 64 deletions

View File

@ -776,24 +776,6 @@
<icon part="tab_home_icon_active" />
</style>
<!-- news_item -->
<style id="news_item">
<background color="background" />
<text color="text" valign="middle" padding-left="2" padding-right="2" padding-top="3" padding-bottom="3" />
</style>
<style id="news_item:hover">
<background color="menuitem_hot_face" />
</style>
<style id="news_item:active">
<background color="listitem_selected_face" />
<text color="listitem_selected_text" />
</style>
<!-- news_item_detail -->
<style id="news_item_detail" base="news_item">
<text color="disabled" valign="top" wordwrap="true" padding-top="0" padding-bottom="0" />
</style>
</stylesheet>
<styles>
@ -1039,13 +1021,25 @@
<background color="background" />
<background color="menuitem_hot_face" state="mouse" />
<background color="listitem_selected_face" state="selected" />
<text color="text" align="left" x="2" /> <!-- padding-left="2" padding-right="2" padding-top="3" padding-bottom="1" -->
<text color="text" align="left" x="2" />
<text color="listitem_selected_text" align="left" x="2" state="selected" />
</style>
<style id="recent_file_detail" border="2" border-left="0" extends="recent_file">
<text color="disabled" align="left" x="2" />
</style>
<style id="news_item" border="2">
<background color="background" />
<background color="menuitem_hot_face" state="mouse" />
<background color="listitem_selected_face" state="selected" />
<text color="text" align="left" x="2" />
<text color="listitem_selected_text" align="left" x="2" state="selected" />
</style>
<style id="news_item_detail" extends="news_item" border="2">
<text color="disabled" align="left top wordwrap" x="2" />
<text color="listitem_selected_text" align="left top wordwrap" x="2" state="selected" />
</style>
</styles>
</theme>

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2001-2016 David Capello
// Copyright (C) 2001-2017 David Capello
//
// This program is distributed under the terms of
// the End-User License Agreement for Aseprite.
@ -14,7 +14,6 @@
#include "app/pref/preferences.h"
#include "app/res/http_loader.h"
#include "app/ui/skin/skin_theme.h"
#include "app/ui/skin/style.h"
#include "app/xml_document.h"
#include "base/fs.h"
#include "base/string.h"
@ -119,54 +118,49 @@ std::string parse_html(const std::string& str)
class NewsItem : public LinkLabel {
public:
NewsItem(const std::string& link,
const std::string& title,
const std::string& desc)
const std::string& title,
const std::string& desc)
: LinkLabel(link, title)
, m_title(title)
, m_desc(desc) {
}
protected:
void onSizeHint(SizeHintEvent& ev) override {
SkinTheme* theme = static_cast<SkinTheme*>(this->theme());
Style* style = theme->styles.newsItem();
Style* styleDetail = theme->styles.newsItemDetail();
Style::State state;
gfx::Size sz1 = style->sizeHint(text().c_str(), state);
gfx::Size sz2, sz2fourlines;
ui::Style* style = theme->newStyles.newsItem();
if (!m_desc.empty()) {
View* view = View::getView(parent());
sz2 = styleDetail->sizeHint(m_desc.c_str(), state,
(view ? view->viewportBounds().w: 0));
sz2fourlines = styleDetail->sizeHint("\n\n\n", state);
}
setText(m_title);
gfx::Size sz = theme->calcSizeHint(this, style);
ev.setSizeHint(gfx::Size(0, MIN(sz1.h+sz2fourlines.h, sz1.h+sz2.h)));
if (!m_desc.empty())
sz.h *= 5;
ev.setSizeHint(gfx::Size(0, sz.h));
}
void onPaint(PaintEvent& ev) override {
SkinTheme* theme = static_cast<SkinTheme*>(this->theme());
Graphics* g = ev.graphics();
gfx::Rect bounds = clientBounds();
Style* style = theme->styles.newsItem();
Style* styleDetail = theme->styles.newsItemDetail();
ui::Style* style = theme->newStyles.newsItem();
ui::Style* styleDetail = theme->newStyles.newsItemDetail();
Style::State state;
if (hasMouse() && !manager()->getCapture()) state += Style::hover();
if (isSelected()) state += Style::active();
if (parent()->hasCapture()) state += Style::clicked();
gfx::Size textSize = style->sizeHint(text().c_str(), state);
setText(m_title);
gfx::Size textSize = theme->calcSizeHint(this, style);
gfx::Rect textBounds(bounds.x, bounds.y, bounds.w, textSize.h);
gfx::Rect detailsBounds(
bounds.x, bounds.y+textSize.h,
bounds.w, bounds.h-textSize.h);
style->paint(g, textBounds, text().c_str(), state);
styleDetail->paint(g, detailsBounds, m_desc.c_str(), state);
theme->paintWidget(g, this, style, textBounds);
setText(m_desc);
theme->paintWidget(g, this, styleDetail, detailsBounds);
}
private:
std::string m_title;
std::string m_desc;
};

View File

@ -328,29 +328,40 @@ void Theme::paintLayer(Graphics* g,
case Style::Layer::Type::kText:
if (layer.color() != gfx::ColorNone) {
gfx::Size textSize = g->measureUIText(widget->text());
gfx::Point pt;
if (layer.align() & WORDWRAP) {
gfx::Rect textBounds = rc;
textBounds.offset(layer.offset());
if (layer.align() & LEFT)
pt.x = rc.x;
else if (layer.align() & RIGHT)
pt.x = rc.x+rc.w-textSize.w;
else
pt.x = rc.x+rc.w/2-textSize.w/2;
g->drawAlignedUIText(widget->text(),
layer.color(),
bgColor,
textBounds, layer.align());
}
else {
gfx::Size textSize = g->measureUIText(widget->text());
gfx::Point pt;
if (layer.align() & TOP)
pt.y = rc.y;
else if (layer.align() & BOTTOM)
pt.y = rc.y+rc.h-textSize.h;
else
pt.y = rc.y+rc.h/2-textSize.h/2;
if (layer.align() & LEFT)
pt.x = rc.x;
else if (layer.align() & RIGHT)
pt.x = rc.x+rc.w-textSize.w;
else
pt.x = rc.x+rc.w/2-textSize.w/2;
pt += layer.offset();
if (layer.align() & TOP)
pt.y = rc.y;
else if (layer.align() & BOTTOM)
pt.y = rc.y+rc.h-textSize.h;
else
pt.y = rc.y+rc.h/2-textSize.h/2;
g->drawUIText(widget->text(),
layer.color(),
bgColor,
pt, widget->mnemonic());
pt += layer.offset();
g->drawUIText(widget->text(),
layer.color(),
bgColor,
pt, widget->mnemonic());
}
}
break;