Added new ItemClicked event for ListView items which is also sent for right-clicks. ItemDoubleClicked is also sent also for right-clicks now. Added more event parameters to ItemClicked & ItemDoubleClicked events. Closes #88.
This commit is contained in:
parent
4da5b49361
commit
c61a5e6f01
@ -7773,9 +7773,21 @@ Properties:
|
||||
### SelectionChanged
|
||||
- %Element : UIElement pointer
|
||||
|
||||
### ItemClicked
|
||||
- %Element : UIElement pointer
|
||||
- %Item : UIElement pointer
|
||||
- %Selection : int
|
||||
- %Button : int
|
||||
- %Buttons : int
|
||||
- %Qualifiers : int
|
||||
|
||||
### ItemDoubleClicked
|
||||
- %Element : UIElement pointer
|
||||
- %Item : UIElement pointer
|
||||
- %Selection : int
|
||||
- %Button : int
|
||||
- %Buttons : int
|
||||
- %Qualifiers : int
|
||||
|
||||
### UnhandledKey
|
||||
- %Element : UIElement pointer
|
||||
|
@ -428,7 +428,8 @@ void FileSelector::HandleFileDoubleClicked(StringHash eventType, VariantMap& eve
|
||||
if (ignoreEvents_)
|
||||
return;
|
||||
|
||||
EnterFile();
|
||||
if (eventData[ItemDoubleClicked::P_BUTTON] == MOUSEB_LEFT)
|
||||
EnterFile();
|
||||
}
|
||||
|
||||
void FileSelector::HandleFileListKey(StringHash eventType, VariantMap& eventData)
|
||||
|
@ -923,8 +923,8 @@ void ListView::EnsureItemVisibility(UIElement* item)
|
||||
|
||||
void ListView::HandleUIMouseClick(StringHash eventType, VariantMap& eventData)
|
||||
{
|
||||
if (eventData[UIMouseClick::P_BUTTON].GetInt() != MOUSEB_LEFT)
|
||||
return;
|
||||
int button = eventData[UIMouseClick::P_BUTTON].GetInt();
|
||||
int buttons = eventData[UIMouseClick::P_BUTTONS].GetInt();
|
||||
int qualifiers = eventData[UIMouseClick::P_QUALIFIERS].GetInt();
|
||||
|
||||
UIElement* element = static_cast<UIElement*>(eventData[UIMouseClick::P_ELEMENT].GetPtr());
|
||||
@ -936,62 +936,75 @@ void ListView::HandleUIMouseClick(StringHash eventType, VariantMap& eventData)
|
||||
return;
|
||||
}
|
||||
|
||||
/// \todo Should not be doing a linear search of all items
|
||||
unsigned numItems = GetNumItems();
|
||||
for (unsigned i = 0; i < numItems; ++i)
|
||||
{
|
||||
if (element == GetItem(i))
|
||||
{
|
||||
// Single selection
|
||||
if (!multiselect_ || !qualifiers)
|
||||
SetSelection(i);
|
||||
|
||||
// Check multiselect with shift & ctrl
|
||||
if (multiselect_)
|
||||
if (button == MOUSEB_LEFT)
|
||||
{
|
||||
if (qualifiers & QUAL_SHIFT)
|
||||
{
|
||||
if (selections_.Empty())
|
||||
SetSelection(i);
|
||||
else
|
||||
{
|
||||
unsigned first = selections_.Front();
|
||||
unsigned last = selections_.Back();
|
||||
PODVector<unsigned> newSelections = selections_;
|
||||
if (i == first || i == last)
|
||||
{
|
||||
for (unsigned j = first; j <= last; ++j)
|
||||
newSelections.Push(j);
|
||||
}
|
||||
else if (i < first)
|
||||
{
|
||||
for (unsigned j = i; j <= first; ++j)
|
||||
newSelections.Push(j);
|
||||
}
|
||||
else if (i < last)
|
||||
{
|
||||
if ((abs((int)i - (int)first)) <= (abs((int)i - (int)last)))
|
||||
{
|
||||
for (unsigned j = first; j <= i; ++j)
|
||||
newSelections.Push(j);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (unsigned j = i; j <= last; ++j)
|
||||
newSelections.Push(j);
|
||||
}
|
||||
}
|
||||
else if (i > last)
|
||||
{
|
||||
for (unsigned j = last; j <= i; ++j)
|
||||
newSelections.Push(j);
|
||||
}
|
||||
SetSelections(newSelections);
|
||||
}
|
||||
}
|
||||
else if (qualifiers & QUAL_CTRL)
|
||||
ToggleSelection(i);
|
||||
}
|
||||
// Single selection
|
||||
if (!multiselect_ || !qualifiers)
|
||||
SetSelection(i);
|
||||
|
||||
// Check multiselect with shift & ctrl
|
||||
if (multiselect_)
|
||||
{
|
||||
if (qualifiers & QUAL_SHIFT)
|
||||
{
|
||||
if (selections_.Empty())
|
||||
SetSelection(i);
|
||||
else
|
||||
{
|
||||
unsigned first = selections_.Front();
|
||||
unsigned last = selections_.Back();
|
||||
PODVector<unsigned> newSelections = selections_;
|
||||
if (i == first || i == last)
|
||||
{
|
||||
for (unsigned j = first; j <= last; ++j)
|
||||
newSelections.Push(j);
|
||||
}
|
||||
else if (i < first)
|
||||
{
|
||||
for (unsigned j = i; j <= first; ++j)
|
||||
newSelections.Push(j);
|
||||
}
|
||||
else if (i < last)
|
||||
{
|
||||
if ((abs((int)i - (int)first)) <= (abs((int)i - (int)last)))
|
||||
{
|
||||
for (unsigned j = first; j <= i; ++j)
|
||||
newSelections.Push(j);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (unsigned j = i; j <= last; ++j)
|
||||
newSelections.Push(j);
|
||||
}
|
||||
}
|
||||
else if (i > last)
|
||||
{
|
||||
for (unsigned j = last; j <= i; ++j)
|
||||
newSelections.Push(j);
|
||||
}
|
||||
SetSelections(newSelections);
|
||||
}
|
||||
}
|
||||
else if (qualifiers & QUAL_CTRL)
|
||||
ToggleSelection(i);
|
||||
}
|
||||
}
|
||||
|
||||
// Propagate the click as an event. Also include right-clicks
|
||||
VariantMap clickEventData;
|
||||
clickEventData[ItemClicked::P_ELEMENT] = (void*)this;
|
||||
clickEventData[ItemClicked::P_ITEM] = (void*)element;
|
||||
clickEventData[ItemClicked::P_SELECTION] = i;
|
||||
clickEventData[ItemClicked::P_BUTTON] = button;
|
||||
clickEventData[ItemClicked::P_BUTTONS] = buttons;
|
||||
clickEventData[ItemClicked::P_QUALIFIERS] = qualifiers;
|
||||
SendEvent(E_ITEMCLICKED, clickEventData);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -999,19 +1012,26 @@ void ListView::HandleUIMouseClick(StringHash eventType, VariantMap& eventData)
|
||||
|
||||
void ListView::HandleUIMouseDoubleClick(StringHash eventType, VariantMap& eventData)
|
||||
{
|
||||
if (eventData[UIMouseClick::P_BUTTON].GetInt() != MOUSEB_LEFT)
|
||||
return;
|
||||
int button = eventData[UIMouseClick::P_BUTTON].GetInt();
|
||||
int buttons = eventData[UIMouseClick::P_BUTTONS].GetInt();
|
||||
int qualifiers = eventData[UIMouseClick::P_QUALIFIERS].GetInt();
|
||||
|
||||
UIElement* element = static_cast<UIElement*>(eventData[UIMouseClick::P_ELEMENT].GetPtr());
|
||||
|
||||
/// \todo Should not be doing a linear search of all items
|
||||
unsigned numItems = GetNumItems();
|
||||
for (unsigned i = 0; i < numItems; ++i)
|
||||
{
|
||||
if (element == GetItem(i))
|
||||
{
|
||||
VariantMap eventData;
|
||||
eventData[ItemDoubleClicked::P_ELEMENT] = (void*)this;
|
||||
eventData[ItemDoubleClicked::P_SELECTION] = i;
|
||||
SendEvent(E_ITEMDOUBLECLICKED, eventData);
|
||||
VariantMap clickEventData;
|
||||
clickEventData[ItemDoubleClicked::P_ELEMENT] = (void*)this;
|
||||
clickEventData[ItemDoubleClicked::P_ITEM] = (void*)element;
|
||||
clickEventData[ItemDoubleClicked::P_SELECTION] = i;
|
||||
clickEventData[ItemDoubleClicked::P_BUTTON] = button;
|
||||
clickEventData[ItemDoubleClicked::P_BUTTONS] = buttons;
|
||||
clickEventData[ItemDoubleClicked::P_QUALIFIERS] = qualifiers;
|
||||
SendEvent(E_ITEMDOUBLECLICKED, clickEventData);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ enum LayoutMode
|
||||
LM_VERTICAL
|
||||
};
|
||||
|
||||
/// Traversal mode.
|
||||
/// Traversal mode for rendering.
|
||||
enum TraversalMode
|
||||
{
|
||||
/// Traverse thru children having same priority first and recurse into their children before traversing children having higher priority.
|
||||
@ -311,7 +311,7 @@ public:
|
||||
void SetVar(ShortStringHash key, const Variant& value);
|
||||
/// Mark as internally (programmatically) created. Used when an element composes itself out of child elements.
|
||||
void SetInternal(bool enable);
|
||||
/// Set traversal mode. The default traversal mode is TM_BREADTH_FIRST for non-root element. Root element should be set to TM_DEPTH_FIRST to avoid artifacts during rendering.
|
||||
/// Set traversal mode for rendering. The default traversal mode is TM_BREADTH_FIRST for non-root element. Root element should be set to TM_DEPTH_FIRST to avoid artifacts during rendering.
|
||||
void SetTraversalMode(TraversalMode traversalMode);
|
||||
/// Set element event sender flag. When child element is added or deleted, the event would be sent using UIElement found in the parental chain having this flag set. If not set, the event is sent using UI's root as per normal.
|
||||
void SetElementEventSender(bool flag);
|
||||
@ -458,7 +458,7 @@ public:
|
||||
currentScissor);
|
||||
/// Return color attribute. Uses just the top-left color.
|
||||
const Color& GetColorAttr() const { return color_[0]; }
|
||||
/// Return traversal mode.
|
||||
/// Return traversal mode for rendering.
|
||||
TraversalMode GetTraversalMode() const { return traversalMode_; }
|
||||
/// Return whether element should send child added / removed events by itself. If false, defers to parent element.
|
||||
bool IsElementEventSender() const { return elementEventSender_; }
|
||||
@ -584,7 +584,7 @@ private:
|
||||
bool colorGradient_;
|
||||
/// Default style file.
|
||||
SharedPtr<XMLFile> defaultStyle_;
|
||||
/// Traversal mode.
|
||||
/// Traversal mode for rendering.
|
||||
TraversalMode traversalMode_;
|
||||
/// Flag whether node should send child added / removed events by itself.
|
||||
bool elementEventSender_;
|
||||
|
@ -227,11 +227,26 @@ EVENT(E_SELECTIONCHANGED, SelectionChanged)
|
||||
PARAM(P_ELEMENT, Element); // UIElement pointer
|
||||
}
|
||||
|
||||
/// Listview item clicked. If this is a left-click, also ItemSelected event will be sent. If this is a right-click, only this event is sent.
|
||||
EVENT(E_ITEMCLICKED, ItemClicked)
|
||||
{
|
||||
PARAM(P_ELEMENT, Element); // UIElement pointer
|
||||
PARAM(P_ITEM, Item); // UIElement pointer
|
||||
PARAM(P_SELECTION, Selection); // int
|
||||
PARAM(P_BUTTON, Button); // int
|
||||
PARAM(P_BUTTONS, Buttons); // int
|
||||
PARAM(P_QUALIFIERS, Qualifiers); // int
|
||||
}
|
||||
|
||||
/// Listview item double clicked.
|
||||
EVENT(E_ITEMDOUBLECLICKED, ItemDoubleClicked)
|
||||
{
|
||||
PARAM(P_ELEMENT, Element); // UIElement pointer
|
||||
PARAM(P_ITEM, Item); // UIElement pointer
|
||||
PARAM(P_SELECTION, Selection); // int
|
||||
PARAM(P_BUTTON, Button); // int
|
||||
PARAM(P_BUTTONS, Buttons); // int
|
||||
PARAM(P_QUALIFIERS, Qualifiers); // int
|
||||
}
|
||||
|
||||
/// LineEdit or ListView unhandled key pressed.
|
||||
|
Loading…
Reference in New Issue
Block a user