--------------------------------- EditorSplitNode::AdjustLayout Set the pane position once the widget is realized
| 85 | // Set the pane position once the widget is realized |
| 86 | // |
| 87 | void EditorSplitNode::AdjustLayout() |
| 88 | { |
| 89 | if (m_LayoutAdjusted) |
| 90 | { |
| 91 | return; |
| 92 | } |
| 93 | |
| 94 | // set the position of the handle |
| 95 | int32 size = 0; |
| 96 | |
| 97 | if (m_IsHorizontal) |
| 98 | { |
| 99 | size = m_Attachment->get_allocated_width(); |
| 100 | } |
| 101 | else |
| 102 | { |
| 103 | size = m_Attachment->get_allocated_height(); |
| 104 | } |
| 105 | |
| 106 | m_Paned->set_position(static_cast<int32>(m_SplitRatio * static_cast<float>(size))); |
| 107 | |
| 108 | // propagate this to children |
| 109 | if (!(m_Child1->IsLeaf())) |
| 110 | { |
| 111 | static_cast<EditorSplitNode*>(m_Child1)->AdjustLayout(); |
| 112 | } |
| 113 | |
| 114 | if (!(m_Child2->IsLeaf())) |
| 115 | { |
| 116 | static_cast<EditorSplitNode*>(m_Child2)->AdjustLayout(); |
| 117 | } |
| 118 | |
| 119 | m_LayoutAdjusted = true; |
| 120 | |
| 121 | // ensure the split ratio is updated if the user drags the handle |
| 122 | auto positionChangedCallback = [this]() |
| 123 | { |
| 124 | if (!m_LayoutAdjusted) |
| 125 | { |
| 126 | return; |
| 127 | } |
| 128 | |
| 129 | float size = 0.f; |
| 130 | if (m_IsHorizontal) |
| 131 | { |
| 132 | size = static_cast<float>(m_Attachment->get_allocated_width()); |
| 133 | } |
| 134 | else |
| 135 | { |
| 136 | size = static_cast<float>(m_Attachment->get_allocated_height()); |
| 137 | } |
| 138 | |
| 139 | if (size == 0.f) |
| 140 | { |
| 141 | return; |
| 142 | } |
| 143 | |
| 144 | m_SplitRatio = static_cast<float>(m_Paned->get_position()) / size; |
no test coverage detected