Add an icon to "Home" tab

This commit is contained in:
David Capello 2015-02-19 21:44:22 -03:00
parent c704d20534
commit e850c8dbb0
10 changed files with 81 additions and 9 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 12 KiB

View File

@ -4,11 +4,12 @@
url="http://ilkke.blogspot.com/">
<dimensions>
<dim id="tabs_width" value="80" />
<dim id="tabs_height" value="17" />
<dim id="tabs_empty_height" value="5" />
<dim id="tabs_width" value="80" />
<dim id="tabs_close_icon_width" value="14" />
<dim id="tabs_close_icon_height" value="12" />
<dim id="tabs_icon_width" value="10" />
</dimensions>
<colors>
@ -233,6 +234,8 @@
<part id="tab_close_icon_active" x="37" y="117" w="5" h="5" />
<part id="tab_icon_bg_active" x="42" y="112" w="14" h="12" />
<part id="tab_icon_bg_hover" x="56" y="112" w="14" h="12" />
<part id="tab_home_icon_normal" x="32" y="240" w="7" h="8" />
<part id="tab_home_icon_active" x="40" y="240" w="7" h="8" />
<part id="editor_normal" x="40" y="96" w1="3" w2="10" w3="3" h1="3" h2="10" h3="3" />
<part id="editor_selected" x="56" y="96" w1="3" w2="10" w3="3" h1="3" h2="10" h3="3" />
<part id="colorbar_0" x="0" y="192" w1="5" w2="6" w3="5" h1="5" h2="6" h3="5" />
@ -627,6 +630,14 @@
<text color="tab_active_text" />
</style>
<!-- tab_text -->
<style id="tab_text">
<text color="tab_normal_text" align="left" valign="middle" padding-left="4" padding-top="2" />
</style>
<style id="tab_text:active">
<text color="tab_active_text" />
</style>
<!-- tab_bottom -->
<style id="tab_bottom">
<background part="tab_bottom_normal" color="tab_normal_face" repeat="repeat-x" />
@ -679,6 +690,14 @@
<icon part="tab_modified_icon_normal" />
</style>
<!-- tab_home -->
<style id="tab_home">
<icon part="tab_home_icon_normal" align="left" valign="middle" x="4" y="1" />
</style>
<style id="tab_home:active">
<icon part="tab_home_icon_active" />
</style>
</stylesheet>
</skin>

View File

