Improve feedback when moving meters.

This commit is contained in:
Hisham Muhammad 2015-08-27 19:14:13 -03:00
parent f6c31eeaf5
commit 6082db2121
3 changed files with 28 additions and 8 deletions

View File

@ -45,8 +45,8 @@ static inline void AvailableMetersPanel_addMeter(Header* header, Panel* panel, M
Meter* meter = (Meter*) Header_addMeterByClass(header, type, param, column); Meter* meter = (Meter*) Header_addMeterByClass(header, type, param, column);
Panel_add(panel, (Object*) Meter_toListItem(meter, false)); Panel_add(panel, (Object*) Meter_toListItem(meter, false));
Panel_setSelected(panel, Panel_size(panel) - 1); Panel_setSelected(panel, Panel_size(panel) - 1);
((MetersPanel*)panel)->moving = true; MetersPanel_setMoving((MetersPanel*)panel, true);
((ListItem*)Panel_getSelected(panel))->moving = true; FunctionBar_draw(panel->currentBar, NULL);
} }
static HandlerResult AvailableMetersPanel_eventHandler(Panel* super, int ch) { static HandlerResult AvailableMetersPanel_eventHandler(Panel* super, int ch) {

View File

@ -34,6 +34,11 @@ static const char* MetersFunctions[] = {"Type ", "Move ", "Delete", "Done ",
static const char* MetersKeys[] = {"Space", "Enter", "Del", "Esc"}; static const char* MetersKeys[] = {"Space", "Enter", "Del", "Esc"};
static int MetersEvents[] = {' ', 13, KEY_DC, 27}; static int MetersEvents[] = {' ', 13, KEY_DC, 27};
static const char* MetersMovingFunctions[] = {"Up ", "Down ", "Left ", "Right ", "Confirm", "Delete", "Done ", NULL};
static const char* MetersMovingKeys[] = {"Up", "Dn", "Lt", "Rt", "Arrows", "Enter", "Del", "Esc"};
static int MetersMovingEvents[] = {KEY_UP, KEY_DOWN, KEY_LEFT, KEY_RIGHT, 13, KEY_DC, 27};
static FunctionBar* Meters_movingBar = NULL;
static void MetersPanel_delete(Object* object) { static void MetersPanel_delete(Object* object) {
Panel* super = (Panel*) object; Panel* super = (Panel*) object;
MetersPanel* this = (MetersPanel*) object; MetersPanel* this = (MetersPanel*) object;
@ -41,12 +46,23 @@ static void MetersPanel_delete(Object* object) {
free(this); free(this);
} }
void MetersPanel_setMoving(MetersPanel* this, bool moving) {
Panel* super = (Panel*) this;
this->moving = moving;
((ListItem*)Panel_getSelected(super))->moving = moving;
if (!moving) {
Panel_setDefaultBar(super);
} else {
super->currentBar = Meters_movingBar;
}
}
static inline bool moveToNeighbor(MetersPanel* this, MetersPanel* neighbor, int selected) { static inline bool moveToNeighbor(MetersPanel* this, MetersPanel* neighbor, int selected) {
Panel* super = (Panel*) this; Panel* super = (Panel*) this;
if (this->moving) { if (this->moving) {
if (neighbor) { if (neighbor) {
if (selected < Vector_size(this->meters)) { if (selected < Vector_size(this->meters)) {
((ListItem*)Panel_getSelected(super))->moving = false; MetersPanel_setMoving(this, false);
Meter* meter = (Meter*) Vector_take(this->meters, selected); Meter* meter = (Meter*) Vector_take(this->meters, selected);
Panel_remove(super, selected); Panel_remove(super, selected);
@ -54,9 +70,7 @@ static inline bool moveToNeighbor(MetersPanel* this, MetersPanel* neighbor, int
Panel_insert(&(neighbor->super), selected, (Object*) Meter_toListItem(meter, false)); Panel_insert(&(neighbor->super), selected, (Object*) Meter_toListItem(meter, false));
Panel_setSelected(&(neighbor->super), selected); Panel_setSelected(&(neighbor->super), selected);
this->moving = false; MetersPanel_setMoving(neighbor, true);
neighbor->moving = true;
((ListItem*)Panel_getSelected((Panel*)neighbor))->moving = true;
return true; return true;
} }
} }
@ -78,8 +92,8 @@ static HandlerResult MetersPanel_eventHandler(Panel* super, int ch) {
{ {
if (!Vector_size(this->meters)) if (!Vector_size(this->meters))
break; break;
this->moving = !(this->moving); MetersPanel_setMoving(this, !(this->moving));
((ListItem*)Panel_getSelected(super))->moving = this->moving; FunctionBar_draw(this->super.currentBar, NULL);
result = HANDLED; result = HANDLED;
break; break;
} }
@ -183,6 +197,9 @@ MetersPanel* MetersPanel_new(Settings* settings, const char* header, Vector* met
MetersPanel* this = AllocThis(MetersPanel); MetersPanel* this = AllocThis(MetersPanel);
Panel* super = (Panel*) this; Panel* super = (Panel*) this;
FunctionBar* fuBar = FunctionBar_new(MetersFunctions, MetersKeys, MetersEvents); FunctionBar* fuBar = FunctionBar_new(MetersFunctions, MetersKeys, MetersEvents);
if (!Meters_movingBar) {
Meters_movingBar = FunctionBar_new(MetersMovingFunctions, MetersMovingKeys, MetersMovingEvents);
}
Panel_init(super, 1, 1, 1, 1, Class(ListItem), true, fuBar); Panel_init(super, 1, 1, 1, 1, Class(ListItem), true, fuBar);
this->settings = settings; this->settings = settings;

View File

@ -27,6 +27,9 @@ struct MetersPanel_ {
}; };
void MetersPanel_setMoving(MetersPanel* this, bool moving);
extern PanelClass MetersPanel_class; extern PanelClass MetersPanel_class;
MetersPanel* MetersPanel_new(Settings* settings, const char* header, Vector* meters, ScreenManager* scr); MetersPanel* MetersPanel_new(Settings* settings, const char* header, Vector* meters, ScreenManager* scr);