Started writing TabView

Loopable NumberField
This commit is contained in:
furrtek
2017-07-30 09:39:01 +01:00
parent 215ac43126
commit 89a3afcd74
11 changed files with 378 additions and 52 deletions

View File

@@ -114,7 +114,9 @@ void Widget::hidden(bool hide) {
if( hide ) {
// TODO: Instead of dirtying parent entirely, dirty only children
// that overlap with this widget.
parent()->dirty_overlapping_children_in_rect(parent_rect());
//parent()->dirty_overlapping_children_in_rect(parent_rect());
/* TODO: Notify self and all non-hidden children that they're
* now effectively hidden?
*/
@@ -1122,12 +1124,14 @@ NumberField::NumberField(
int length,
range_t range,
int32_t step,
char fill_char
char fill_char,
bool can_loop
) : Widget { { parent_pos, { 8 * length, 16 } } },
range { range },
step { step },
length_ { length },
fill_char { fill_char }
fill_char { fill_char },
can_loop { can_loop }
{
set_focusable(true);
}
@@ -1137,6 +1141,13 @@ int32_t NumberField::value() const {
}
void NumberField::set_value(int32_t new_value, bool trigger_change) {
if (can_loop) {
if (new_value >= 0)
new_value = new_value % (range.second + 1);
else
new_value = range.second + new_value + 1;
}
new_value = clip_value(new_value);
if( new_value != value() ) {

View File

@@ -485,9 +485,15 @@ public:
using range_t = std::pair<int32_t, int32_t>;
NumberField(Point parent_pos, int length, range_t range, int32_t step, char fill_char);
NumberField(Point parent_pos, int length, range_t range, int32_t step, char fill_char, bool can_loop);
NumberField(Point parent_pos, int length, range_t range, int32_t step, char fill_char
) : NumberField { parent_pos, length, range, step, fill_char, false }
{
}
NumberField(
) : NumberField { { 0, 0 }, 1, { 0, 1 }, 1, ' ' }
) : NumberField { { 0, 0 }, 1, { 0, 1 }, 1, ' ', false }
{
}
@@ -510,6 +516,7 @@ private:
const int length_;
const char fill_char;
int32_t value_ { 0 };
bool can_loop { };
int32_t clip_value(int32_t value);
};