mirror of
https://github.com/apache/nuttx-apps.git
synced 2025-07-17 19:51:03 +08:00
NxWidgets: Fix CListBox crash when clicked below the last item
This commit is contained in:
parent
8f305416ed
commit
cb3dc4d544
@ -1,7 +1,7 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* NxWidgets/libnxwidgets/include/clistdata.hxx
|
* NxWidgets/libnxwidgets/include/clistdata.hxx
|
||||||
*
|
*
|
||||||
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2012, 2016 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@ -258,9 +258,16 @@ namespace NXWidgets
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
virtual inline const CListDataItem *getItem(const int index) const
|
virtual inline const CListDataItem *getItem(const int index) const
|
||||||
|
{
|
||||||
|
if (index < 0 || index >= m_items.size())
|
||||||
|
{
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
return m_items[index];
|
return m_items[index];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sort the items using their compareTo() methods.
|
* Sort the items using their compareTo() methods.
|
||||||
|
@ -607,6 +607,11 @@ void CListBox::onClick(nxgl_coord_t x, nxgl_coord_t y)
|
|||||||
const CListBoxDataItem *item =
|
const CListBoxDataItem *item =
|
||||||
(const CListBoxDataItem*)m_options.getItem(m_lastSelectedIndex);
|
(const CListBoxDataItem*)m_options.getItem(m_lastSelectedIndex);
|
||||||
|
|
||||||
|
if (!item)
|
||||||
|
{
|
||||||
|
return; // No item at click position
|
||||||
|
}
|
||||||
|
|
||||||
// Are we selecting or de-selecting?
|
// Are we selecting or de-selecting?
|
||||||
|
|
||||||
if (item->isSelected())
|
if (item->isSelected())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user