Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
htop
Commits
6082db21
Commit
6082db21
authored
Aug 27, 2015
by
Hisham Muhammad
Browse files
Improve feedback when moving meters.
parent
f6c31eea
Changes
3
Hide whitespace changes
Inline
Side-by-side
AvailableMetersPanel.c
View file @
6082db21
...
...
@@ -45,8 +45,8 @@ static inline void AvailableMetersPanel_addMeter(Header* header, Panel* panel, M
Meter
*
meter
=
(
Meter
*
)
Header_addMeterByClass
(
header
,
type
,
param
,
column
);
Panel_add
(
panel
,
(
Object
*
)
Meter_toListItem
(
meter
,
false
));
Panel_setSelected
(
panel
,
Panel_size
(
panel
)
-
1
);
((
MetersPanel
*
)
panel
)
->
moving
=
true
;
((
ListItem
*
)
Panel_getSelected
(
panel
))
->
moving
=
true
;
MetersPanel_setMoving
((
MetersPanel
*
)
panel
,
true
)
;
FunctionBar_draw
(
panel
->
currentBar
,
NULL
)
;
}
static
HandlerResult
AvailableMetersPanel_eventHandler
(
Panel
*
super
,
int
ch
)
{
...
...
MetersPanel.c
View file @
6082db21
...
...
@@ -34,6 +34,11 @@ static const char* MetersFunctions[] = {"Type ", "Move ", "Delete", "Done ",
static
const
char
*
MetersKeys
[]
=
{
"Space"
,
"Enter"
,
"Del"
,
"Esc"
};
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
)
{
Panel
*
super
=
(
Panel
*
)
object
;
MetersPanel
*
this
=
(
MetersPanel
*
)
object
;
...
...
@@ -41,12 +46,23 @@ static void MetersPanel_delete(Object* object) {
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
)
{
Panel
*
super
=
(
Panel
*
)
this
;
if
(
this
->
moving
)
{
if
(
neighbor
)
{
if
(
selected
<
Vector_size
(
this
->
meters
))
{
((
ListItem
*
)
Panel_
g
et
Selected
(
super
))
->
moving
=
false
;
Meters
Panel_
s
et
Moving
(
this
,
false
)
;
Meter
*
meter
=
(
Meter
*
)
Vector_take
(
this
->
meters
,
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_setSelected
(
&
(
neighbor
->
super
),
selected
);
this
->
moving
=
false
;
neighbor
->
moving
=
true
;
((
ListItem
*
)
Panel_getSelected
((
Panel
*
)
neighbor
))
->
moving
=
true
;
MetersPanel_setMoving
(
neighbor
,
true
);
return
true
;
}
}
...
...
@@ -78,8 +92,8 @@ static HandlerResult MetersPanel_eventHandler(Panel* super, int ch) {
{
if
(
!
Vector_size
(
this
->
meters
))
break
;
this
->
moving
=
!
(
this
->
moving
);
((
ListItem
*
)
Panel_getSelected
(
super
))
->
moving
=
this
->
moving
;
MetersPanel_setMoving
(
this
,
!
(
this
->
moving
)
)
;
FunctionBar_draw
(
this
->
super
.
currentBar
,
NULL
)
;
result
=
HANDLED
;
break
;
}
...
...
@@ -183,6 +197,9 @@ MetersPanel* MetersPanel_new(Settings* settings, const char* header, Vector* met
MetersPanel
*
this
=
AllocThis
(
MetersPanel
);
Panel
*
super
=
(
Panel
*
)
this
;
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
);
this
->
settings
=
settings
;
...
...
MetersPanel.h
View file @
6082db21
...
...
@@ -27,6 +27,9 @@ struct MetersPanel_ {
};
void
MetersPanel_setMoving
(
MetersPanel
*
this
,
bool
moving
);
extern
PanelClass
MetersPanel_class
;
MetersPanel
*
MetersPanel_new
(
Settings
*
settings
,
const
char
*
header
,
Vector
*
meters
,
ScreenManager
*
scr
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment