add tick and on_tick event, fix unsaved document prompt, implement TextInput blinking cursor
This commit is contained in:
@@ -2,22 +2,35 @@
|
||||
#include "app.h"
|
||||
#include "log.h"
|
||||
#include "node_text_input.h"
|
||||
#include "node_border.h"
|
||||
|
||||
Node* NodeTextInput::clone_instantiate() const
|
||||
{
|
||||
return new NodeTextInput();
|
||||
}
|
||||
|
||||
void NodeTextInput::on_tick(float dt)
|
||||
{
|
||||
timer += dt;
|
||||
if (timer > 1.0)
|
||||
{
|
||||
timer = 0;
|
||||
if (m_cursor)
|
||||
m_cursor->m_display = !m_cursor->m_display;
|
||||
}
|
||||
}
|
||||
|
||||
void NodeTextInput::clone_finalize(Node* dest) const
|
||||
{
|
||||
NodeBorder::clone_copy(dest);
|
||||
NodeTextInput* n = static_cast<NodeTextInput*>(dest);
|
||||
if (n->m_children.size())
|
||||
{
|
||||
auto t = n->m_children[0];
|
||||
n->m_text = (NodeText*)t.get();
|
||||
n->m_text = (NodeText*)n->m_children[0].get();
|
||||
n->m_cursor = (NodeBorder*)n->m_children[1].get();
|
||||
}
|
||||
n->m_string = m_string;
|
||||
|
||||
}
|
||||
|
||||
void NodeTextInput::init()
|
||||
@@ -34,6 +47,11 @@ void NodeTextInput::init_controls()
|
||||
m_text->m_text = "TextInput";
|
||||
m_text->create();
|
||||
m_string = "TextInput";
|
||||
YGNodeStyleSetFlexDirection(y_node, YGFlexDirectionRow);
|
||||
m_cursor = add_child<NodeBorder>();
|
||||
m_cursor->SetWidth(4);
|
||||
m_cursor->SetHeightP(100);
|
||||
m_cursor->SetMargin(0, 0, 0, 2);
|
||||
}
|
||||
|
||||
kEventResult NodeTextInput::handle_event(Event* e)
|
||||
@@ -58,7 +76,16 @@ kEventResult NodeTextInput::handle_event(Event* e)
|
||||
// break;
|
||||
//}
|
||||
break;
|
||||
case kEventType::KeyUp:
|
||||
if (ke->m_key == kKey::KeyEnter && on_return)
|
||||
on_return(this);
|
||||
break;
|
||||
case kEventType::KeyChar:
|
||||
if (m_cursor)
|
||||
{
|
||||
timer = 0;
|
||||
m_cursor->m_display = true;
|
||||
}
|
||||
if (ke->m_char == '\b') // backspace
|
||||
{
|
||||
if (!m_string.empty())
|
||||
@@ -77,8 +104,6 @@ kEventResult NodeTextInput::handle_event(Event* e)
|
||||
}
|
||||
else if (ke->m_char == '\n' || ke->m_char == '\r') // enter/return
|
||||
{
|
||||
if (on_return)
|
||||
on_return(this);
|
||||
}
|
||||
else if (ke->m_char >= 32 && ke->m_char < (32 + 96))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user