Skip to content

Commit

Permalink
Add a flag to avoid updating a non-modified StatusBar on the screen
Browse files Browse the repository at this point in the history
  • Loading branch information
dacap committed Nov 3, 2017
1 parent 727a97f commit 1531d1f
Showing 1 changed file with 30 additions and 17 deletions.
47 changes: 30 additions & 17 deletions src/app/ui/status_bar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,17 @@ class StatusBar::Indicators : public HBox {
updateIndicator(text);
}

void updateIndicator(const char* text) {
bool updateIndicator(const char* text) {
if (this->text() == text)
return;
return false;

setText(text);

if (minSize().w > textSize().w*2)
setMinSize(textSize());
else
setMinSize(minSize().createUnion(textSize()));
return true;
}

private:
Expand Down Expand Up @@ -119,15 +120,16 @@ class StatusBar::Indicators : public HBox {
initTheme();
}

void updateIndicator(const skin::SkinPartPtr& part, bool colored) {
bool updateIndicator(const skin::SkinPartPtr& part, bool colored) {
if (m_part.get() == part.get() &&
m_colored == colored)
return;
return false;

ASSERT(part);
m_part = part;
m_colored = colored;
updateIndicator();
return true;
}

private:
Expand Down Expand Up @@ -166,12 +168,13 @@ class StatusBar::Indicators : public HBox {
updateIndicator(color, true);
}

void updateIndicator(const app::Color& color, bool first = false) {
bool updateIndicator(const app::Color& color, bool first = false) {
if (m_color == color && !first)
return;
return false;

m_color = color;
setMinSize(minSize().createUnion(Size(32*guiscale(), 1)));
return true;
}

private:
Expand All @@ -191,7 +194,9 @@ class StatusBar::Indicators : public HBox {

public:

Indicators() : m_backupIcon(BackupIcon::None) {
Indicators()
: m_backupIcon(BackupIcon::None)
, m_redraw(true) {
m_leftArea.setBorder(gfx::Border(0));
m_leftArea.setVisible(true);
m_leftArea.setExpansive(true);
Expand All @@ -209,20 +214,24 @@ class StatusBar::Indicators : public HBox {

void endIndicators() {
removeAllNextIndicators();
layout();
if (m_redraw) {
m_redraw = false;
layout();
}
}

void addTextIndicator(const char* text) {
// Re-use indicator
if (m_iterator != m_indicators.end()) {
if ((*m_iterator)->indicatorType() == Indicator::kText) {
static_cast<TextIndicator*>(*m_iterator)
m_redraw |= static_cast<TextIndicator*>(*m_iterator)
->updateIndicator(text);
++m_iterator;
return;
}
else
else {
removeAllNextIndicators();
}
}

auto indicator = new TextIndicator(text);
Expand All @@ -234,7 +243,7 @@ class StatusBar::Indicators : public HBox {
void addIconIndicator(const skin::SkinPartPtr& part, bool colored) {
if (m_iterator != m_indicators.end()) {
if ((*m_iterator)->indicatorType() == Indicator::kIcon) {
static_cast<IconIndicator*>(*m_iterator)
m_redraw |= static_cast<IconIndicator*>(*m_iterator)
->updateIndicator(part, colored);
++m_iterator;
return;
Expand All @@ -252,7 +261,7 @@ class StatusBar::Indicators : public HBox {
void addColorIndicator(const app::Color& color) {
if (m_iterator != m_indicators.end()) {
if ((*m_iterator)->indicatorType() == Indicator::kColor) {
static_cast<ColorIndicator*>(*m_iterator)
m_redraw |= static_cast<ColorIndicator*>(*m_iterator)
->updateIndicator(color);
++m_iterator;
return;
Expand Down Expand Up @@ -293,19 +302,23 @@ class StatusBar::Indicators : public HBox {
void removeAllNextIndicators() {
auto it = m_iterator;
auto end = m_indicators.end();
for (; it != end; ++it) {
auto indicator = *it;
m_leftArea.removeChild(indicator);
delete indicator;
if (m_iterator != end) {
for (; it != end; ++it) {
auto indicator = *it;
m_leftArea.removeChild(indicator);
delete indicator;
}
m_indicators.erase(m_iterator, end);
m_redraw = true;
}
m_indicators.erase(m_iterator, end);
}

std::vector<Indicator*> m_indicators;
std::vector<Indicator*>::iterator m_iterator;
BackupIcon m_backupIcon;
HBox m_leftArea;
HBox m_rightArea;
bool m_redraw;
};

class StatusBar::IndicatorsGeneration {
Expand Down

0 comments on commit 1531d1f

Please sign in to comment.