Menu: Rearranged and relabeled some buttons in the Update menu. Added ability to double-click entries to stage files for install/removal for improved UX.

This commit is contained in:
Marco Cawthorne 2020-07-30 09:54:46 +02:00
parent 73597af3c0
commit effc455b04
2 changed files with 45 additions and 5 deletions

View file

@ -82,6 +82,23 @@ up_btnremove_start(void)
print(sprintf("Marking package %s for 'removal'.\n", updates[pkgid].title));
}
void
up_toggleinstall(void)
{
int pkgid;
pkgid = up_lbUpdates.GetSelected();
switch (updates[pkgid].installed) {
case "rem":
localcmd(sprintf("pkg add %s\n", updates[pkgid].name));
updates[pkgid].installed = "pending";
break;
default:
localcmd(sprintf("pkg rem %s\n", updates[pkgid].name));
updates[pkgid].installed = "rem";
}
}
void
up_btnapply_start(void)
{
@ -117,13 +134,13 @@ menu_updates_init(void)
up_btnDone = spawn(CMainButton);
up_btnDone.SetImage(BTN_DONE);
up_btnDone.SetExecute(up_btndone_start);
up_btnDone.SetPos(50,420);
up_btnDone.SetPos(50,420+13);
Widget_Add(fn_updates, up_btnDone);
up_btnApply = spawn(CMainButton);
up_btnApply.SetImage(BTN_ACTIVATE);
up_btnApply.SetImage(BTN_UPDATE);
up_btnApply.SetExecute(up_btnapply_start);
up_btnApply.SetPos(50,450);
up_btnApply.SetPos(350+96,420+30);
Widget_Add(fn_updates, up_btnApply);
up_btnInstall = spawn(CMainButton);
@ -147,6 +164,7 @@ menu_updates_init(void)
up_lbUpdates.SetPos(53,163);
up_lbUpdates.SetSize(194+50,244);
up_lbUpdates.SetChanged(up_lbupdates_changed);
up_lbUpdates.SetDClicked(up_toggleinstall);
Widget_Add(fn_updates, up_lbUpdates);
up_sbUpdates = spawn(CScrollbar);

View file

@ -28,13 +28,15 @@ class CUpdateList:CWidget
int m_scroll;
int m_selected;
virtual void(void) m_changed = 0;
virtual void(void) m_dclicked = 0;
void(void) CUpdateList;
virtual void(void) Draw;
virtual void(float, float, float, float) Input;
virtual void(int, int) SetSize;
//virtual void(void(int)) SetChanged;
virtual void(void(void)) SetChanged;
virtual void(void(void)) SetDClicked;
virtual void(int) SetSelected;
virtual int(void) GetSelected;
};
@ -124,6 +126,7 @@ CUpdateList::Input(float type, float x, float y, float devid)
{
int visible;
int pos[2];
static float clicktime;
visible = floor(m_size[1] / 18) + 1;
visible = bound(0, visible, update_count);
@ -135,7 +138,19 @@ CUpdateList::Input(float type, float x, float y, float devid)
if (Util_CheckMouse(pos[0], pos[1], m_size[0], 18)) {
if (type == IE_KEYDOWN) {
if (x == K_MOUSE1) {
SetSelected(i);
if (m_selected != i) {
SetSelected(i);
clicktime = time + 0.5f;
} else {
if (time < clicktime) {
dprint("double click!\n");
if (m_dclicked) {
m_dclicked();
}
} else {
clicktime = time + 0.5f;
}
}
break;
}
}
@ -163,6 +178,13 @@ CUpdateList::SetChanged(void(void) func)
m_changed = func;
}
void
CUpdateList::SetDClicked(void(void) func)
{
m_dclicked = func;
}
void
CUpdateList::SetSelected(int i)
{