add text input popup
This commit is contained in:
@@ -352,6 +352,7 @@
|
||||
<ClCompile Include="src\node_icon.cpp" />
|
||||
<ClCompile Include="src\node_image.cpp" />
|
||||
<ClCompile Include="src\node_image_texture.cpp" />
|
||||
<ClCompile Include="src\node_input_box.cpp" />
|
||||
<ClCompile Include="src\node_message_box.cpp" />
|
||||
<ClCompile Include="src\node_panel_brush.cpp" />
|
||||
<ClCompile Include="src\node_panel_color.cpp" />
|
||||
@@ -478,6 +479,7 @@
|
||||
<ClInclude Include="src\node_icon.h" />
|
||||
<ClInclude Include="src\node_image.h" />
|
||||
<ClInclude Include="src\node_image_texture.h" />
|
||||
<ClInclude Include="src\node_input_box.h" />
|
||||
<ClInclude Include="src\node_message_box.h" />
|
||||
<ClInclude Include="src\node_panel_brush.h" />
|
||||
<ClInclude Include="src\node_panel_color.h" />
|
||||
|
||||
@@ -366,6 +366,9 @@
|
||||
<ClCompile Include="libs\glad\src\glad_wgl.c">
|
||||
<Filter>libs\glad</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\node_input_box.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="src\app.h">
|
||||
@@ -608,6 +611,9 @@
|
||||
<ClInclude Include="src\node_tool_bucket.h">
|
||||
<Filter>Header Files\ui</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\node_input_box.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="PanoPainter.rc">
|
||||
|
||||
@@ -870,6 +870,27 @@
|
||||
</node>
|
||||
</layout>
|
||||
|
||||
<!-- INPUT BOX -->
|
||||
<layout id="input-box">
|
||||
<border positioning="absolute" position="0 0" color=".4 .4 .4 .8" width="100%" height="100%" align="center" justify="center">
|
||||
<border thickness="1" border-color=".2" pad="3">
|
||||
<border width="400" height="30" color=".2 .2 .2 .9" dir="row" align="center" justify="center">
|
||||
<text id="title" text="Just a test message"></text>
|
||||
</border>
|
||||
<border width="400" color="0 0 0 .9" pad="10" dir="col">
|
||||
<node dir="row" height="30" align="center" grow="1">
|
||||
<text id="field-name" text="Field" margin="0 5 0 0"/>
|
||||
<text-input id="field-text" align="center" pad="5" grow="1" height="30" color=".3"/>
|
||||
</node>
|
||||
<node height="40" grow="1" dir="row" align="flex-end" justify="flex-end">
|
||||
<button id="btn-ok" text="Ok" width="50" height="30" margin="0 10 0 0"/>
|
||||
<button id="btn-cancel" text="Cancel" width="60" height="30"/>
|
||||
</node>
|
||||
</border>
|
||||
</border>
|
||||
</border>
|
||||
</layout>
|
||||
|
||||
<!-- MESSAGE BOX -->
|
||||
<layout id="message-box">
|
||||
<border positioning="absolute" position="0 0" color=".4 .4 .4 .8" width="100%" height="100%" align="center" justify="center">
|
||||
|
||||
12
src/app.h
12
src/app.h
@@ -33,6 +33,7 @@
|
||||
#endif
|
||||
#include "node_panel_grid.h"
|
||||
#include "node_panel_quick.h"
|
||||
#include "node_input_box.h"
|
||||
|
||||
struct VRController
|
||||
{
|
||||
@@ -206,7 +207,6 @@ public:
|
||||
bool key_char(char key);
|
||||
void toggle_ui();
|
||||
void set_stylus();
|
||||
std::shared_ptr<NodeMessageBox> message_box(const std::string& title, const std::string& text, bool cancel_button = false);
|
||||
|
||||
void rec_clear();
|
||||
void rec_loop();
|
||||
@@ -241,11 +241,17 @@ public:
|
||||
void cloud_upload();
|
||||
void cloud_upload_all();
|
||||
void cloud_browse();
|
||||
void upload(std::string filename, std::string name = "", std::function<void(float)> progress = nullptr);
|
||||
void download(std::string url, std::string dest_filepath, std::function<void(float)> progress = nullptr);
|
||||
void upload(std::string filename, std::string name = "",
|
||||
std::function<void(float)> progress = nullptr);
|
||||
void download(std::string url, std::string dest_filepath,
|
||||
std::function<void(float)> progress = nullptr);
|
||||
bool check_license();
|
||||
|
||||
std::shared_ptr<NodeProgressBar> show_progress(const std::string& title, int total = 0);
|
||||
std::shared_ptr<NodeMessageBox> message_box(const std::string& title,
|
||||
const std::string& text, bool cancel_button = false);
|
||||
std::shared_ptr<NodeInputBox> input_box(const std::string& title,
|
||||
const std::string& field_name, const std::string& ok_caption = "Ok");
|
||||
|
||||
void brush_update(bool update_color, bool update_brush);
|
||||
void title_update();
|
||||
|
||||
@@ -44,6 +44,21 @@ std::shared_ptr<NodeMessageBox> App::message_box(const std::string &title, const
|
||||
return m;
|
||||
}
|
||||
|
||||
std::shared_ptr<NodeInputBox> App::input_box(const std::string& title,
|
||||
const std::string& field_name, const std::string& ok_caption /*= "Ok"*/)
|
||||
{
|
||||
auto m = std::make_shared<NodeInputBox>();
|
||||
m->m_manager = &layout;
|
||||
m->init();
|
||||
m->create();
|
||||
m->loaded();
|
||||
m->m_title->set_text(title.c_str());
|
||||
m->m_field_name->set_text(field_name.c_str());
|
||||
m->btn_ok->m_text->set_text(ok_caption.c_str());
|
||||
layout[main_id]->add_child(m);
|
||||
return m;
|
||||
}
|
||||
|
||||
void App::dialog_usermanual()
|
||||
{
|
||||
auto dialog = std::make_shared<NodeUserManual>();
|
||||
|
||||
57
src/node_input_box.cpp
Normal file
57
src/node_input_box.cpp
Normal file
@@ -0,0 +1,57 @@
|
||||
#include "pch.h"
|
||||
#include "log.h"
|
||||
#include "node_input_box.h"
|
||||
#include "layout.h"
|
||||
|
||||
Node* NodeInputBox::clone_instantiate() const
|
||||
{
|
||||
return new NodeInputBox();
|
||||
}
|
||||
|
||||
void NodeInputBox::init()
|
||||
{
|
||||
SetPosition(0, 0);
|
||||
SetWidthP(100);
|
||||
SetHeightP(100);
|
||||
SetPositioning(YGPositionTypeAbsolute);
|
||||
auto m_template = (*m_manager)[const_hash("input-box")]->m_children[0]->clone();
|
||||
add_child(m_template);
|
||||
m_title = m_template->find<NodeText>("title");
|
||||
m_field_name = m_template->find<NodeText>("field-name");
|
||||
m_field_text = m_template->find<NodeTextInput>("field-text");
|
||||
btn_ok = m_template->find<NodeButton>("btn-ok");
|
||||
btn_ok->on_click = [&](Node*) {
|
||||
if (on_submit)
|
||||
on_submit(this, m_field_text->m_text->m_text);
|
||||
};
|
||||
btn_cancel = m_template->find<NodeButton>("btn-cancel");
|
||||
btn_cancel->on_click = [&](Node*) { destroy(); };
|
||||
m_capture_children = false; // don't capture children events on mouse_capture
|
||||
}
|
||||
|
||||
kEventResult NodeInputBox::handle_event(Event* e)
|
||||
{
|
||||
Node::handle_event(e);
|
||||
auto ke = (KeyEvent*)e;
|
||||
switch (e->m_type)
|
||||
{
|
||||
case kEventType::KeyDown:
|
||||
break;
|
||||
case kEventType::KeyUp:
|
||||
if (ke->m_key == kKey::KeyEnter && on_submit)
|
||||
on_submit(this, m_field_text->m_text->m_text);
|
||||
break;
|
||||
case kEventType::KeyChar:
|
||||
break;
|
||||
default:
|
||||
return kEventResult::Available;
|
||||
break;
|
||||
}
|
||||
return kEventResult::Consumed;
|
||||
}
|
||||
|
||||
void NodeInputBox::added(Node* parent)
|
||||
{
|
||||
Node::added(parent);
|
||||
mouse_capture();
|
||||
}
|
||||
19
src/node_input_box.h
Normal file
19
src/node_input_box.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
#include "node.h"
|
||||
#include "node_button.h"
|
||||
#include "node_text_input.h"
|
||||
|
||||
class NodeInputBox : public Node
|
||||
{
|
||||
public:
|
||||
std::function<void(Node*, std::string text)> on_submit = nullptr;
|
||||
NodeButton* btn_ok;
|
||||
NodeButton* btn_cancel;
|
||||
NodeText* m_field_name;
|
||||
NodeTextInput* m_field_text;
|
||||
NodeText* m_title;
|
||||
virtual Node* clone_instantiate() const override;
|
||||
virtual void init() override;
|
||||
virtual kEventResult handle_event(Event* e) override;
|
||||
virtual void added(Node* parent) override;
|
||||
};
|
||||
Reference in New Issue
Block a user