@ -83,6 +83,11 @@ std::string DevConsoleView::getTabText()
return "Console";
}
TabIcon DevConsoleView::getTabIcon()
{
return TabIcon::NONE;
}
WorkspaceView* DevConsoleView::cloneWorkspaceView()
{
return new DevConsoleView();

View File

@ -26,6 +26,7 @@ namespace app {
// TabView implementation
std::string getTabText() override;
TabIcon getTabIcon() override;
// WorkspaceView implementation
ui::Widget* getContentWidget() override { return this; }

View File

@ -194,6 +194,11 @@ std::string DocumentView::getTabText()
return m_document->name();
}
TabIcon DocumentView::getTabIcon()
{
return TabIcon::NONE;
}
WorkspaceView* DocumentView::cloneWorkspaceView()
{
return new DocumentView(m_document, Normal);

View File

@ -42,6 +42,7 @@ namespace app {
// TabView implementation
std::string getTabText() override;
TabIcon getTabIcon() override;
// WorkspaceView implementation
ui::Widget* getContentWidget() override { return this; }

View File

@ -43,6 +43,11 @@ std::string HomeView::getTabText()
return "Home";
}
TabIcon HomeView::getTabIcon()
{
return TabIcon::HOME;
}
WorkspaceView* HomeView::cloneWorkspaceView()
{
return NULL; // This view cannot be cloned

View File

@ -27,6 +27,7 @@ namespace app {
// TabView implementation
std::string getTabText() override;
TabIcon getTabIcon() override;
// WorkspaceView implementation
ui::Widget* getContentWidget() override { return this; }

View File

@ -80,6 +80,7 @@ void Tabs::addTab(TabView* tabView)
{
Tab* tab = new Tab(tabView);
tab->text = tab->view->getTabText();
tab->icon = tab->view->getTabIcon();
m_list.push_back(tab);
@ -131,8 +132,10 @@ void Tabs::removeTab(TabView* tabView)
void Tabs::updateTabsText()
{
for (Tab* tab : m_list)
for (Tab* tab : m_list) {
tab->text = tab->view->getTabText();
tab->icon = tab->view->getTabIcon();
}
invalidate();
}
@ -418,7 +421,7 @@ void Tabs::selectTabInternal(Tab* tab)
invalidate();
}
void Tabs::drawTab(Graphics* g, const gfx::Rect& _box, Tab* tab, int y_delta,
void Tabs::drawTab(Graphics* g, const gfx::Rect& _box, Tab* tab, int dy,
bool hover, bool selected)
{
gfx::Rect box = _box;
@ -439,7 +442,7 @@ void Tabs::drawTab(Graphics* g, const gfx::Rect& _box, Tab* tab, int y_delta,
if (closeBox.isEmpty())
clipTextRightSide = 4*ui::guiscale();
else {
closeBox.y += y_delta;
closeBox.y += dy;
clipTextRightSide = closeBox.w;
}
@ -458,17 +461,40 @@ void Tabs::drawTab(Graphics* g, const gfx::Rect& _box, Tab* tab, int y_delta,
if (selected) state += skin::Style::active();
if (hover) state += skin::Style::hover();
// Tab without text
theme->styles.tab()->paint(g,
gfx::Rect(box.x, box.y+y_delta, box.w, box.h),
gfx::Rect(box.x, box.y+dy, box.w, box.h),
nullptr, state);
// Tab icon
TabIcon icon = tab->icon;
int dx = 0;
switch (icon) {
case TabIcon::NONE:
break;
case TabIcon::HOME:
{
theme->styles.tabHome()->paint(g,
gfx::Rect(
box.x,
box.y+dy,
box.x-dx,
box.h),
nullptr, state);
dx += theme->dimensions.tabsIconWidth();
}
break;
}
// Tab with text + clipping the close button
if (box.w > 8*ui::guiscale()) {
IntersectClip clip(g, gfx::Rect(box.x, box.y+y_delta, box.w-clipTextRightSide, box.h));
theme->styles.tab()->paint(g,
gfx::Rect(box.x, box.y+y_delta, box.w, box.h),
IntersectClip clip(g, gfx::Rect(box.x+dx, box.y+dy, box.w-dx-clipTextRightSide, box.h));
theme->styles.tabText()->paint(g,
gfx::Rect(box.x+dx, box.y+dy, box.w-dx, box.h),
tab->text.c_str(), state);
}
// Tab bottom part
theme->styles.tabBottom()->paint(g,
gfx::Rect(box.x, box.y2(), box.w, getBounds().y2()-box.y2()),
nullptr, state);

View File

@ -22,6 +22,11 @@ namespace ui {
namespace app {
class Tabs;
enum class TabIcon {
NONE,
HOME,
};
// Required interface to be implemented by each new tab that is added
// in the Tabs widget.
class TabView {
@ -30,6 +35,9 @@ namespace app {
// Returns the text to be shown in the tab.
virtual std::string getTabText() = 0;
// Returns the icon to be shown in the tab
virtual TabIcon getTabIcon() = 0;
};
// Interface used to control notifications from the Tabs widget.
@ -55,6 +63,7 @@ namespace app {
struct Tab {
TabView* view;
std::string text;
TabIcon icon;
Tab(TabView* view) : view(view) {
}
@ -92,7 +101,7 @@ namespace app {
void stopAni();
void selectTabInternal(Tab* tab);
void drawTab(ui::Graphics* g, const gfx::Rect& box, Tab* tab, int y_delta, bool hover, bool selected);
void drawTab(ui::Graphics* g, const gfx::Rect& box, Tab* tab, int dy, bool hover, bool selected);
TabsListIterator getTabIteratorByView(TabView* tabView);
Tab* getTabByView(TabView* tabView);
int getMaxScrollX();