Editor Improvement

Share your helpful Urho3D code snippets, samples and tutorials here.

Editor Improvement

PostPosted by artgolf1000 » 23 Oct 2016, 02:40

Hi,

If using free UI layout in a certain window, I want to drag UI elements to proper places, so I added the function when GUI interface hides to speed up UI layout design.

Note that you need to check the property of 'Is Enabled' of a UI element before you can drag it.

Here is the modified part of Urho3D/bin/Data/Scripts/Editor/EditorUI.as

Code: Select all
...
IntVector2 dragBeginElementPosition;
IntVector2 dragBeginPosition;
...
void HandleDragBegin(StringHash eventType, VariantMap& eventData)
{
    UIElement@ uiElement = eventData["Element"].GetPtr();
    if (uiElement is null)
        return;

    dragBeginElementPosition = uiElement.position;
    dragBeginPosition = IntVector2(eventData["X"].GetInt(), eventData["Y"].GetInt());
}

void HandleDragMove(StringHash eventType, VariantMap& eventData)
{
    UIElement@ uiElement = eventData["Element"].GetPtr();
    if (uiElement is null)
        return;

    IntVector2 dragCurrentPosition = IntVector2(eventData["X"].GetInt(), eventData["Y"].GetInt());
    uiElement.position = dragBeginElementPosition + (dragCurrentPosition - dragBeginPosition);
}

void HandleDragEnd(StringHash eventType, VariantMap& eventData)
{
    UIElement@ uiElement = eventData["Element"].GetPtr();
    if (uiElement is null)
        return;

    // Do nothing
}

void HideUI(bool hide = true)
{
    if (uiHidden == hide) {
        return;
    }

    if (hide) {
       SubscribeToEvent("DragBegin", "HandleDragBegin");
       SubscribeToEvent("DragMove", "HandleDragMove");
       SubscribeToEvent("DragEnd", "HandleDragEnd");
    } else {
       UnsubscribeFromEvent("DragBegin");
       UnsubscribeFromEvent("DragMove");
       UnsubscribeFromEvent("DragEnd");
    }
    ...
}
User avatar
artgolf1000
Have some posts
Have some posts
 
Posts: 38
Joined: 31 Aug 2016, 08:49

Return to Code Exchange

Who is online

Users browsing this forum: No registered users and 0 guests

cron