Added add button to file selector that sends user to phone drawing program

This commit is contained in:
Yousef Khadadeh 2026-04-26 13:21:05 +03:00
parent 7274a9396b
commit 97d299a346
7 changed files with 107 additions and 4 deletions

View file

@ -57,6 +57,7 @@ set(sources "src/main.cpp"
"src/Screens/Screen.cpp"
"src/Screens/DrawingProgramScreen.cpp"
"src/Screens/DesktopDrawingProgramScreen.cpp"
"src/Screens/PhoneDrawingProgramScreen.cpp"
"src/Screens/FileSelectScreen.cpp"
"src/Bookmarks/BookmarkListItem.cpp"
"src/Bookmarks/BookmarkManager.cpp"

View file

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M10.8284 12.0007L15.7782 16.9504L14.364 18.3646L8 12.0007L14.364 5.63672L15.7782 7.05093L10.8284 12.0007Z"></path></svg>

After

Width:  |  Height:  |  Size: 209 B

View file

@ -13,7 +13,7 @@
#include "../GUIStuff/Elements/PositionAdjustingPopupMenu.hpp"
#include "../World.hpp"
#include "Helpers/StringHelpers.hpp"
#include "DrawingProgramScreen.hpp"
#include "PhoneDrawingProgramScreen.hpp"
#include <SDL3/SDL_time.h>
#include <SDL3/SDL_timer.h>
@ -157,6 +157,8 @@ void FileSelectScreen::main_display() {
switch(selectedMenu) {
case SelectedMenu::FILES:
file_view();
if(!editMode)
create_file_button();
break;
case SelectedMenu::TRASH:
file_view();
@ -171,6 +173,35 @@ void FileSelectScreen::main_display() {
}
}
void FileSelectScreen::create_file_button() {
auto& gui = main.g.gui;
gui.set_z_index(gui.get_z_index() + 2, [&] {
gui.element<LayoutElement>("create file button floating area", [&](LayoutElement*, const Clay_ElementId& lId) {
CLAY(lId, {
.layout = {.sizing = {.width = CLAY_SIZING_FIT(0), .height = CLAY_SIZING_FIT(0)}},
.floating = {
.offset = {-5, -5},
.zIndex = gui.get_z_index(),
.attachPoints = {
.element = CLAY_ATTACH_POINT_RIGHT_BOTTOM,
.parent = CLAY_ATTACH_POINT_RIGHT_BOTTOM
},
.attachTo = CLAY_ATTACH_TO_PARENT
}
}) {
svg_icon_button(gui, "add button", "data/icons/plus.svg", {
.onClick = [&] {
main.create_new_tab({
.isClient = false
});
main.screen = std::make_unique<PhoneDrawingProgramScreen>(main);
}
});
}
});
});
}
void FileSelectScreen::edit_action_bar_button(const char* id, const std::string& svgPath, const char* text, const std::function<void()>& onClick) {
auto& gui = main.g.gui;
CLAY_AUTO_ID({
@ -664,7 +695,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<DrawingProgramScreen>(main);
main.screen = std::make_unique<PhoneDrawingProgramScreen>(main);
}
void FileSelectScreen::draw(SkCanvas* canvas) {

View file

@ -43,6 +43,7 @@ class FileSelectScreen : public Screen {
void main_display();
void main_menu();
void file_view();
void create_file_button();
void file_view_edit();
void menu_black_box();
void edit_action_bar();

View file

@ -0,0 +1,56 @@
#include "PhoneDrawingProgramScreen.hpp"
#include "../MainProgram.hpp"
#include "DrawingProgramScreen.hpp"
#include "Helpers/ConvertVec.hpp"
#include "../GUIStuff/Elements/LayoutElement.hpp"
#include "../GUIStuff/ElementHelpers/ButtonHelpers.hpp"
#include "FileSelectScreen.hpp"
using namespace GUIStuff;
using namespace ElementHelpers;
PhoneDrawingProgramScreen::PhoneDrawingProgramScreen(MainProgram& m):
DrawingProgramScreen(m)
{}
void PhoneDrawingProgramScreen::update() {
DrawingProgramScreen::update();
}
void PhoneDrawingProgramScreen::gui_layout_run() {
main_display();
}
void PhoneDrawingProgramScreen::main_display() {
auto& gui = main.g.gui;
auto& io = gui.io;
CLAY_AUTO_ID({
.layout = {
.sizing = { .width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0) },
.layoutDirection = CLAY_TOP_TO_BOTTOM
},
}) {
gui.element<LayoutElement>("top toolbar", [&](LayoutElement* l, const Clay_ElementId& lId) {
CLAY(lId, {
.layout = {
.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIT(0) },
.childAlignment = { .x = CLAY_ALIGN_X_LEFT, .y = CLAY_ALIGN_Y_CENTER},
.layoutDirection = CLAY_LEFT_TO_RIGHT
},
.backgroundColor = convert_vec4<Clay_Color>(io.theme->backColor0),
.border = {
.color = convert_vec4<Clay_Color>(io.theme->frontColor1),
.width = {.bottom = 1}
}
}) {
svg_icon_button(gui, "back exit button", "data/icons/RemixIcon/arrow-left-s-line.svg", {
.drawType = SelectableButton::DrawType::TRANSPARENT_ALL,
.onClick = [&] {
main.set_tab_to_close(main.world.get());
main.screen = std::make_unique<FileSelectScreen>(main);
}
});
}
});
}
}

View file

@ -0,0 +1,12 @@
#pragma once
#include "DrawingProgramScreen.hpp"
#include "../Toolbar.hpp"
class PhoneDrawingProgramScreen : public DrawingProgramScreen {
public:
PhoneDrawingProgramScreen(MainProgram& m);
virtual void update() override;
virtual void gui_layout_run() override;
private:
void main_display();
};

View file

@ -4,6 +4,7 @@
#include "Helpers/FileDownloader.hpp"
#include "Screens/FileSelectScreen.hpp"
#include "Screens/DesktopDrawingProgramScreen.hpp"
#include "Screens/PhoneDrawingProgramScreen.hpp"
#include "VersionConstants.hpp"
#include "include/gpu/GpuTypes.h"
#include <SDL3/SDL_filesystem.h>
@ -525,6 +526,8 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char **argv) {
mS.m->window.canCreateSurfaces = true;
resize_window(mS);
mS.m->screen = std::make_unique<PhoneDrawingProgramScreen>(*mS.m);
if(listOfFilesToOpenFromCommand.empty()) {
mS.m->create_new_tab({
.isClient = false
@ -539,8 +542,6 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char **argv) {
}
}
mS.m->screen = std::make_unique<DrawingProgramScreen>(*mS.m);
mS.m->update(); // Run update once to make sure that callbacks dont crash
#ifdef NDEBUG