Fixed a bug in SimpleScrollAdapter "selectable" mode.

This commit is contained in:
casey langen 2016-11-08 07:26:36 -08:00
parent c8d3bd1692
commit 174e0dfbce
4 changed files with 16 additions and 13 deletions

View File

@ -1,3 +1,3 @@
#pragma once
#define VERSION "0.3.0"
#define VERSION "0.3.1"

View File

@ -60,12 +60,12 @@ namespace cursespp {
};
class IEntry {
public:
virtual ~IEntry() { }
virtual size_t GetLineCount() = 0;
virtual std::string GetLine(size_t line) = 0;
virtual void SetWidth(size_t width) = 0;
virtual int64 GetAttrs(size_t line) = 0;
public:
virtual ~IEntry() { }
virtual size_t GetLineCount() = 0;
virtual std::string GetLine(size_t line) = 0;
virtual void SetWidth(size_t width) = 0;
virtual int64 GetAttrs(size_t line) = 0;
};
typedef std::shared_ptr<IEntry> EntryPtr;

View File

@ -58,7 +58,7 @@ int64 MultiLineEntry::GetAttrs(size_t line) {
}
void MultiLineEntry::SetWidth(size_t width) {
if (this->width != width) {
if (this->width != width && width > 0) {
this->width = width;
this->lines = text::BreakLines(this->value, this->width);
}

View File

@ -76,12 +76,15 @@ void SimpleScrollAdapter::SetMaxEntries(size_t maxEntries) {
EntryPtr SimpleScrollAdapter::GetEntry(cursespp::ScrollableWindow* window, size_t index) {
auto entry = this->entries.at(index);
SingleLineEntry* styleable = static_cast<SingleLineEntry*>(entry.get());
styleable->SetAttrs(-1LL);
/* this is pretty damned gross, but super convenient. */
if (window && selectable) {
SingleLineEntry* single = dynamic_cast<SingleLineEntry*>(entry.get());
if (single) {
single->SetAttrs(-1LL);
if (window && this->selectable) {
if (index == window->GetScrollPosition().logicalIndex) {
styleable->SetAttrs(COLOR_PAIR(CURSESPP_HIGHLIGHTED_LIST_ITEM));
if (index == window->GetScrollPosition().logicalIndex) {
single->SetAttrs(COLOR_PAIR(CURSESPP_HIGHLIGHTED_LIST_ITEM));
}
}
}