add app.set_title

This commit is contained in:
MihailRis 2025-11-10 20:48:26 +03:00
parent d5469acb55
commit 7d367a9793
5 changed files with 19 additions and 4 deletions

View File

@ -47,6 +47,7 @@ local function complete_app_lib(app)
end end
app.reset_content = core.reset_content app.reset_content = core.reset_content
app.is_content_loaded = core.is_content_loaded app.is_content_loaded = core.is_content_loaded
app.set_title = core.set_title
function app.config_packs(packs_list) function app.config_packs(packs_list)
-- Check if packs are valid and add dependencies to the configuration -- Check if packs are valid and add dependencies to the configuration

View File

@ -33,11 +33,12 @@ WindowControl::Result WindowControl::initialize() {
auto& settings = engine.getSettings(); auto& settings = engine.getSettings();
std::string title = project.title; std::string title = project.title;
if (title.empty()) { if (!title.empty()) {
title = "VoxelCore v" + title += " - ";
std::to_string(ENGINE_VERSION_MAJOR) + "." +
std::to_string(ENGINE_VERSION_MINOR);
} }
title += "VoxelCore v" +
std::to_string(ENGINE_VERSION_MAJOR) + "." +
std::to_string(ENGINE_VERSION_MINOR);
if (ENGINE_DEBUG_BUILD) { if (ENGINE_DEBUG_BUILD) {
title += " [debug]"; title += " [debug]";
} }

View File

@ -25,6 +25,7 @@
#include "graphics/ui/gui_util.hpp" #include "graphics/ui/gui_util.hpp"
#include "graphics/ui/GUI.hpp" #include "graphics/ui/GUI.hpp"
#include "graphics/ui/elements/Menu.hpp" #include "graphics/ui/elements/Menu.hpp"
#include "window/Window.hpp"
using namespace scripting; using namespace scripting;
@ -298,6 +299,12 @@ static int l_capture_output(lua::State* L) {
return 1; return 1;
} }
static int l_set_title(lua::State* L) {
auto title = lua::require_string(L, 1);
engine->getWindow().setTitle(title);
return 0;
}
const luaL_Reg corelib[] = { const luaL_Reg corelib[] = {
{"blank", lua::wrap<l_blank>}, {"blank", lua::wrap<l_blank>},
{"get_version", lua::wrap<l_get_version>}, {"get_version", lua::wrap<l_get_version>},
@ -319,5 +326,6 @@ const luaL_Reg corelib[] = {
{"open_url", lua::wrap<l_open_url>}, {"open_url", lua::wrap<l_open_url>},
{"quit", lua::wrap<l_quit>}, {"quit", lua::wrap<l_quit>},
{"capture_output", lua::wrap<l_capture_output>}, {"capture_output", lua::wrap<l_capture_output>},
{"set_title", lua::wrap<l_set_title>},
{nullptr, nullptr} {nullptr, nullptr}
}; };

View File

@ -36,6 +36,7 @@ public:
virtual void setMode(WindowMode mode) = 0; virtual void setMode(WindowMode mode) = 0;
virtual WindowMode getMode() const = 0; virtual WindowMode getMode() const = 0;
virtual void setTitle(const std::string& title) = 0;
virtual void setIcon(const ImageData* image) = 0; virtual void setIcon(const ImageData* image) = 0;
virtual void pushScissor(glm::vec4 area) = 0; virtual void pushScissor(glm::vec4 area) = 0;

View File

@ -468,6 +468,10 @@ public:
return mode; return mode;
} }
void setTitle(const std::string& title) override {
glfwSetWindowTitle(window, title.c_str());
}
void setIcon(const ImageData* image) override { void setIcon(const ImageData* image) override {
if (image == nullptr) { if (image == nullptr) {
glfwSetWindowIcon(window, 0, nullptr); glfwSetWindowIcon(window, 0, nullptr);