Fixed GUI issues and added android save on quit (has some problems)

This commit is contained in:
Yousef Khadadeh 2026-04-27 21:30:31 +03:00
parent 45dbde5da5
commit d3e4524589
9 changed files with 51 additions and 23 deletions

View file

@ -10,9 +10,6 @@ GUIHolder::GUIHolder(MainProgram& m):
{
gui.io.textTypeface = main.fonts->map["Roboto"];
gui.io.fonts = main.fonts;
gui.io.layoutRun = [&] {
main.screen->gui_layout_run();
};
gui.io.input = &main.input;
// NOTE: On windows, when the native file picker is open, any call to MakeFromFile fails

View file

@ -1,6 +1,5 @@
#include "MainProgram.hpp"
#include "CustomEvents.hpp"
#include "Screens/FileSelectScreen.hpp"
#include "VersionConstants.hpp"
#include <SDL3/SDL_render.h>
#include <SDL3/SDL_video.h>
@ -16,12 +15,9 @@
#include <cereal/types/vector.hpp>
#include <cereal/types/unordered_map.hpp>
#include <Eigen/Core>
#include <fstream>
#include <cereal/archives/json.hpp>
#include <Helpers/Serializers.hpp>
#include <nlohmann/json.hpp>
#include "Screens/DrawingProgramScreen.hpp"
#include "Screens/FileSelectScreen.hpp"
#include <include/core/SkSurface.h>
#ifdef USE_SKIA_BACKEND_GRAPHITE
@ -42,6 +38,10 @@ MainProgram::MainProgram():
fonts(std::make_shared<FontData>()),
g(*this)
{
g.gui.io.layoutRun = [&] {
screen->gui_layout_run();
};
Logger::get().add_log("WORLDFATAL", [&](const std::string& text) {
*logFile << "[WORLDFATAL] " << text << std::endl;
std::cout << "[WORLDFATAL] " << text << std::endl;
@ -263,6 +263,10 @@ void MainProgram::switch_to_tab(size_t wIndex) {
worldIndex = wIndex;
}
void MainProgram::input_app_terminate_callback() {
screen->input_app_terminate_callback();
}
void MainProgram::post_callback() {
close_set_to_close_tabs();
g.post_callback();
@ -275,6 +279,7 @@ void MainProgram::input_add_file_to_canvas_callback(const CustomEvents::AddFileT
void MainProgram::input_open_infinipaint_file_callback(const CustomEvents::OpenInfiniPaintFileEvent& openFile) {
screen->input_open_infinipaint_file_callback(openFile);
g.gui.set_to_layout();
post_callback();
}
@ -417,6 +422,12 @@ void MainProgram::toggle_full_screen() {
SDL_SetWindowFullscreen(window.sdlWindow, window.fullscreen);
}
void MainProgram::set_screen(std::unique_ptr<Screen> newScreen) {
screen = std::move(newScreen);
g.gui.set_to_layout();
g.gui.io.redrawSurface = true;
}
void MainProgram::close_set_to_close_tabs() {
if(!tabsToClose.empty()) {
std::erase_if(worlds, [&](auto& w) {

View file

@ -91,8 +91,6 @@ class MainProgram {
std::ofstream* logFile;
std::deque<UserLogMessage> logMessages;
std::unique_ptr<Screen> screen;
MainProgram();
void update();
void draw_world(SkCanvas* canvas, std::shared_ptr<World> worldToDraw, const DrawData& drawData);
@ -116,6 +114,7 @@ class MainProgram {
float get_scale_and_density_factor_gui();
bool app_close_requested();
void toggle_full_screen();
void set_screen(std::unique_ptr<Screen> newScreen);
void refresh_draw_surfaces();
@ -135,6 +134,7 @@ class MainProgram {
void input_open_infinipaint_file_callback(const CustomEvents::OpenInfiniPaintFileEvent& openFile);
void input_paste_callback(const CustomEvents::PasteEvent& paste);
void input_app_terminate_callback();
void input_global_back_button_callback();
bool input_keybind_callback(const Vector2ui32& newKey);
void input_drop_file_callback(const InputManager::DropCallbackArgs& drop);
@ -167,6 +167,7 @@ class MainProgram {
void post_callback();
std::string gen_random_display_name();
std::unique_ptr<Screen> screen;
void gui();
void draw_grid(SkCanvas* canvas);

View file

@ -50,12 +50,11 @@ void FileSelectScreen::gui_layout_run() {
void FileSelectScreen::update_file_list(std::vector<FileInfo>& fL, const std::filesystem::path& savePath, bool trashUpdate) {
constexpr SDL_Time NS_IN_DAY = SDL_SECONDS_TO_NS(24 * 3600);
constexpr int64_t DAYS_TO_DELETION = 30;
SDL_Time currentTime;
SDL_GetCurrentTime(&currentTime);
SDL_Time afterThirtyDays = currentTime + NS_IN_DAY * 30;
fL.clear();
int globCount;
char** filesInPath = SDL_GlobDirectory(savePath.string().c_str(), "*", 0, &globCount);
@ -77,22 +76,21 @@ void FileSelectScreen::update_file_list(std::vector<FileInfo>& fL, const std::fi
else
fileInfoToAdd.lastModifyTime = it->second.trashTime;
if(fileInfoToAdd.lastModifyTime >= afterThirtyDays) {
int64_t daysSinceMovedToTrash = (currentTime - fileInfoToAdd.lastModifyTime) / NS_IN_DAY;
if(daysSinceMovedToTrash >= DAYS_TO_DELETION) {
// Remove file and thumbnail
SDL_RemovePath(fullPath.string().c_str());
SDL_RemovePath((savePath / fileInfoToAdd.fileName / ".jpg").string().c_str());
trashInfo.files.erase(it);
continue;
}
int64_t daysToDeletion = (afterThirtyDays - fileInfoToAdd.lastModifyTime) / NS_IN_DAY;
if(daysToDeletion == 0)
else if(daysSinceMovedToTrash == 29)
fileInfoToAdd.lastModifyDate = "Today";
else if(daysToDeletion == 1)
else if(daysSinceMovedToTrash == 28)
fileInfoToAdd.lastModifyDate = "Tomorrow";
else
fileInfoToAdd.lastModifyDate = std::to_string(daysToDeletion) + " days";
fileInfoToAdd.lastModifyDate = std::to_string(DAYS_TO_DELETION - daysSinceMovedToTrash - 1) + " days";
}
else {
SDL_PathInfo pathInfo;
@ -209,7 +207,7 @@ void FileSelectScreen::create_file_button() {
.isClient = false,
.filePathEmptyAutoSaveDir = savePath
});
main.screen = std::make_unique<PhoneDrawingProgramScreen>(main);
main.set_screen(std::make_unique<PhoneDrawingProgramScreen>(main));
}
});
}
@ -738,7 +736,7 @@ void FileSelectScreen::start_edit_mode() {
void FileSelectScreen::input_open_infinipaint_file_callback(const CustomEvents::OpenInfiniPaintFileEvent& openFile) {
main.create_new_tab(openFile);
main.screen = std::make_unique<PhoneDrawingProgramScreen>(main);
main.set_screen(std::make_unique<PhoneDrawingProgramScreen>(main));
}
void FileSelectScreen::input_global_back_button_callback() {
@ -746,6 +744,8 @@ void FileSelectScreen::input_global_back_button_callback() {
mainMenuOpenAnim->animation_trigger_reverse();
else if(editMode)
editMode = false;
else
main.setToQuit = true;
main.g.gui.set_to_layout();
}

View file

@ -7,6 +7,7 @@
#include "../GUIStuff/ElementHelpers/LayoutHelpers.hpp"
#include "../GUIStuff/ElementHelpers/TextLabelHelpers.hpp"
#include "FileSelectScreen.hpp"
#include <Helpers/Logger.hpp>
using namespace GUIStuff;
using namespace ElementHelpers;
@ -58,7 +59,7 @@ void PhoneDrawingProgramScreen::top_toolbar() {
.onClick = [&] {
main.world->save_to_file(main.world->filePath);
main.set_tab_to_close(main.world.get());
main.screen = std::make_unique<FileSelectScreen>(main);
main.set_screen(std::make_unique<FileSelectScreen>(main));
}
});
text_label(gui, main.world->name);
@ -69,6 +70,15 @@ void PhoneDrawingProgramScreen::top_toolbar() {
void PhoneDrawingProgramScreen::input_global_back_button_callback() {
main.world->save_to_file(main.world->filePath);
main.set_tab_to_close(main.world.get());
main.screen = std::make_unique<FileSelectScreen>(main);
main.set_screen(std::make_unique<FileSelectScreen>(main));
main.g.gui.set_to_layout();
}
bool PhoneDrawingProgramScreen::app_close_requested() {
main.world->save_to_file(main.world->filePath);
return true;
}
void PhoneDrawingProgramScreen::input_app_terminate_callback() {
main.world->save_to_file(main.world->filePath);
}

View file

@ -8,6 +8,8 @@ class PhoneDrawingProgramScreen : public DrawingProgramScreen {
virtual void update() override;
virtual void gui_layout_run() override;
virtual void input_global_back_button_callback() override;
virtual bool app_close_requested() override;
virtual void input_app_terminate_callback() override;
private:
void top_toolbar();
void main_display();

View file

@ -29,5 +29,6 @@ void Screen::input_finger_touch_callback(const InputManager::FingerTouchCallback
void Screen::input_finger_motion_callback(const InputManager::FingerMotionCallbackArgs& motion) {}
void Screen::input_window_resize_callback(const InputManager::WindowResizeCallbackArgs& w) {}
void Screen::input_window_scale_callback(const InputManager::WindowScaleCallbackArgs& w) {}
void Screen::input_app_terminate_callback() {}
Screen::~Screen() {}

View file

@ -31,6 +31,7 @@ class Screen {
virtual void input_finger_motion_callback(const InputManager::FingerMotionCallbackArgs& motion);
virtual void input_window_resize_callback(const InputManager::WindowResizeCallbackArgs& w);
virtual void input_window_scale_callback(const InputManager::WindowScaleCallbackArgs& w);
virtual void input_app_terminate_callback();
virtual ~Screen();
protected:

View file

@ -527,7 +527,7 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char **argv) {
mS.m->window.canCreateSurfaces = true;
resize_window(mS);
mS.m->screen = std::make_unique<FileSelectScreen>(*mS.m);
mS.m->set_screen(std::make_unique<FileSelectScreen>(*mS.m));
if(listOfFilesToOpenFromCommand.empty()) {
//mS.m->create_new_tab({
@ -634,9 +634,14 @@ SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event) {
#endif
switch(event->type) {
case SDL_EVENT_QUIT:
Logger::get().log("INFO", "[SDL_AppEvent] Quit");
if(mS.m->app_close_requested())
return SDL_APP_SUCCESS;
break;
case SDL_EVENT_TERMINATING:
Logger::get().log("INFO", "[SDL_AppEvent] Terminate");
mS.m->input_app_terminate_callback();
return SDL_APP_SUCCESS;
case SDL_EVENT_WINDOW_CLOSE_REQUESTED:
if(event->window.windowID == SDL_GetWindowID(mS.window)) {
if(mS.m->app_close_requested())