mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-10 21:41:50 +00:00
Merge 5a0a1cf326 into 00425c4175
This commit is contained in:
commit
04ba8287b6
4 changed files with 62 additions and 17 deletions
|
|
@ -35,8 +35,15 @@ void InlineFrame::setDocument(const std::shared_ptr<UiDocument>& document) {
|
||||||
|
|
||||||
root->setSize(size);
|
root->setSize(size);
|
||||||
|
|
||||||
gui.postRunnable([this]() {
|
gui.postRunnable([weak = weak_from_this(), document]() {
|
||||||
scripting::on_ui_open(*this->document, {});
|
auto node = weak.lock();
|
||||||
|
if (node == nullptr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (static_cast<InlineFrame&>(*node).document != document) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
scripting::on_ui_open(*document, {});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -82,6 +82,19 @@ void SplitBox::doubleClick(int x, int y) {
|
||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<UINode> SplitBox::getAt(const glm::vec2& pos) {
|
||||||
|
auto hover = Container::getAt(pos);
|
||||||
|
if (hover.get() != this) {
|
||||||
|
return hover;
|
||||||
|
}
|
||||||
|
for (const auto& node : nodes) {
|
||||||
|
if (node->isVisible() && node->isInside(pos)) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return hover;
|
||||||
|
}
|
||||||
|
|
||||||
void SplitBox::fullRefresh() {
|
void SplitBox::fullRefresh() {
|
||||||
refresh();
|
refresh();
|
||||||
reposition();
|
reposition();
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ namespace gui {
|
||||||
virtual void refresh() override;
|
virtual void refresh() override;
|
||||||
virtual void fullRefresh() override;
|
virtual void fullRefresh() override;
|
||||||
virtual void doubleClick(int x, int y) override;
|
virtual void doubleClick(int x, int y) override;
|
||||||
|
virtual std::shared_ptr<UINode> getAt(const glm::vec2& pos) override;
|
||||||
private:
|
private:
|
||||||
float splitPos;
|
float splitPos;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -99,14 +99,21 @@ template <typename T, T(tovalueFunc)(lua::State*, int)>
|
||||||
std::function<T()> create_supplier(
|
std::function<T()> create_supplier(
|
||||||
const scriptenv& env, const std::string& src, const std::string& file
|
const scriptenv& env, const std::string& src, const std::string& file
|
||||||
) {
|
) {
|
||||||
return [=]() {
|
return [=, errorLogged = false]() mutable {
|
||||||
|
lua::stackguard guard(lua::get_main_state());
|
||||||
if (auto L = process_callback(env, src, file)) {
|
if (auto L = process_callback(env, src, file)) {
|
||||||
if (lua::isfunction(L, -1)) {
|
if (lua::isfunction(L, -1) && !lua::call_nothrow(L, 0)) {
|
||||||
lua::call_nothrow(L, 0);
|
return T {};
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return tovalueFunc(L, -1);
|
||||||
|
} catch (const std::exception& err) {
|
||||||
|
if (!errorLogged) {
|
||||||
|
logger.error() << "supplier " << util::quote(src) << ": "
|
||||||
|
<< err.what();
|
||||||
|
errorLogged = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
auto str = tovalueFunc(L, -1);
|
|
||||||
lua::pop(L);
|
|
||||||
return str;
|
|
||||||
}
|
}
|
||||||
return T {};
|
return T {};
|
||||||
};
|
};
|
||||||
|
|
@ -158,16 +165,33 @@ int_array_consumer scripting::create_int_array_consumer(
|
||||||
vec2supplier scripting::create_vec2_supplier(
|
vec2supplier scripting::create_vec2_supplier(
|
||||||
const scriptenv& env, const std::string& src, const std::string& file
|
const scriptenv& env, const std::string& src, const std::string& file
|
||||||
) {
|
) {
|
||||||
return [=]() {
|
return [=, errorLogged = false]() mutable {
|
||||||
if (auto L = process_callback(env, src, file)) {
|
auto L = lua::get_main_state();
|
||||||
if (lua::isfunction(L, -1)) {
|
lua::stackguard guard(L);
|
||||||
lua::call_nothrow(L, 0);
|
int top = lua::gettop(L);
|
||||||
|
if (process_callback(env, src, file)) {
|
||||||
|
if (lua::isfunction(L, -1) && !lua::call_nothrow(L, 0)) {
|
||||||
|
return glm::vec2(0, 0);
|
||||||
|
}
|
||||||
|
if (lua::gettop(L) - top < 2) {
|
||||||
|
if (!errorLogged) {
|
||||||
|
logger.error() << "supplier " << util::quote(src)
|
||||||
|
<< ": two numbers expected";
|
||||||
|
errorLogged = true;
|
||||||
|
}
|
||||||
|
return glm::vec2(0, 0);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
auto y = lua::tonumber(L, -1);
|
||||||
|
auto x = lua::tonumber(L, -2);
|
||||||
|
return glm::vec2(x, y);
|
||||||
|
} catch (const std::exception& err) {
|
||||||
|
if (!errorLogged) {
|
||||||
|
logger.error() << "supplier " << util::quote(src) << ": "
|
||||||
|
<< err.what();
|
||||||
|
errorLogged = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
auto y = lua::tonumber(L, -1);
|
|
||||||
lua::pop(L);
|
|
||||||
auto x = lua::tonumber(L, -1);
|
|
||||||
lua::pop(L);
|
|
||||||
return glm::vec2(x, y);
|
|
||||||
}
|
}
|
||||||
return glm::vec2(0, 0);
|
return glm::vec2(0, 0);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue