Skip to content

Commit 4b05017

Browse files
committed
Node and Element: Change to new behavior for previously deprecated functions
Rename usage of previously deprecated functions to use the new names.
1 parent 8d3c0e2 commit 4b05017

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+237
-232
lines changed

CMake/Utilities.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ function(set_common_target_options target)
103103

104104
if(RMLUI_COMPILER_OPTIONS)
105105
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU")
106-
target_compile_options(${target} PRIVATE -Wall -Wextra -pedantic -Wno-deprecated-declarations)
106+
target_compile_options(${target} PRIVATE -Wall -Wextra -pedantic)
107107
elseif(MSVC)
108-
target_compile_options(${target} PRIVATE /W4 /w44062 /wd4458 /wd4251 /wd4996 /permissive-)
108+
target_compile_options(${target} PRIVATE /W4 /w44062 /wd4458 /wd4251 /permissive-)
109109
target_compile_definitions(${target} PRIVATE _CRT_SECURE_NO_WARNINGS)
110110
if(CMAKE_GENERATOR MATCHES "Visual Studio")
111111
target_compile_options(${target} PRIVATE /MP)

Include/RmlUi/Core/Element.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -431,20 +431,16 @@ class RMLUICORE_API Element : public Node, public EnableObserverPtr<Element> {
431431
/// Gets the element immediately following this one in the tree.
432432
/// @return This element's next sibling element, or nullptr if there is no sibling element.
433433
Element* GetNextElementSibling() const;
434-
[[deprecated("Use GetNextElementSibling")]] Element* GetNextSibling() const;
435434
/// Gets the element immediately preceding this one in the tree.
436435
/// @return This element's previous sibling element, or nullptr if there is no sibling element.
437436
Element* GetPreviousElementSibling() const;
438-
[[deprecated("Use GetPreviousElementSibling")]] Element* GetPreviousSibling() const;
439437

440438
/// Returns the first child of this element.
441439
/// @return This element's first child, or nullptr if it contains no children.
442440
Element* GetFirstElementChild() const;
443-
[[deprecated("Use GetFirstElementChild")]] Element* GetFirstChild() const;
444441
/// Gets the last child of this element.
445442
/// @return This element's last child, or nullptr if it contains no children.
446443
Element* GetLastElementChild() const;
447-
[[deprecated("Use GetLastElementChild")]] Element* GetLastChild() const;
448444
/// Get the child element at the given index.
449445
/// @param[in] index Index of child to get.
450446
/// @return The child element at the given index.

Include/RmlUi/Core/Node.h

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class Context;
3939
class Element;
4040
class ElementDocument;
4141
class NodeInstancer;
42+
class NodePtrProxy;
4243
using OwnedNodeList = Vector<NodePtr>;
4344

4445
/**
@@ -62,34 +63,43 @@ class RMLUICORE_API Node : public ScriptInterface {
6263
/// @return True if the node has at least one DOM child, false otherwise.
6364
bool HasChildNodes() const;
6465

66+
/// Returns the first child of this node.
67+
/// @return This node's first child, or nullptr if it contains no children.
68+
Node* GetFirstChild() const;
69+
/// Gets the last child of this node.
70+
/// @return This node's last child, or nullptr if it contains no children.
71+
Node* GetLastChild() const;
72+
/// Gets the node immediately following this one in the tree.
73+
/// @return This node's next sibling node, or nullptr if there is no sibling node.
74+
Node* GetNextSibling() const;
75+
/// Gets the node immediately preceding this one in the tree.
76+
/// @return This node's previous sibling node, or nullptr if there is no sibling node.
77+
Node* GetPreviousSibling() const;
78+
6579
/// Append a child to this node.
6680
/// @param[in] node The node to append as a child.
6781
/// @param[in] dom_node True if the node is to be part of the DOM, false otherwise. Only set this to false if you know what you're doing!
6882
/// @return A pointer to the just inserted node.
69-
Node* AppendChild(NodePtr node, bool dom_node = true);
70-
[[deprecated("Use the NodePtr version of this function")]] Element* AppendChild(ElementPtr element, bool dom_element = true);
83+
Node* AppendChild(NodePtrProxy node, bool dom_node = true);
7184
/// Adds a child to this node directly before the adjacent node. The new node inherits the DOM/non-DOM
7285
/// status from the adjacent node.
7386
/// @param[in] node Node to be inserted.
7487
/// @param[in] adjacent_node The reference node which the new node will be inserted before.
7588
/// @return A pointer to the just inserted node.
76-
Node* InsertBefore(NodePtr node, Node* adjacent_node);
77-
[[deprecated("Use the NodePtr version of this function")]] Element* InsertBefore(ElementPtr element, Element* adjacent_element);
89+
Node* InsertBefore(NodePtrProxy node, Node* adjacent_node);
7890
/// Replaces the second node with the first node.
7991
/// @param[in] inserted_node The node that will be inserted and replace the other node.
8092
/// @param[in] replaced_node The existing node that will be replaced. If this doesn't exist, inserted_node will be appended.
8193
/// @return A unique pointer to the replaced node if found, discard the result to immediately destroy.
82-
NodePtr ReplaceChild(NodePtr inserted_node, Node* replaced_node);
83-
[[deprecated("Use the NodePtr version of this function")]] ElementPtr ReplaceChild(ElementPtr inserted_element, Element* replaced_element);
94+
NodePtr ReplaceChild(NodePtrProxy inserted_node, Node* replaced_node);
8495
/// Remove a child node from this node.
8596
/// @param[in] node The node to remove.
8697
/// @return A unique pointer to the node if found, discard the result to immediately destroy.
8798
NodePtr RemoveChild(Node* node);
88-
[[deprecated("Use the NodePtr version of this function")]] ElementPtr RemoveChild(Element* element);
8999

90100
/// Gets this nodes's parent node.
91101
/// @return This node's parent.
92-
[[deprecated("Use GetParentElement")]] Element* GetParentNode() const;
102+
Node* GetParentNode() const;
93103
/// Gets this nodes's parent element.
94104
/// @return This node's parent if it is an element, otherwise false.
95105
Element* GetParentElement() const;
@@ -311,6 +321,18 @@ class RMLUICORE_API Node : public ScriptInterface {
311321
friend class Rml::Context;
312322
};
313323

324+
class RMLUICORE_API NodePtrProxy {
325+
public:
326+
NodePtrProxy(NodePtr node);
327+
NodePtrProxy(ElementPtr element);
328+
Node* Get();
329+
NodePtr Extract();
330+
explicit operator bool() const;
331+
332+
private:
333+
NodePtr node;
334+
};
335+
314336
} // namespace Rml
315337

316338
#endif

Samples/basic/demo/src/DemoEventListener.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ void DemoEventListener::ProcessEvent(Rml::Event& event)
5353
else if (value == "move_child")
5454
{
5555
const Vector2f mouse_pos = {event.GetParameter("mouse_x", 0.0f), event.GetParameter("mouse_y", 0.0f)};
56-
if (Element* child = element->GetFirstChild())
56+
if (Element* child = element->GetFirstElementChild())
5757
{
5858
Vector2f new_pos = mouse_pos - element->GetAbsoluteOffset() - Vector2f(0.35f * child->GetClientWidth(), 0.9f * child->GetClientHeight());
5959
Property destination = Transform::MakeProperty({Transforms::Translate2D(new_pos.x, new_pos.y)});

Samples/basic/demo/src/DemoWindow.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ bool DemoWindow::Initialize(const Rml::String& title, Rml::Context* context)
7272
if (auto target = document->GetElementById("sandbox_target"))
7373
{
7474
iframe = context->CreateDocument();
75-
auto iframe_ptr = iframe->GetParentNode()->RemoveChild(iframe);
76-
target->AppendChild(std::move(iframe_ptr));
75+
target->AppendChild(iframe->Remove());
7776
iframe->SetProperty(PropertyId::Position, Property(Style::Position::Absolute));
7877
iframe->SetProperty(PropertyId::Display, Property(Style::Display::Block));
7978
iframe->SetInnerRML("<p>Rendered output goes here.</p>");

Samples/basic/drag/src/DragListener.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ void DragListener::ProcessEvent(Rml::Event& event)
4747
if (dest_container == dest_element)
4848
{
4949
// The dragged element was dragged directly onto a container.
50-
Rml::ElementPtr element = drag_element->GetParentNode()->RemoveChild(drag_element);
51-
dest_container->AppendChild(std::move(element));
50+
dest_container->AppendChild(drag_element->Remove());
5251
}
5352
else
5453
{
@@ -59,25 +58,25 @@ void DragListener::ProcessEvent(Rml::Event& event)
5958

6059
// Unless of course if it was dragged on top of an item in its own container; we need
6160
// to check then if it was moved up or down with the container.
62-
if (drag_element->GetParentNode() == dest_container)
61+
if (drag_element->GetParentElement() == dest_container)
6362
{
6463
// Check whether we're moving this icon from the left or the right.
6564

66-
Rml::Element* previous_icon = insert_before->GetPreviousSibling();
65+
Rml::Element* previous_icon = insert_before->GetPreviousElementSibling();
6766
while (previous_icon != nullptr)
6867
{
6968
if (previous_icon == drag_element)
7069
{
71-
insert_before = insert_before->GetNextSibling();
70+
insert_before = insert_before->GetNextElementSibling();
7271
break;
7372
}
7473

75-
previous_icon = previous_icon->GetPreviousSibling();
74+
previous_icon = previous_icon->GetPreviousElementSibling();
7675
}
7776
}
7877

79-
Rml::ElementPtr element = drag_element->GetParentNode()->RemoveChild(drag_element);
80-
dest_container->InsertBefore(std::move(element), insert_before);
78+
Rml::NodePtr node = drag_element->GetParentElement()->RemoveChild(drag_element);
79+
dest_container->InsertBefore(std::move(node), insert_before);
8180
}
8281
}
8382
}

Samples/basic/drag/src/Inventory.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,6 @@ void Inventory::AddItem(const Rml::String& name)
6363
return;
6464

6565
// Create the new 'icon' element.
66-
Rml::Element* icon = content->AppendChild(Rml::As<Rml::ElementPtr>(Rml::Factory::InstanceNode("icon", "icon")));
66+
Rml::Element* icon = Rml::As<Rml::Element*>(content->AppendChild(Rml::Factory::InstanceNode("icon", "icon")));
6767
icon->SetInnerRML(name);
6868
}

Samples/tutorial/drag/src/Inventory.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ void Inventory::AddItem(const Rml::String& name)
2929
return;
3030

3131
// Create the new 'icon' element.
32-
Rml::Element* icon = content->AppendChild(Rml::As<Rml::ElementPtr>(Rml::Factory::InstanceNode("icon", "icon")));
32+
Rml::Element* icon = Rml::As<Rml::Element*>(content->AppendChild(Rml::Factory::InstanceNode("icon", "icon")));
3333
icon->SetInnerRML(name);
3434
}

Source/Core/Context.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -363,8 +363,8 @@ void Context::UnloadDocument(ElementDocument* _document)
363363
document->DispatchEvent(EventId::Unload, Dictionary());
364364
PluginRegistry::NotifyDocumentUnload(document);
365365

366-
// Move document to a temporary location to be released later.
367-
unloaded_documents.push_back(root->RemoveChild(document));
366+
// Remove from root and place document in a temporary location to be released later.
367+
unloaded_documents.push_back(document->Remove());
368368
}
369369

370370
// Remove the item from the focus history.
@@ -635,7 +635,7 @@ static Element* FindFocusElement(Element* element)
635635

636636
while (element && element->GetComputedValues().focus() == Style::Focus::None)
637637
{
638-
element = element->GetParentNode();
638+
element = element->GetParentElement();
639639
}
640640

641641
return element;
@@ -710,7 +710,7 @@ bool Context::ProcessMouseButtonDown(int button_index, int key_modifier_state)
710710
Style::Drag drag_style = drag->GetComputedValues().drag();
711711
switch (drag_style)
712712
{
713-
case Style::Drag::None: drag = drag->GetParentNode(); continue;
713+
case Style::Drag::None: drag = drag->GetParentElement(); continue;
714714
case Style::Drag::Block: drag = nullptr; continue;
715715
default: drag_verbose = (drag_style == Style::Drag::DragDrop || drag_style == Style::Drag::Clone);
716716
}
@@ -1233,15 +1233,15 @@ bool Context::OnFocusChange(Element* new_focus, bool focus_visible)
12331233
while (element)
12341234
{
12351235
old_chain.insert(element);
1236-
element = element->GetParentNode();
1236+
element = element->GetParentElement();
12371237
}
12381238

12391239
// Build the new chain
12401240
element = new_focus;
12411241
while (element)
12421242
{
12431243
new_chain.insert(element);
1244-
element = element->GetParentNode();
1244+
element = element->GetParentElement();
12451245
}
12461246

12471247
// Send out blur/focus events.
@@ -1353,7 +1353,7 @@ void Context::UpdateHoverChain(Vector2i old_mouse_position, int key_modifier_sta
13531353
while (element != nullptr)
13541354
{
13551355
new_hover_chain.insert(element);
1356-
element = element->GetParentNode();
1356+
element = element->GetParentElement();
13571357
}
13581358

13591359
// Send mouseout / mouseover events.
@@ -1370,7 +1370,7 @@ void Context::UpdateHoverChain(Vector2i old_mouse_position, int key_modifier_sta
13701370
while (element != nullptr)
13711371
{
13721372
new_drag_hover_chain.insert(element);
1373-
element = element->GetParentNode();
1373+
element = element->GetParentElement();
13741374
}
13751375

13761376
if (drag_started && drag_verbose)
@@ -1427,7 +1427,7 @@ Element* Context::GetElementAtPoint(Vector2f point, const Element* ignore_elemen
14271427
if (element_hierarchy == ignore_element)
14281428
break;
14291429

1430-
element_hierarchy = element_hierarchy->GetParentNode();
1430+
element_hierarchy = element_hierarchy->GetParentElement();
14311431
}
14321432

14331433
if (element_hierarchy)
@@ -1495,12 +1495,12 @@ void Context::CreateDragClone(Element* element)
14951495
drag_clone = element_drag_clone.get();
14961496

14971497
// Append the clone to the cursor proxy element.
1498-
cursor_proxy->AppendChild(std::move(element_drag_clone));
1498+
cursor_proxy->AppendChild(As<NodePtr>(std::move(element_drag_clone)));
14991499

15001500
// Position the clone. Use projected mouse coordinates to handle any ancestor transforms.
15011501
const Vector2f absolute_pos = element->GetAbsoluteOffset(BoxArea::Border);
15021502
Vector2f projected_mouse_position = Vector2f(mouse_position);
1503-
if (Element* parent = element->GetParentNode())
1503+
if (Element* parent = element->GetParentElement())
15041504
parent->Project(projected_mouse_position);
15051505

15061506
drag_clone->SetProperty(PropertyId::Position, Property(Style::Position::Absolute));

Source/Core/DataModel.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ void DataModel::CopyAliases(Element* from_element, Element* to_element)
244244
{
245245
// Need to create a copy to prevent errors during concurrent modification for 3rd party containers
246246
auto copy = existing_map->second;
247-
for (auto const& it : copy)
247+
for (const auto& it : copy)
248248
aliases[to_element][it.first] = std::move(it.second);
249249
}
250250
}
@@ -288,7 +288,7 @@ DataAddress DataModel::ResolveAddress(const String& address_str, Element* elemen
288288
}
289289
}
290290

291-
ancestor = ancestor->GetParentNode();
291+
ancestor = ancestor->GetParentElement();
292292
}
293293

294294
Log::Message(Log::LT_WARNING, "Could not find variable name '%s' in data model.", address_str.c_str());

0 commit comments

Comments
 (0)