add layout designer

This commit is contained in:
2019-09-26 09:55:54 +02:00
parent f9bddfddad
commit 0a8c3aeaf2
7 changed files with 35 additions and 7 deletions

View File

@@ -547,6 +547,8 @@ void App::draw(float dt)
glEnable(GL_SCISSOR_TEST);
for (int i = 1; i < layout[main_id]->m_children.size(); i++)
layout[main_id]->m_children[i]->watch(observer);
for (int i = 0; layout_designer.get(main_id) && i < layout_designer[main_id]->m_children.size(); i++)
layout_designer[main_id]->m_children[i]->watch(observer);
//msgbox->watch(observer);
glDisable(GL_SCISSOR_TEST);
uirtt.unbindFramebuffer();
@@ -563,6 +565,8 @@ void App::draw(float dt)
glEnable(GL_SCISSOR_TEST);
for (int i = 0; i < layout[main_id]->m_children.size(); i++)
layout[main_id]->m_children[i]->watch(observer);
for (int i = 0; layout_designer.get(main_id) && i < layout_designer[main_id]->m_children.size(); i++)
layout_designer[main_id]->m_children[i]->watch(observer);
//msgbox->watch(observer);
glDisable(GL_SCISSOR_TEST);
}
@@ -617,6 +621,9 @@ void App::update(float dt)
if (auto* main = layout[main_id])
main->update(width, height, zoom);
if (auto* main = layout_designer[main_id])
main->update(width, height, zoom);
{
static glm::vec4 color_button_normal{ .1, .1, .1, 1 };
static glm::vec4 color_button_hlight{ 1, .0, .0, 1 };
@@ -651,6 +658,7 @@ void App::terminate()
TextureManager::invalidate();
ShaderManager::invalidate();
layout.unload();
layout_designer.unload();
uirtt.destroy();
m_face_plane.destroy();
layers.reset();
@@ -921,9 +929,9 @@ void App::ui_thread_main()
redraw = true;
}
if (layout.reload())
{
redraw = true;
}
if (layout_designer.reload())
redraw = true;
}
#endif

View File

@@ -96,6 +96,7 @@ public:
Plane m_face_plane;
Sphere sphere;
LayoutManager layout;
LayoutManager layout_designer;
NodeMessageBox* msgbox;
NodeSettings* settings;
NodeBorder* sidebar = nullptr;

View File

@@ -332,6 +332,8 @@ bool App::mouse_down(int button, float x, float y, float pressure, kEventSource
e.m_source = source;
e.m_eraser = eraser;
kEventResult ret = kEventResult::Available;
if (auto* main = layout_designer[main_id])
return main->on_event(&e) == kEventResult::Consumed;
if (auto* main = layout[main_id])
ret = main->on_event(&e);
return ret == kEventResult::Consumed;
@@ -347,6 +349,8 @@ bool App::mouse_move(float x, float y, float pressure, kEventSource source, bool
e.m_source = source;
e.m_eraser = eraser;
kEventResult ret = kEventResult::Available;
if (auto* main = layout_designer[main_id])
return main->on_event(&e) == kEventResult::Consumed;
if (auto* main = layout[main_id])
ret = main->on_event(&e);
return ret == kEventResult::Consumed;
@@ -360,6 +364,8 @@ bool App::mouse_up(int button, float x, float y, kEventSource source, bool erase
e.m_source = source;
e.m_eraser = eraser;
kEventResult ret = kEventResult::Available;
if (auto* main = layout_designer[main_id])
return main->on_event(&e) == kEventResult::Consumed;
if (auto* main = layout[main_id])
ret = main->on_event(&e);
return ret == kEventResult::Consumed;
@@ -372,6 +378,8 @@ bool App::mouse_scroll(float x, float y, float delta)
e.m_pos = { x / zoom, y / zoom };
e.m_scroll_delta = delta;
kEventResult ret = kEventResult::Available;
if (auto* main = layout_designer[main_id])
return main->on_event(&e) == kEventResult::Consumed;
if (auto* main = layout[main_id])
ret = main->on_event(&e);
return ret == kEventResult::Consumed;
@@ -382,6 +390,8 @@ bool App::mouse_cancel(int button)
MouseEvent e;
e.m_type = kEventType::MouseCancel;
kEventResult ret = kEventResult::Available;
if (auto* main = layout_designer[main_id])
return main->on_event(&e) == kEventResult::Consumed;
if (auto* main = layout[main_id])
ret = main->on_event(&e);
return ret == kEventResult::Consumed;

View File

@@ -1404,6 +1404,14 @@ void App::initLayout()
else
layout.load("data/layout.xml");
LOG("initializing layout completed");
//LOG("initializing layout designer xml");
//layout_designer.on_loaded = [&](bool reloaded) {
// if (!reloaded)
// layout_designer.create();
// layout_designer[main_id]->add_child(layout_designer.instantiate("changelog"));
//};
//layout_designer.load("data/dialogs/changelog.xml");
}
void App::set_ui_scale(float scale)

View File

@@ -21,6 +21,9 @@ bool Font::load(const std::string& ttf, int font_size, float font_scale)
LOG("Font::load loaded");
auto bitmap = std::make_unique<uint8_t[]>(w*h);
chars.resize(num_chars);
//int offset = stbtt_FindMatchingFont(file.m_data, "Arial Bold", STBTT_MACSTYLE_DONTCARE);
//if (offset < 0)
// offset = 0;
stbtt_BakeFontBitmap(file.m_data, 0, (float)font_size*scale, bitmap.get(), w, h, start_char, num_chars, chars.data());
calc_bounds();
font_tex.create(w, h, GL_R8, GL_RED, bitmap.get());

View File

@@ -13,10 +13,10 @@
class LayoutManager
{
std::map<uint16_t, std::shared_ptr<class Node>> m_layouts;
std::string m_path;
struct stat m_file_info { 0 };
public:
std::map<uint16_t, std::shared_ptr<class Node>> m_layouts;
bool m_loaded = false;
std::function<void(bool reloaded)> on_loaded;
std::function<void()> on_reloading;

View File

@@ -343,9 +343,6 @@ const Node* Node::init_template(const char* id)
{
auto node = c->clone();
add_child(node);
//node->init();
//node->create();
//node->loaded();
}
YGNodeCopyStyle(y_node, m_template->y_node);
m_template->clone_copy(this);
@@ -377,7 +374,8 @@ std::shared_ptr<Node> Node::load_template(const std::string& filename, const std
LayoutManager m;
std::shared_ptr<Node> ret;
if (m.load(filename.c_str()))
ret = std::move(m.get_ref(name.c_str())->m_children[0]);
ret = m.get_ref(name.c_str())->m_children[0]->clone();
m.unload();
return ret;
}