Merge pull request #925 from MihailRis/more-about-ui

more about ui
This commit is contained in:
MihailRis 2026-08-13 22:44:45 +03:00 • committed by GitHub
commit 450b32d12e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 36 additions and 12 deletions

View file

@ -13,6 +13,7 @@
#include "window/Window.hpp"
#include "../GUI.hpp"
// TODO: remove
// TODO: remove
#include <GL/glew.h>
@ -24,8 +25,7 @@ ModelViewer::ModelViewer(
: Container(gui, size),
modelName(modelName),
camera(),
batch(std::make_unique<Batch3D>(1024)),
fbo(std::make_unique<Framebuffer>(size.x, size.y)) {
batch(std::make_unique<Batch3D>(1024)) {
camera.perspective = true;
camera.position = glm::vec3(2, 2, 2);
}
@ -115,7 +115,13 @@ void ModelViewer::draw(const DrawContext& pctx, const Assets& assets) {
return;
}
auto& prevShader = Shader::getUsed();
if (!fbo) {
if (size.x <= 0 || size.y <= 0) {
return;
}
fbo = std::make_unique<Framebuffer>(size.x, size.y);
}
fbo->resize(size.x, size.y);
{
glDisable(GL_SCISSOR_TEST);
@ -154,6 +160,13 @@ void ModelViewer::draw(const DrawContext& pctx, const Assets& assets) {
Container::draw(pctx, assets);
}
void ModelViewer::setVisible(bool flag) {
if (!flag && fbo) {
fbo.reset();
}
Container::setVisible(flag);
}
void ModelViewer::setCenter(const glm::vec3& center) {
this->center = center;
}

View file

@ -23,7 +23,6 @@ namespace gui {
bool grabbing = false;
public:
ModelViewer(GUI& gui, const glm::vec2& size, const std::string& modelName);
~ModelViewer();
void setModel(const std::string& modelName);
@ -34,6 +33,7 @@ namespace gui {
void act(float delta) override;
void draw(const DrawContext& pctx, const Assets& assets) override;
void setVisible(bool flag) override;
void setRotation(const glm::vec3& euler);
void setCenter(const glm::vec3& center);

View file

@ -79,6 +79,8 @@ void UINode::click(int, int) {
void UINode::clicked(Mousecode button) {
if (button == Mousecode::BUTTON_2) {
actions.notify(UIAction::RIGHT_CLICK, gui);
} else if (button == Mousecode::BUTTON_3) {
actions.notify(UIAction::MIDDLE_CLICK, gui);
}
}

View file

@ -58,6 +58,7 @@ namespace gui {
FOCUS,
DEFOCUS,
RIGHT_CLICK,
MIDDLE_CLICK,
MOUSE_OVER,
MOUSE_OUT,
MOUSE_ENTER,

View file

@ -181,6 +181,7 @@ static void read_uinode(
register_action(node, reader, element, "onclick", UIAction::CLICK);
register_action(node, reader, element, "onrightclick", UIAction::RIGHT_CLICK);
register_action(node, reader, element, "onmiddleclick", UIAction::MIDDLE_CLICK);
register_action(node, reader, element, "onfocus", UIAction::FOCUS);
register_action(node, reader, element, "ondefocus", UIAction::DEFOCUS);
register_action(node, reader, element, "ondoubleclick", UIAction::DOUBLE_CLICK);

View file

@ -1127,6 +1127,7 @@ static int l_gui_load_document(lua::State* L) {
}
auto env = scripting::create_doc_environment(parentEnv, alias);
auto envId = *env;
// namespace extension
if (lua::istable(L, 4)) {
if (lua::get_from(L, "table", "extend")) {
@ -1148,7 +1149,7 @@ static int l_gui_load_document(lua::State* L) {
engine->requireAssets().store(std::move(documentPtr), alias);
scripting::on_ui_open(*document, {args});
return 0;
return lua::pushenv(L, envId);
}
static int l_set_syntax_styles(lua::State* L) {