Sdk/Canvas: Rename widgetbox to widgetentry
This commit is contained in:
parent
c435923533
commit
4116984f9f
|
|
@ -56,7 +56,7 @@ namespace Ndk
|
||||||
void OnEventKeyReleased(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::KeyEvent& event);
|
void OnEventKeyReleased(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::KeyEvent& event);
|
||||||
void OnEventTextEntered(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::TextEvent& event);
|
void OnEventTextEntered(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::TextEvent& event);
|
||||||
|
|
||||||
struct WidgetBox
|
struct WidgetEntry
|
||||||
{
|
{
|
||||||
BaseWidget* widget;
|
BaseWidget* widget;
|
||||||
Nz::Boxf box;
|
Nz::Boxf box;
|
||||||
|
|
@ -73,7 +73,7 @@ namespace Ndk
|
||||||
|
|
||||||
std::size_t m_keyboardOwner;
|
std::size_t m_keyboardOwner;
|
||||||
std::size_t m_hoveredWidget;
|
std::size_t m_hoveredWidget;
|
||||||
std::vector<WidgetBox> m_widgetBoxes;
|
std::vector<WidgetEntry> m_widgetEntries;
|
||||||
Nz::CursorControllerHandle m_cursorController;
|
Nz::CursorControllerHandle m_cursorController;
|
||||||
WorldHandle m_world;
|
WorldHandle m_world;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,7 @@ namespace Ndk
|
||||||
|
|
||||||
inline void Canvas::NotifyWidgetBoxUpdate(std::size_t index)
|
inline void Canvas::NotifyWidgetBoxUpdate(std::size_t index)
|
||||||
{
|
{
|
||||||
WidgetBox& entry = m_widgetBoxes[index];
|
WidgetEntry& entry = m_widgetEntries[index];
|
||||||
|
|
||||||
Nz::Vector3f pos = entry.widget->GetPosition();
|
Nz::Vector3f pos = entry.widget->GetPosition();
|
||||||
Nz::Vector2f size = entry.widget->GetContentSize();
|
Nz::Vector2f size = entry.widget->GetContentSize();
|
||||||
|
|
@ -69,7 +69,7 @@ namespace Ndk
|
||||||
|
|
||||||
inline void Canvas::NotifyWidgetCursorUpdate(std::size_t index)
|
inline void Canvas::NotifyWidgetCursorUpdate(std::size_t index)
|
||||||
{
|
{
|
||||||
WidgetBox& entry = m_widgetBoxes[index];
|
WidgetEntry& entry = m_widgetEntries[index];
|
||||||
|
|
||||||
entry.cursor = entry.widget->GetCursor();
|
entry.cursor = entry.widget->GetCursor();
|
||||||
if (m_cursorController && m_hoveredWidget == index)
|
if (m_cursorController && m_hoveredWidget == index)
|
||||||
|
|
@ -81,12 +81,12 @@ namespace Ndk
|
||||||
if (m_keyboardOwner != canvasIndex)
|
if (m_keyboardOwner != canvasIndex)
|
||||||
{
|
{
|
||||||
if (m_keyboardOwner != InvalidCanvasIndex)
|
if (m_keyboardOwner != InvalidCanvasIndex)
|
||||||
m_widgetBoxes[m_keyboardOwner].widget->OnFocusLost();
|
m_widgetEntries[m_keyboardOwner].widget->OnFocusLost();
|
||||||
|
|
||||||
m_keyboardOwner = canvasIndex;
|
m_keyboardOwner = canvasIndex;
|
||||||
|
|
||||||
if (m_keyboardOwner != InvalidCanvasIndex)
|
if (m_keyboardOwner != InvalidCanvasIndex)
|
||||||
m_widgetBoxes[m_keyboardOwner].widget->OnFocusReceived();
|
m_widgetEntries[m_keyboardOwner].widget->OnFocusReceived();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -73,6 +73,7 @@ namespace Ndk
|
||||||
private:
|
private:
|
||||||
void Layout() override;
|
void Layout() override;
|
||||||
|
|
||||||
|
bool IsFocusable() const override;
|
||||||
void OnFocusLost() override;
|
void OnFocusLost() override;
|
||||||
void OnFocusReceived() override;
|
void OnFocusReceived() override;
|
||||||
void OnKeyPressed(const Nz::WindowEvent::KeyEvent& key) override;
|
void OnKeyPressed(const Nz::WindowEvent::KeyEvent& key) override;
|
||||||
|
|
|
||||||
|
|
@ -13,12 +13,12 @@ namespace Ndk
|
||||||
|
|
||||||
std::size_t Canvas::RegisterWidget(BaseWidget* widget)
|
std::size_t Canvas::RegisterWidget(BaseWidget* widget)
|
||||||
{
|
{
|
||||||
WidgetBox box;
|
WidgetEntry box;
|
||||||
box.cursor = widget->GetCursor();
|
box.cursor = widget->GetCursor();
|
||||||
box.widget = widget;
|
box.widget = widget;
|
||||||
|
|
||||||
std::size_t index = m_widgetBoxes.size();
|
std::size_t index = m_widgetEntries.size();
|
||||||
m_widgetBoxes.emplace_back(box);
|
m_widgetEntries.emplace_back(box);
|
||||||
|
|
||||||
NotifyWidgetBoxUpdate(index);
|
NotifyWidgetBoxUpdate(index);
|
||||||
return index;
|
return index;
|
||||||
|
|
@ -26,7 +26,7 @@ namespace Ndk
|
||||||
|
|
||||||
void Canvas::UnregisterWidget(std::size_t index)
|
void Canvas::UnregisterWidget(std::size_t index)
|
||||||
{
|
{
|
||||||
WidgetBox& entry = m_widgetBoxes[index];
|
WidgetEntry& entry = m_widgetEntries[index];
|
||||||
|
|
||||||
if (m_hoveredWidget == index)
|
if (m_hoveredWidget == index)
|
||||||
m_hoveredWidget = InvalidCanvasIndex;
|
m_hoveredWidget = InvalidCanvasIndex;
|
||||||
|
|
@ -34,10 +34,10 @@ namespace Ndk
|
||||||
if (m_keyboardOwner == index)
|
if (m_keyboardOwner == index)
|
||||||
m_keyboardOwner = InvalidCanvasIndex;
|
m_keyboardOwner = InvalidCanvasIndex;
|
||||||
|
|
||||||
if (m_widgetBoxes.size() > 1U)
|
if (m_widgetEntries.size() > 1U)
|
||||||
{
|
{
|
||||||
WidgetBox& lastEntry = m_widgetBoxes.back();
|
WidgetEntry& lastEntry = m_widgetEntries.back();
|
||||||
std::size_t lastEntryIndex = m_widgetBoxes.size() - 1;
|
std::size_t lastEntryIndex = m_widgetEntries.size() - 1;
|
||||||
|
|
||||||
entry = std::move(lastEntry);
|
entry = std::move(lastEntry);
|
||||||
entry.widget->UpdateCanvasIndex(index);
|
entry.widget->UpdateCanvasIndex(index);
|
||||||
|
|
@ -49,14 +49,14 @@ namespace Ndk
|
||||||
m_keyboardOwner = index;
|
m_keyboardOwner = index;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_widgetBoxes.pop_back();
|
m_widgetEntries.pop_back();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Canvas::OnEventMouseButtonPressed(const Nz::EventHandler* /*eventHandler*/, const Nz::WindowEvent::MouseButtonEvent& event)
|
void Canvas::OnEventMouseButtonPressed(const Nz::EventHandler* /*eventHandler*/, const Nz::WindowEvent::MouseButtonEvent& event)
|
||||||
{
|
{
|
||||||
if (m_hoveredWidget != InvalidCanvasIndex)
|
if (m_hoveredWidget != InvalidCanvasIndex)
|
||||||
{
|
{
|
||||||
WidgetBox& hoveredWidget = m_widgetBoxes[m_hoveredWidget];
|
WidgetEntry& hoveredWidget = m_widgetEntries[m_hoveredWidget];
|
||||||
|
|
||||||
int x = static_cast<int>(std::round(event.x - hoveredWidget.box.x));
|
int x = static_cast<int>(std::round(event.x - hoveredWidget.box.x));
|
||||||
int y = static_cast<int>(std::round(event.y - hoveredWidget.box.y));
|
int y = static_cast<int>(std::round(event.y - hoveredWidget.box.y));
|
||||||
|
|
@ -69,7 +69,7 @@ namespace Ndk
|
||||||
{
|
{
|
||||||
if (m_hoveredWidget != InvalidCanvasIndex)
|
if (m_hoveredWidget != InvalidCanvasIndex)
|
||||||
{
|
{
|
||||||
WidgetBox& hoveredWidget = m_widgetBoxes[m_hoveredWidget];
|
WidgetEntry& hoveredWidget = m_widgetEntries[m_hoveredWidget];
|
||||||
|
|
||||||
int x = static_cast<int>(std::round(event.x - hoveredWidget.box.x));
|
int x = static_cast<int>(std::round(event.x - hoveredWidget.box.x));
|
||||||
int y = static_cast<int>(std::round(event.y - hoveredWidget.box.y));
|
int y = static_cast<int>(std::round(event.y - hoveredWidget.box.y));
|
||||||
|
|
@ -84,9 +84,9 @@ namespace Ndk
|
||||||
float bestEntryArea = std::numeric_limits<float>::infinity();
|
float bestEntryArea = std::numeric_limits<float>::infinity();
|
||||||
|
|
||||||
Nz::Vector3f mousePos(float(event.x), float(event.y), 0.f);
|
Nz::Vector3f mousePos(float(event.x), float(event.y), 0.f);
|
||||||
for (std::size_t i = 0; i < m_widgetBoxes.size(); ++i)
|
for (std::size_t i = 0; i < m_widgetEntries.size(); ++i)
|
||||||
{
|
{
|
||||||
const Nz::Boxf& box = m_widgetBoxes[i].box;
|
const Nz::Boxf& box = m_widgetEntries[i].box;
|
||||||
|
|
||||||
if (box.Contains(mousePos))
|
if (box.Contains(mousePos))
|
||||||
{
|
{
|
||||||
|
|
@ -105,18 +105,18 @@ namespace Ndk
|
||||||
{
|
{
|
||||||
if (m_hoveredWidget != InvalidCanvasIndex)
|
if (m_hoveredWidget != InvalidCanvasIndex)
|
||||||
{
|
{
|
||||||
WidgetBox& previouslyHovered = m_widgetBoxes[m_hoveredWidget];
|
WidgetEntry& previouslyHovered = m_widgetEntries[m_hoveredWidget];
|
||||||
previouslyHovered.widget->OnMouseExit();
|
previouslyHovered.widget->OnMouseExit();
|
||||||
}
|
}
|
||||||
|
|
||||||
m_hoveredWidget = bestEntry;
|
m_hoveredWidget = bestEntry;
|
||||||
m_widgetBoxes[m_hoveredWidget].widget->OnMouseEnter();
|
m_widgetEntries[m_hoveredWidget].widget->OnMouseEnter();
|
||||||
|
|
||||||
if (m_cursorController)
|
if (m_cursorController)
|
||||||
m_cursorController->UpdateCursor(Nz::Cursor::Get(m_widgetBoxes[m_hoveredWidget].cursor));
|
m_cursorController->UpdateCursor(Nz::Cursor::Get(m_widgetEntries[m_hoveredWidget].cursor));
|
||||||
}
|
}
|
||||||
|
|
||||||
WidgetBox& hoveredWidget = m_widgetBoxes[m_hoveredWidget];
|
WidgetEntry& hoveredWidget = m_widgetEntries[m_hoveredWidget];
|
||||||
|
|
||||||
int x = static_cast<int>(std::round(event.x - hoveredWidget.box.x));
|
int x = static_cast<int>(std::round(event.x - hoveredWidget.box.x));
|
||||||
int y = static_cast<int>(std::round(event.y - hoveredWidget.box.y));
|
int y = static_cast<int>(std::round(event.y - hoveredWidget.box.y));
|
||||||
|
|
@ -124,7 +124,7 @@ namespace Ndk
|
||||||
}
|
}
|
||||||
else if (m_hoveredWidget != InvalidCanvasIndex)
|
else if (m_hoveredWidget != InvalidCanvasIndex)
|
||||||
{
|
{
|
||||||
m_widgetBoxes[m_hoveredWidget].widget->OnMouseExit();
|
m_widgetEntries[m_hoveredWidget].widget->OnMouseExit();
|
||||||
m_hoveredWidget = InvalidCanvasIndex;
|
m_hoveredWidget = InvalidCanvasIndex;
|
||||||
|
|
||||||
if (m_cursorController)
|
if (m_cursorController)
|
||||||
|
|
@ -136,7 +136,7 @@ namespace Ndk
|
||||||
{
|
{
|
||||||
if (m_hoveredWidget != InvalidCanvasIndex)
|
if (m_hoveredWidget != InvalidCanvasIndex)
|
||||||
{
|
{
|
||||||
m_widgetBoxes[m_hoveredWidget].widget->OnMouseExit();
|
m_widgetEntries[m_hoveredWidget].widget->OnMouseExit();
|
||||||
m_hoveredWidget = InvalidCanvasIndex;
|
m_hoveredWidget = InvalidCanvasIndex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -144,18 +144,18 @@ namespace Ndk
|
||||||
void Canvas::OnEventKeyPressed(const Nz::EventHandler* /*eventHandler*/, const Nz::WindowEvent::KeyEvent& event)
|
void Canvas::OnEventKeyPressed(const Nz::EventHandler* /*eventHandler*/, const Nz::WindowEvent::KeyEvent& event)
|
||||||
{
|
{
|
||||||
if (m_keyboardOwner != InvalidCanvasIndex)
|
if (m_keyboardOwner != InvalidCanvasIndex)
|
||||||
m_widgetBoxes[m_keyboardOwner].widget->OnKeyPressed(event);
|
m_widgetEntries[m_keyboardOwner].widget->OnKeyPressed(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Canvas::OnEventKeyReleased(const Nz::EventHandler* /*eventHandler*/, const Nz::WindowEvent::KeyEvent& event)
|
void Canvas::OnEventKeyReleased(const Nz::EventHandler* /*eventHandler*/, const Nz::WindowEvent::KeyEvent& event)
|
||||||
{
|
{
|
||||||
if (m_keyboardOwner != InvalidCanvasIndex)
|
if (m_keyboardOwner != InvalidCanvasIndex)
|
||||||
m_widgetBoxes[m_keyboardOwner].widget->OnKeyReleased(event);
|
m_widgetEntries[m_keyboardOwner].widget->OnKeyReleased(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Canvas::OnEventTextEntered(const Nz::EventHandler* /*eventHandler*/, const Nz::WindowEvent::TextEvent& event)
|
void Canvas::OnEventTextEntered(const Nz::EventHandler* /*eventHandler*/, const Nz::WindowEvent::TextEvent& event)
|
||||||
{
|
{
|
||||||
if (m_keyboardOwner != InvalidCanvasIndex)
|
if (m_keyboardOwner != InvalidCanvasIndex)
|
||||||
m_widgetBoxes[m_keyboardOwner].widget->OnTextEntered(event.character, event.repeated);
|
m_widgetEntries[m_keyboardOwner].widget->OnTextEntered(event.character, event.repeated);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue