[turbine,studio] Fix some popup window resize weirdness, cleanup some function names
All checks were successful
Build / build (push) Successful in 1m17s

This commit is contained in:
Gary Talent 2025-05-24 01:32:14 -05:00
parent ed1160ec74
commit 8419b137e5
6 changed files with 42 additions and 8 deletions

View File

@ -43,7 +43,7 @@ static ox::Error runApp(
oxLogError(turbine::setWindowIcon(*ctx, WindowIcons())); oxLogError(turbine::setWindowIcon(*ctx, WindowIcons()));
turbine::setWindowTitle(*ctx, keelCtx(*ctx).appName); turbine::setWindowTitle(*ctx, keelCtx(*ctx).appName);
turbine::setKeyEventHandler(*ctx, keyEventHandler); turbine::setKeyEventHandler(*ctx, keyEventHandler);
turbine::setRefreshWithin(*ctx, 0); turbine::requireRefreshWithin(*ctx, 0);
StudioUI ui(*ctx, projectDataDir); StudioUI ui(*ctx, projectDataDir);
StudioUIDrawer drawer(ui); StudioUIDrawer drawer(ui);
turbine::gl::addDrawer(*ctx, &drawer); turbine::gl::addDrawer(*ctx, &drawer);

View File

@ -2,6 +2,8 @@
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved. * Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/ */
#include <turbine/gfx.hpp>
#include <studio/imguiutil.hpp> #include <studio/imguiutil.hpp>
#include "deleteconfirmation.hpp" #include "deleteconfirmation.hpp"
@ -43,6 +45,9 @@ void DeleteConfirmation::draw(Context &ctx) noexcept {
ImGui::OpenPopup(title().c_str()); ImGui::OpenPopup(title().c_str());
m_stage = Stage::Open; m_stage = Stage::Open;
m_open = true; m_open = true;
// require extended refresh in case new contents require resize
// this can take around a second
turbine::requireRefreshFor(ctx.tctx, 1000);
[[fallthrough]]; [[fallthrough]];
case Stage::Open: case Stage::Open:
drawWindow(ctx.tctx, m_open, [this] { drawWindow(ctx.tctx, m_open, [this] {

View File

@ -347,7 +347,7 @@ void StudioUI::drawTabs() noexcept {
pc->activeTabItemName = m_activeEditor->itemPath(); pc->activeTabItemName = m_activeEditor->itemPath();
} }
}); });
turbine::setRefreshWithin(m_tctx, 0); turbine::requireRefreshWithin(m_tctx, 0);
} else [[likely]] { } else [[likely]] {
if (m_activeEditorUpdatePending == e.get()) [[unlikely]] { if (m_activeEditorUpdatePending == e.get()) [[unlikely]] {
m_activeEditorUpdatePending = nullptr; m_activeEditorUpdatePending = nullptr;

View File

@ -275,6 +275,9 @@ void QuestionPopup::draw(Context &ctx) noexcept {
ImGui::OpenPopup(m_title.c_str()); ImGui::OpenPopup(m_title.c_str());
m_stage = Stage::Open; m_stage = Stage::Open;
m_open = true; m_open = true;
// require extended refresh in case new contents require resize
// this can take around a second
turbine::requireRefreshFor(ctx.tctx, 1000);
[[fallthrough]]; [[fallthrough]];
case Stage::Open: case Stage::Open:
centerNextWindow(ctx.tctx); centerNextWindow(ctx.tctx);

View File

@ -49,6 +49,19 @@ ox::Error setWindowBounds(Context &ctx, ox::Bounds const&bnds) noexcept;
* @param ctx - Context * @param ctx - Context
* @param ms - milliseconds * @param ms - milliseconds
*/ */
void setRefreshWithin(Context &ctx, int ms) noexcept; void requireRefreshWithin(Context &ctx, int ms) noexcept;
/**
* Stimulates screen to draw for a period of a short period of
* time (168 ms on GLFW implementation).
* @param ctx - Context
*/
void requireRefresh(Context &ctx) noexcept;
/**
* Stimulates screen to draw for a specified period of time.
* @param ctx - Context
*/
void requireRefreshFor(Context &ctx, int ms) noexcept;
} }

View File

@ -155,6 +155,10 @@ static ox::Result<IconData> toGlfwImgPixels(ox::SpanView<uint8_t> const &iconPng
return out; return out;
} }
static void setMandatoryRefreshPeriod(Context &ctx, TimeMs const newVal) {
ctx.mandatoryRefreshPeriodEnd = ox::max(ctx.mandatoryRefreshPeriodEnd, newVal);
}
ox::Error setWindowIcon(Context &ctx, ox::SpanView<ox::SpanView<uint8_t>> const &iconPngs) noexcept { ox::Error setWindowIcon(Context &ctx, ox::SpanView<ox::SpanView<uint8_t>> const &iconPngs) noexcept {
if constexpr(ox::defines::OS != ox::OS::Darwin) { if constexpr(ox::defines::OS != ox::OS::Darwin) {
ox::Vector<IconData, 8> src; ox::Vector<IconData, 8> src;
@ -216,10 +220,19 @@ ox::Error setWindowBounds(Context &ctx, ox::Bounds const&bnds) noexcept {
return {}; return {};
} }
void setRefreshWithin(Context &ctx, int ms) noexcept { void requireRefreshWithin(Context &ctx, int const ms) noexcept {
ctx.refreshWithinMs = ox::min(ms, ctx.refreshWithinMs); ctx.refreshWithinMs = ox::min(ms, ctx.refreshWithinMs);
} }
void requireRefresh(Context &ctx) noexcept {
setMandatoryRefreshPeriod(ctx, ticksMs(ctx) + config::MandatoryRefreshPeriod);
}
void requireRefreshFor(Context &ctx, int ms) noexcept {
ms = ox::max(0, ms);
setMandatoryRefreshPeriod(ctx, ticksMs(ctx) + static_cast<TimeMs>(ms));
}
static void draw(Context &ctx) noexcept { static void draw(Context &ctx) noexcept {
// draw start // draw start
#if TURBINE_USE_IMGUI #if TURBINE_USE_IMGUI
@ -288,12 +301,12 @@ static void handleGlfwCursorPosEvent(GLFWwindow*, double, double) noexcept {
static void handleGlfwMouseButtonEvent(GLFWwindow *window, int, int, int) noexcept { static void handleGlfwMouseButtonEvent(GLFWwindow *window, int, int, int) noexcept {
auto &ctx = *static_cast<Context*>(glfwGetWindowUserPointer(window)); auto &ctx = *static_cast<Context*>(glfwGetWindowUserPointer(window));
ctx.mandatoryRefreshPeriodEnd = ticksMs(ctx) + config::MandatoryRefreshPeriod; setMandatoryRefreshPeriod(ctx, ticksMs(ctx) + config::MandatoryRefreshPeriod);
} }
static void handleGlfwKeyEvent(GLFWwindow *window, int const key, int, int const action, int) noexcept { static void handleGlfwKeyEvent(GLFWwindow *window, int const key, int, int const action, int) noexcept {
auto &ctx = *static_cast<Context*>(glfwGetWindowUserPointer(window)); auto &ctx = *static_cast<Context*>(glfwGetWindowUserPointer(window));
ctx.mandatoryRefreshPeriodEnd = ticksMs(ctx) + config::MandatoryRefreshPeriod; setMandatoryRefreshPeriod(ctx, ticksMs(ctx) + config::MandatoryRefreshPeriod);
if (action == GLFW_PRESS) { if (action == GLFW_PRESS) {
handleKeyPress(ctx, key, true); handleKeyPress(ctx, key, true);
} else if (action == GLFW_RELEASE) { } else if (action == GLFW_RELEASE) {
@ -303,7 +316,7 @@ static void handleGlfwKeyEvent(GLFWwindow *window, int const key, int, int const
static void handleGlfwWindowCloseEvent(GLFWwindow *window) noexcept { static void handleGlfwWindowCloseEvent(GLFWwindow *window) noexcept {
auto &ctx = *static_cast<Context*>(glfwGetWindowUserPointer(window)); auto &ctx = *static_cast<Context*>(glfwGetWindowUserPointer(window));
ctx.mandatoryRefreshPeriodEnd = ticksMs(ctx) + config::MandatoryRefreshPeriod; setMandatoryRefreshPeriod(ctx, ticksMs(ctx) + config::MandatoryRefreshPeriod);
ctx.running = ctx.shutdownHandler ? !ctx.shutdownHandler(ctx) : false; ctx.running = ctx.shutdownHandler ? !ctx.shutdownHandler(ctx) : false;
glfwSetWindowShouldClose(window, !ctx.running); glfwSetWindowShouldClose(window, !ctx.running);
glfwPostEmptyEvent(); glfwPostEmptyEvent();
@ -316,7 +329,7 @@ ox::Result<ox::UPtr<Context>> init(
using namespace std::chrono; using namespace std::chrono;
ctx->startTime = static_cast<TimeMs>( ctx->startTime = static_cast<TimeMs>(
duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count()); duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count());
ctx->mandatoryRefreshPeriodEnd = ticksMs(*ctx) + config::MandatoryRefreshPeriod; setMandatoryRefreshPeriod(*ctx, ticksMs(*ctx) + config::MandatoryRefreshPeriod);
// init GLFW context // init GLFW context
glfwInit(); glfwInit();
glfwSetErrorCallback(handleGlfwError); glfwSetErrorCallback(handleGlfwError);