Add some initial widget functionality (prefs partly working)

This commit is contained in:
elasota
2020-01-01 20:24:46 -05:00
parent d9b5dd20d6
commit 5fe6218c28
85 changed files with 2131 additions and 1074 deletions

View File

@@ -1,12 +1,18 @@
#pragma once
#include "CoreDefs.h"
#include <stdint.h>
template<class T>
class ArrayViewIterator
{
{
public:
#if GP_DEBUG_CONFIG
ArrayViewIterator(T *items, size_t count, size_t index);
#else
ArrayViewIterator(T *item);
#endif
ArrayViewIterator(const ArrayViewIterator<T> &other);
ArrayViewIterator<T> operator++(int);
@@ -24,9 +30,88 @@ public:
operator T*() const;
private:
#if GP_DEBUG_CONFIG
T *m_items;
size_t m_count;
size_t m_index;
#else
T *m_iter;
#endif
};
#if GP_DEBUG_CONFIG
#include <assert.h>
template<class T>
inline ArrayViewIterator<T>::ArrayViewIterator(T *items, size_t count, size_t index)
: m_items(items)
, m_count(count)
, m_index(index)
{
}
template<class T>
inline ArrayViewIterator<T>::ArrayViewIterator(const ArrayViewIterator<T> &other)
: m_items(other.m_items)
, m_count(other.m_count)
, m_index(other.m_index)
{
}
template<class T>
inline ArrayViewIterator<T> &ArrayViewIterator<T>::operator+=(ptrdiff_t delta)
{
if (delta < 0)
{
assert(-static_cast<ptrdiff_t>(m_index) >= delta);
}
else
{
assert(static_cast<ptrdiff_t>(m_count) >= delta && static_cast<ptrdiff_t>(m_count - m_index) >= delta);
}
m_index = static_cast<size_t>(static_cast<ptrdiff_t>(m_index) + delta);
return *this;
}
template<class T>
inline ArrayViewIterator<T> &ArrayViewIterator<T>::operator-=(ptrdiff_t delta)
{
if (delta >= 0)
{
assert(static_cast<ptrdiff_t>(m_index) >= delta);
}
else
{
assert(-static_cast<ptrdiff_t>(m_count) <= delta && -static_cast<ptrdiff_t>(m_count - m_index) <= delta);
}
m_index = static_cast<size_t>(static_cast<ptrdiff_t>(m_index) - delta);
return *this;
}
template<class T>
inline bool ArrayViewIterator<T>::operator==(const ArrayViewIterator<T> &other) const
{
return m_index == other.m_index && m_items == other.m_items;
}
template<class T>
inline bool ArrayViewIterator<T>::operator!=(const ArrayViewIterator<T> &other) const
{
return m_index != other.m_index || m_items != other.m_items;
}
template<class T>
inline ArrayViewIterator<T>::operator T*() const
{
assert(m_index < m_count);
return m_items + m_index;
}
#else
template<class T>
inline ArrayViewIterator<T>::ArrayViewIterator(T *item)
: m_iter(item)
@@ -39,36 +124,6 @@ inline ArrayViewIterator<T>::ArrayViewIterator(const ArrayViewIterator<T> &other
{
}
template<class T>
inline ArrayViewIterator<T> ArrayViewIterator<T>::operator++(int)
{
ArrayViewIterator<T> copy = *this;
m_iter++;
return copy;
}
template<class T>
inline ArrayViewIterator<T> &ArrayViewIterator<T>::operator++()
{
m_iter++;
return *this;
}
template<class T>
inline ArrayViewIterator<T> ArrayViewIterator<T>::operator--(int)
{
ArrayViewIterator<T> copy = *this;
m_iter--;
return copy;
}
template<class T>
inline ArrayViewIterator<T> &ArrayViewIterator<T>::operator--()
{
m_iter--;
return *this;
}
template<class T>
inline ArrayViewIterator<T> &ArrayViewIterator<T>::operator+=(ptrdiff_t delta)
{
@@ -92,7 +147,7 @@ inline bool ArrayViewIterator<T>::operator==(const ArrayViewIterator<T> &other)
template<class T>
inline bool ArrayViewIterator<T>::operator!=(const ArrayViewIterator<T> &other) const
{
return m_iter == other.m_iter;
return m_iter != other.m_iter;
}
template<class T>
@@ -100,3 +155,36 @@ inline ArrayViewIterator<T>::operator T*() const
{
return m_iter;
}
#endif
template<class T>
inline ArrayViewIterator<T> ArrayViewIterator<T>::operator++(int)
{
ArrayViewIterator<T> copy = *this;
++(*this);
return copy;
}
template<class T>
inline ArrayViewIterator<T> ArrayViewIterator<T>::operator--(int)
{
ArrayViewIterator<T> copy = *this;
--(*this);
return copy;
}
template<class T>
inline ArrayViewIterator<T> &ArrayViewIterator<T>::operator++()
{
(*this) += 1;
return *this;
}
template<class T>
inline ArrayViewIterator<T> &ArrayViewIterator<T>::operator--()
{
(*this) -= 1;
return *this;
}