Cache name and path in RecentFileItem

This is to avoid calling base.:get_file_name/path()
on each onPaint/SizeHint()
This commit is contained in:
David Capello 2016-03-04 17:30:12 -03:00
parent 75203037e2
commit f391be6824

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2001-2015 David Capello // Copyright (C) 2001-2016 David Capello
// //
// This program is free software; you can redistribute it and/or modify // This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as // it under the terms of the GNU General Public License version 2 as
@ -40,7 +40,9 @@ using namespace skin;
class RecentFileItem : public LinkLabel { class RecentFileItem : public LinkLabel {
public: public:
RecentFileItem(const std::string& file) RecentFileItem(const std::string& file)
: LinkLabel(file) { : LinkLabel(file)
, m_name(base::get_file_name(file))
, m_path(base::get_file_path(file)) {
} }
protected: protected:
@ -49,8 +51,8 @@ protected:
Style* style = theme->styles.recentFile(); Style* style = theme->styles.recentFile();
Style* styleDetail = theme->styles.recentFileDetail(); Style* styleDetail = theme->styles.recentFileDetail();
Style::State state; Style::State state;
gfx::Size sz1 = style->sizeHint(name().c_str(), state); gfx::Size sz1 = style->sizeHint(m_name.c_str(), state);
gfx::Size sz2 = styleDetail->sizeHint(path().c_str(), state); gfx::Size sz2 = styleDetail->sizeHint(m_path.c_str(), state);
ev.setSizeHint(gfx::Size(sz1.w+sz2.w, MAX(sz1.h, sz2.h))); ev.setSizeHint(gfx::Size(sz1.w+sz2.w, MAX(sz1.h, sz2.h)));
} }
@ -66,14 +68,13 @@ protected:
if (isSelected()) state += Style::active(); if (isSelected()) state += Style::active();
if (parent()->hasCapture()) state += Style::clicked(); if (parent()->hasCapture()) state += Style::clicked();
std::string name = this->name(); style->paint(g, bounds, m_name.c_str(), state);
style->paint(g, bounds, name.c_str(), state);
gfx::Size textSize = style->sizeHint(name.c_str(), state); gfx::Size textSize = style->sizeHint(m_name.c_str(), state);
gfx::Rect detailsBounds( gfx::Rect detailsBounds(
bounds.x+textSize.w, bounds.y, bounds.x+textSize.w, bounds.y,
bounds.w-textSize.w, bounds.h); bounds.w-textSize.w, bounds.h);
styleDetail->paint(g, detailsBounds, path().c_str(), state); styleDetail->paint(g, detailsBounds, m_path.c_str(), state);
} }
void onClick() override { void onClick() override {
@ -81,8 +82,8 @@ protected:
} }
private: private:
std::string name() const { return base::get_file_name(text()); } std::string m_name;
std::string path() const { return base::get_file_path(text()); } std::string m_path;
}; };
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////