Browse Source

Menu cleanup / fixes

v1
Adam PIppin 3 years ago
parent
commit
a722a3bfca
  1. 73
      watchos/Module_Menu.cpp
  2. 2
      watchos/__vm/Compile.vmps.xml
  3. 2
      watchos/__vm/Upload.vmps.xml
  4. 3
      watchos/watchos.vcxproj
  5. 5
      watchos/watchos.vcxproj.filters

73
watchos/Module_Menu.cpp

@ -74,52 +74,37 @@ void Module_Menu::tick()
{
Event* e;
int prev_selected = m_selected;
bool scroll_up = false, scroll_down = false;
while (m_events->hasEvent())
{
e = m_events->pop();
if (!ui->isVisible(m_hwnd)) continue;
if (!ui->isVisible(m_hwnd) || m_result_select || m_result_cancel) continue;
if ((e->param1 & MODULE_INPUT_BUTTON_UP) == MODULE_INPUT_BUTTON_UP)
if ((e->param1 & MODULE_INPUT_BUTTON_UP) == MODULE_INPUT_BUTTON_UP && m_selected > 0)
{
for (;;)
Kernel::debug("Scroll up event");
for (int i = m_selected - 1; i >= 0; i--)
{
if (m_selected > 0)
if (!m_item[i]->disabled)
{
m_selected -= 1;
scroll_up = true;
Kernel::debug("Scroll up!");
if (!m_item[m_selected]->disabled)
break;
}
if ((m_selected == 0 && m_item[m_selected]->disabled) || (m_selected > 0 && m_item[m_selected - 1]->disabled))
{
Kernel::debug("Cancelled!");
m_selected = prev_selected;
scroll_up = false;
m_selected = i;
break;
}
}
}
if ((e->param1 & MODULE_INPUT_BUTTON_DOWN) == MODULE_INPUT_BUTTON_DOWN)
if ((e->param1 & MODULE_INPUT_BUTTON_DOWN) == MODULE_INPUT_BUTTON_DOWN && m_selected < MODULE_MENU_MAX_OPTIONS - 1)
{
for (;;)
Kernel::debug("Scroll down event");
for (int i = m_selected + 1; i < MODULE_MENU_MAX_OPTIONS; i++)
{
if (m_selected < MODULE_MENU_MAX_OPTIONS && m_item[m_selected + 1] != nullptr)
if (m_item[i] == nullptr)
{
m_selected += 1;
scroll_down = true;
Kernel::debug("Scroll down!");
}
if (!m_item[m_selected]->disabled)
// We've passed the last valid item in the list
break;
if (m_item[m_selected]->disabled && (m_selected == MODULE_MENU_MAX_OPTIONS - 1 || m_item[m_selected + 1] == nullptr))
}
if (!m_item[i]->disabled)
{
Kernel::debug("Cancelled!");
m_selected = prev_selected;
scroll_down = false;
m_selected = i;
break;
}
}
@ -129,29 +114,35 @@ void Module_Menu::tick()
{
m_result_select = true;
hide();
return;
}
if ((e->param1 & MODULE_INPUT_BUTTON_BACK) == MODULE_INPUT_BUTTON_BACK)
{
m_result_cancel = true;
hide();
return;
}
}
if (scroll_up && m_selected < m_scroll_offset)
{
m_scroll_offset -= MODULE_MENU_SHOW_OPTIONS;
if (m_scroll_offset < 0) m_scroll_offset = 0;
}
else if (scroll_down && m_selected >= m_scroll_offset + MODULE_MENU_SHOW_OPTIONS)
// Don't bother with this if we cancelled / selected an item, as we've now hidden the menu.
// Also don't bother if the selected item hasn't changed.
if (!(m_result_select || m_result_cancel) && m_selected != prev_selected)
{
m_scroll_offset += MODULE_MENU_SHOW_OPTIONS;
}
// While selected option is before the first displayed on screen, shift the display earlier in the
// list to try and bring it into view
while (m_selected < m_scroll_offset)
{
m_scroll_offset -= MODULE_MENU_SHOW_OPTIONS;
if (m_scroll_offset < 0) m_scroll_offset = 0;
}
// While selected option is after the last displayed on screen, shift the display later in the list
// to try and bring it into view
while (m_selected >= m_scroll_offset + MODULE_MENU_SHOW_OPTIONS)
{
m_scroll_offset += MODULE_MENU_SHOW_OPTIONS;
}
if (prev_selected != m_selected)
{
// Trigger a redraw
ui->setDirty(m_hwnd);
for (int i = 0; i < MODULE_MENU_SHOW_OPTIONS; i++)
{

2
watchos/__vm/Compile.vmps.xml

File diff suppressed because one or more lines are too long

2
watchos/__vm/Upload.vmps.xml

File diff suppressed because one or more lines are too long

3
watchos/watchos.vcxproj

File diff suppressed because one or more lines are too long

5
watchos/watchos.vcxproj.filters

@ -19,6 +19,7 @@
<None Include="src\arduino folders read me.txt">
<Filter>Misc Files</Filter>
</None>
<None Include="TODO.md" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="__vm\.watchos.vsarduino.h">
@ -104,10 +105,10 @@
<ClCompile Include="Task_Battery.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Task_Menu.cpp">
<ClCompile Include="Module_Menu.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Module_Menu.cpp">
<ClCompile Include="Task_Menu.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>

Loading…
Cancel
Save