FullscreenUI: Various improvements

This commit is contained in:
Connor McLaughlin
2022-09-17 15:51:05 +10:00
parent 91c8681bed
commit ef3ad91ad0
34 changed files with 1350 additions and 514 deletions

View File

@ -69,7 +69,7 @@ public:
void Evict(std::size_t count = 1)
{
while (m_items.size() >= count)
while (!m_items.empty() && count > 0)
{
typename MapType::iterator lowest = m_items.end();
for (auto iter = m_items.begin(); iter != m_items.end(); ++iter)
@ -78,6 +78,7 @@ public:
lowest = iter;
}
m_items.erase(lowest);
count--;
}
}
@ -87,23 +88,20 @@ public:
auto iter = m_items.find(key);
if (iter == m_items.end())
return false;
m_items.erase(iter);
return true;
}
void SetManualEvict(bool block)
{
m_manual_evict = block;
if (!m_manual_evict)
ManualEvict();
}
void ManualEvict()
{
// evict if we went over
while (m_items.size() > m_max_capacity)
Evict(m_items.size() - (m_max_capacity - 1));
Evict(m_items.size() - m_max_capacity);
}
private:

View File

@ -255,6 +255,31 @@ std::vector<std::string_view> StringUtil::SplitString(const std::string_view& st
return res;
}
std::vector<std::string> StringUtil::SplitNewString(const std::string_view& str, char delimiter,
bool skip_empty /*= true*/)
{
std::vector<std::string> res;
std::string_view::size_type last_pos = 0;
std::string_view::size_type pos;
while (last_pos < str.size() && (pos = str.find(delimiter, last_pos)) != std::string_view::npos)
{
std::string_view part(StripWhitespace(str.substr(last_pos, pos - last_pos)));
if (!skip_empty || !part.empty())
res.emplace_back(part);
last_pos = pos + 1;
}
if (last_pos < str.size())
{
std::string_view part(StripWhitespace(str.substr(last_pos)));
if (!skip_empty || !part.empty())
res.emplace_back(part);
}
return res;
}
std::string StringUtil::ReplaceAll(const std::string_view& subject, const std::string_view& search,
const std::string_view& replacement)
{

View File

@ -149,6 +149,7 @@ void StripWhitespace(std::string* str);
/// Splits a string based on a single character delimiter.
std::vector<std::string_view> SplitString(const std::string_view& str, char delimiter, bool skip_empty = true);
std::vector<std::string> SplitNewString(const std::string_view& str, char delimiter, bool skip_empty = true);
/// Joins a string together using the specified delimiter.
template<typename T>