added button click event handler
This commit is contained in:
@@ -194,7 +194,18 @@ public:
|
||||
Node* clone();
|
||||
virtual Node* clone_instantiate() const;
|
||||
virtual void clone_copy(Node* dest) const;
|
||||
Node* find(const char* ids);
|
||||
|
||||
template<class T> T* find(const char* ids)
|
||||
{
|
||||
uint16_t id = const_hash(ids);
|
||||
if (id == m_nodeID)
|
||||
return static_cast<T*>(this);
|
||||
for (auto& c : *this)
|
||||
if (c.m_nodeID == id)
|
||||
return static_cast<T*>(&c);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
kEventResult on_event(Event* e);
|
||||
virtual kEventResult handle_event(Event* e) { return kEventResult::Available; }
|
||||
virtual void create() { }
|
||||
@@ -237,11 +248,11 @@ public:
|
||||
|
||||
class NodeBorder : public Node
|
||||
{
|
||||
public:
|
||||
static Plane m_plane;
|
||||
glm::vec4 m_color;
|
||||
glm::vec4 m_border_color;
|
||||
float m_thinkness{ 1 };
|
||||
public:
|
||||
static void static_init()
|
||||
{
|
||||
m_plane.create<1>(1, 1);
|
||||
@@ -299,18 +310,6 @@ public:
|
||||
ShaderManager::u_vec4(kShaderUniform::Col, m_border_color);
|
||||
m_plane.draw_stroke();
|
||||
}
|
||||
virtual kEventResult handle_event(Event* e) override
|
||||
{
|
||||
switch (e->m_type)
|
||||
{
|
||||
case kEventType::MouseEnter:
|
||||
m_color = rand_color();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return kEventResult::Consumed;
|
||||
}
|
||||
};
|
||||
|
||||
class NodeText : public Node
|
||||
@@ -462,6 +461,10 @@ class NodeButton : public Node
|
||||
public:
|
||||
NodeBorder* m_border;
|
||||
NodeText* m_text;
|
||||
glm::vec4 color_normal{ .1, .1, .1, 1 };
|
||||
glm::vec4 color_hover{ .2, .2, .2, 1 };
|
||||
glm::vec4 color_down{ .3, .3, .3, 1 };
|
||||
std::function<void()> on_click;
|
||||
virtual Node* clone_instantiate() const override { return new NodeImage(); }
|
||||
virtual void clone_copy(Node* dest) const override
|
||||
{
|
||||
@@ -514,6 +517,29 @@ public:
|
||||
m_border->draw();
|
||||
m_text->draw();
|
||||
}
|
||||
virtual kEventResult handle_event(Event* e) override
|
||||
{
|
||||
switch (e->m_type)
|
||||
{
|
||||
case kEventType::MouseEnter:
|
||||
m_border->m_color = color_hover;
|
||||
break;
|
||||
case kEventType::MouseLeave:
|
||||
m_border->m_color = color_normal;
|
||||
break;
|
||||
case kEventType::MouseDownL:
|
||||
m_border->m_color = color_down;
|
||||
break;
|
||||
case kEventType::MouseUpL:
|
||||
m_border->m_color = color_normal;
|
||||
if (m_mouse_inside && on_click != nullptr)
|
||||
on_click();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return kEventResult::Consumed;
|
||||
}
|
||||
};
|
||||
|
||||
class LayoutManager
|
||||
|
||||
Reference in New Issue
Block a user