Skip to content

Commit

Permalink
Support handle with size_target resizing from top right corner.
Browse files Browse the repository at this point in the history
As in, size increases when you move cursor up and repositions top of dialog
  • Loading branch information
exjam committed Jan 1, 2025
1 parent 5c80639 commit 05542d6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
21 changes: 20 additions & 1 deletion Source/Core/ElementHandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ ElementHandle::ElementHandle(const String& tag) : Element(tag), drag_start(0, 0)
move_target = nullptr;
size_target = nullptr;
initialised = false;
top_right = false;
}

ElementHandle::~ElementHandle() {}
Expand All @@ -57,6 +58,7 @@ void ElementHandle::OnAttributeChange(const ElementAttributes& changed_attribute
initialised = false;
move_target = nullptr;
size_target = nullptr;
top_right = false;
}
}

Expand All @@ -77,6 +79,9 @@ void ElementHandle::ProcessDefaultAction(Event& event)
if (!size_target_name.empty())
size_target = GetElementById(size_target_name);

if (HasAttribute("top-right"))
top_right = true;

initialised = true;
}

Expand Down Expand Up @@ -132,12 +137,17 @@ void ElementHandle::ProcessDefaultAction(Event& event)

size_original_size = GetSize(box, computed);

if (top_right) {
move_original_position.x = size_target->GetOffsetLeft() - box.GetEdge(BoxArea::Margin, BoxEdge::Left);
move_original_position.y = size_target->GetOffsetTop() - box.GetEdge(BoxArea::Margin, BoxEdge::Top);
}

SetDefiniteMargins(size_target, computed);
}
}
else if (event == EventId::Drag)
{
const Vector2f delta = event.GetUnprojectedMouseScreenPos() - drag_start;
Vector2f delta = event.GetUnprojectedMouseScreenPos() - drag_start;

if (move_target)
{
Expand All @@ -148,9 +158,18 @@ void ElementHandle::ProcessDefaultAction(Event& event)

if (size_target)
{
if (top_right) {
delta.y = -delta.y;
}

const Vector2f new_size = Math::Max((size_original_size + delta).Round(), Vector2f(0.f));
size_target->SetProperty(PropertyId::Width, Property(new_size.x, Unit::PX));
size_target->SetProperty(PropertyId::Height, Property(new_size.y, Unit::PX));

if (top_right) {
const Vector2f new_position = (move_original_position - delta).Round();
size_target->SetProperty(PropertyId::Top, Property(new_position.y, Unit::PX));
}
}

Dictionary parameters;
Expand Down
1 change: 1 addition & 0 deletions Source/Core/ElementHandle.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class RMLUICORE_API ElementHandle : public Element {

Element* move_target;
Element* size_target;
bool top_right;

bool initialised;
};
Expand Down

0 comments on commit 05542d6

Please sign in to comment.