focus text input on popup dialogs
This commit is contained in:
@@ -42,3 +42,10 @@ std::string NodeDialogLayerRename::get_name()
|
||||
{
|
||||
return input ? input->m_text : "";
|
||||
}
|
||||
|
||||
void NodeDialogLayerRename::added(Node* parent)
|
||||
{
|
||||
Node::added(parent);
|
||||
if (added_to_root())
|
||||
input->key_capture();
|
||||
}
|
||||
|
||||
@@ -12,7 +12,8 @@ public:
|
||||
virtual Node* clone_instantiate() const override;
|
||||
virtual void clone_finalize(Node* dest) const override;
|
||||
virtual void init() override;
|
||||
void init_controls();
|
||||
virtual void loaded() override;
|
||||
virtual void added(Node* parent) override;
|
||||
void init_controls();
|
||||
std::string get_name();
|
||||
};
|
||||
|
||||
@@ -217,6 +217,13 @@ void NodeDialogSave::loaded()
|
||||
|
||||
}
|
||||
|
||||
void NodeDialogSave::added(Node* parent)
|
||||
{
|
||||
Node::added(parent);
|
||||
if (added_to_root())
|
||||
input->key_capture();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
|
||||
Node* NodeDialogNewDoc::clone_instantiate() const
|
||||
@@ -274,3 +281,10 @@ void NodeDialogNewDoc::loaded()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void NodeDialogNewDoc::added(Node* parent)
|
||||
{
|
||||
Node::added(parent);
|
||||
if (added_to_root())
|
||||
input->key_capture();
|
||||
}
|
||||
|
||||
@@ -59,6 +59,7 @@ public:
|
||||
virtual void init() override;
|
||||
void init_controls();
|
||||
virtual void loaded() override;
|
||||
virtual void added(Node* parent) override;
|
||||
};
|
||||
|
||||
class NodeDialogNewDoc : public NodeBorder
|
||||
@@ -75,4 +76,5 @@ public:
|
||||
virtual void init() override;
|
||||
void init_controls();
|
||||
virtual void loaded() override;
|
||||
virtual void added(Node* parent) override;
|
||||
};
|
||||
|
||||
@@ -63,6 +63,8 @@ kEventResult NodeTextInput::handle_event(Event* e)
|
||||
m_cursor_visible = true;
|
||||
break;
|
||||
case kEventType::KeyDown:
|
||||
if (!has_focus())
|
||||
return kEventResult::Available;
|
||||
//switch (ke->m_key)
|
||||
//{
|
||||
//case VK_BACK:
|
||||
@@ -74,6 +76,8 @@ kEventResult NodeTextInput::handle_event(Event* e)
|
||||
//}
|
||||
break;
|
||||
case kEventType::KeyUp:
|
||||
if (!has_focus())
|
||||
return kEventResult::Available;
|
||||
if (ke->m_key == kKey::KeyEnter && on_return)
|
||||
on_return(this);
|
||||
if (ke->m_key == kKey::KeyBackspace)
|
||||
@@ -86,6 +90,8 @@ kEventResult NodeTextInput::handle_event(Event* e)
|
||||
}
|
||||
break;
|
||||
case kEventType::KeyChar:
|
||||
if (!has_focus())
|
||||
return kEventResult::Available;
|
||||
timer = 0;
|
||||
m_cursor_visible = true;
|
||||
if (ke->m_char == '\b' // backspace
|
||||
@@ -163,6 +169,11 @@ void NodeTextInput::update_layout()
|
||||
m_off.x = (w - m_text_mesh.bb.x) + pad[3];
|
||||
}
|
||||
|
||||
bool NodeTextInput::has_focus() noexcept
|
||||
{
|
||||
return root()->current_key_capture.get() == this;
|
||||
}
|
||||
|
||||
void NodeTextInput::handle_resize(glm::vec2 old_size, glm::vec2 new_size, float zoom)
|
||||
{
|
||||
auto pad = GetPadding();
|
||||
|
||||
@@ -41,4 +41,5 @@ public:
|
||||
void set_text(const std::string& s);
|
||||
void set_text_format(const char* fmt, ...);
|
||||
void update_layout();
|
||||
bool has_focus() noexcept;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user