mirror of https://github.com/axmolengine/axmol.git
issue #5176, add focus event listener to UIScrollView
This commit is contained in:
parent
3f363f0e51
commit
6d9a21d0ed
|
@ -136,6 +136,10 @@ void ScrollView::onEnter()
|
|||
{
|
||||
Layout::onEnter();
|
||||
scheduleUpdate();
|
||||
_eventListener = EventListenerFocus::create();
|
||||
_eventListener->onFocusChanged = CC_CALLBACK_2(ScrollView::onFocusChanged, this);
|
||||
|
||||
_eventDispatcher->addEventListenerWithFixedPriority(_eventListener, 1);
|
||||
}
|
||||
|
||||
bool ScrollView::init()
|
||||
|
@ -1772,6 +1776,24 @@ Widget* ScrollView::findNextFocusedWidget(cocos2d::ui::Widget::FocusDirection di
|
|||
}
|
||||
}
|
||||
|
||||
void ScrollView::onFocusChanged(cocos2d::ui::Widget *widgetLostFocus, cocos2d::ui::Widget *widgetGetFocus)
|
||||
{
|
||||
if (dynamic_cast<Layout*>(widgetGetFocus) || dynamic_cast<Layout*>(widgetLostFocus)) {
|
||||
return;
|
||||
}
|
||||
if (this->getLayoutType() == Layout::Type::VERTICAL) {
|
||||
float loseFocusWidgetBoundary = widgetLostFocus->getTopInParent();
|
||||
float getFocusWidgetBoundary = widgetGetFocus->getTopInParent();
|
||||
|
||||
if (loseFocusWidgetBoundary >= getFocusWidgetBoundary) {
|
||||
CCLOG("down");
|
||||
}
|
||||
else{
|
||||
CCLOG("up");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
|
|
|
@ -30,6 +30,8 @@ THE SOFTWARE.
|
|||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class EventFocusListener;
|
||||
|
||||
namespace ui {
|
||||
|
||||
class ScrollInnerContainer : public Layout
|
||||
|
@ -382,6 +384,7 @@ protected:
|
|||
void bounceRightEvent();
|
||||
|
||||
|
||||
virtual void onFocusChanged(Widget* widgetLostFocus, Widget* widgetGetFocus);
|
||||
|
||||
protected:
|
||||
Layout* _innerContainer;
|
||||
|
@ -430,7 +433,7 @@ protected:
|
|||
float _bounceOriginalSpeed;
|
||||
bool _inertiaScrollEnabled;
|
||||
|
||||
|
||||
EventListenerFocus *_eventListener;
|
||||
|
||||
Ref* _scrollViewEventListener;
|
||||
#if defined(__GNUC__) && ((__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)))
|
||||
|
|
Loading…
Reference in New Issue