Added more settings and actions to phone version

This commit is contained in:
Yousef Khadadeh 2026-05-12 21:13:31 +03:00
parent fd2ce71db6
commit 1b99c64c1b
21 changed files with 388 additions and 179 deletions

View file

@ -22,7 +22,7 @@
DesktopDrawingProgramScreen::DesktopDrawingProgramScreen(MainProgram& m):
DrawingProgramScreen(m),
toolbar(m)
toolbar(m, *this)
{}
void DesktopDrawingProgramScreen::update() {
@ -76,3 +76,10 @@ void DesktopDrawingProgramScreen::input_text_key_callback(const InputManager::Ke
}
DrawingProgramScreen::input_text_key_callback(key);
}
void DesktopDrawingProgramScreen::open_file_selector(const std::string& filePickerName, const std::vector<ExtensionFilter>& extensionFilters, OpenFileSelectorCallback postSelectionFunc, const std::string& fileName, bool isSaving) {
if(main.conf.useNativeFilePicker)
Screen::open_file_selector(filePickerName, extensionFilters, postSelectionFunc, fileName, isSaving);
else
toolbar.open_file_selector_non_native(filePickerName, extensionFilters, postSelectionFunc, fileName, isSaving);
}

View file

@ -28,6 +28,8 @@ class DesktopDrawingProgramScreen : public DrawingProgramScreen {
virtual bool app_close_requested() override;
virtual void input_key_callback(const InputManager::KeyCallbackArgs& key) override;
virtual void input_text_key_callback(const InputManager::KeyCallbackArgs& key) override;
virtual void open_file_selector(const std::string& filePickerName, const std::vector<ExtensionFilter>& extensionFilters, OpenFileSelectorCallback postSelectionFunc, const std::string& fileName = "", bool isSaving = false) override;
private:
Toolbar toolbar;
};

View file

@ -29,6 +29,8 @@
#include "../GUIStuff/Elements/SVGIcon.hpp"
#include "../GUIStuff/Elements/TextParagraph.hpp"
#include "../GUIStuff/ElementHelpers/LayoutHelpers.hpp"
#include "../GUIStuff/ElementHelpers/ColorPickerHelpers.hpp"
#include "../GUIStuff/ElementHelpers/CheckBoxHelpers.hpp"
#include "../GUIStuff/Elements/PositionAdjustingPopupMenu.hpp"
#include "../World.hpp"
#include "Helpers/StringHelpers.hpp"
@ -181,15 +183,17 @@ void FileSelectScreen::main_display() {
.layoutDirection = CLAY_TOP_TO_BOTTOM,
},
}) {
file_view();
switch(selectedMenu) {
case SelectedMenu::FILES:
file_view();
if(!editMode)
create_file_button();
break;
case SelectedMenu::TRASH:
file_view();
break;
case SelectedMenu::SETTINGS:
settings_view();
break;
}
}
@ -479,51 +483,71 @@ void FileSelectScreen::title_bar() {
}
});
if(moreButton->get_bb().has_value() && moreOptionsMenu != MoreOptionsMenu::CLOSED) {
size_t elemCount = 0;
if(moreOptionsMenu == MoreOptionsMenu::MAIN)
elemCount = 2;
else if(moreOptionsMenu == MoreOptionsMenu::VIEW)
elemCount = 4;
gui.set_z_index(gui.get_z_index() + 10, [&] {
gui.element<PositionAdjustingPopupMenu>("more options popup", moreButton->get_bb().value().top_right(), [&] {
CLAY_AUTO_ID({
.layout = {
.sizing = {.width = CLAY_SIZING_FIT(200), .height = CLAY_SIZING_FIT(0)},
.layoutDirection = CLAY_TOP_TO_BOTTOM
},
.backgroundColor = convert_vec4<Clay_Color>(gui.io.theme->backColor1),
.cornerRadius = CLAY_CORNER_RADIUS(4)
}) {
dropdown_many_element_popup_layout(gui, "more options popup", {
.button = moreButton,
.clickUpAwayCallback = [&] {
gui.set_post_callback_func_high_priority([&] { // Cancel actions on other buttons
moreOptionsMenu = MoreOptionsMenu::CLOSED;
main.g.gui.set_to_layout();
});
},
.entrySize = {200.0f, 30.0f},
.entryCount = elemCount,
.entryLayout = [&] (size_t i) {
if(moreOptionsMenu == MoreOptionsMenu::MAIN) {
text_transparent_option_button("Edit", "Edit", [&] {
moreOptionsMenu = MoreOptionsMenu::CLOSED;
start_edit_mode();
});
text_transparent_option_button("View", "View", [&] {
moreOptionsMenu = MoreOptionsMenu::VIEW;
});
switch(i) {
case 0: {
text_transparent_option_button("Edit", "Edit", [&] {
moreOptionsMenu = MoreOptionsMenu::CLOSED;
start_edit_mode();
});
break;
}
case 1: {
text_transparent_option_button("View", "View", [&] {
moreOptionsMenu = MoreOptionsMenu::VIEW;
});
break;
}
}
}
else if(moreOptionsMenu == MoreOptionsMenu::VIEW) {
text_transparent_option_button("Large Grid", "Large Grid", [&] {
fileViewType = FileViewType::LARGE_GRID;
moreOptionsMenu = MoreOptionsMenu::CLOSED;
});
text_transparent_option_button("Medium Grid", "Medium Grid", [&] {
fileViewType = FileViewType::MEDIUM_GRID;
moreOptionsMenu = MoreOptionsMenu::CLOSED;
});
text_transparent_option_button("Small Grid", "Small Grid", [&] {
fileViewType = FileViewType::SMALL_GRID;
moreOptionsMenu = MoreOptionsMenu::CLOSED;
});
text_transparent_option_button("List", "List", [&] {
fileViewType = FileViewType::LIST;
moreOptionsMenu = MoreOptionsMenu::CLOSED;
});
}
}
}, LayoutElement::Callbacks{
.onClick = [&](LayoutElement* l, const InputManager::MouseButtonCallbackArgs& m) {
if(!l->mouseHovering && !m.down) {
gui.set_post_callback_func_high_priority([&] { // Cancel actions on other buttons
moreOptionsMenu = MoreOptionsMenu::CLOSED;
main.g.gui.set_to_layout();
});
switch(i) {
case 0: {
text_transparent_option_button("Large Grid", "Large Grid", [&] {
fileViewType = FileViewType::LARGE_GRID;
moreOptionsMenu = MoreOptionsMenu::CLOSED;
});
break;
}
case 1: {
text_transparent_option_button("Medium Grid", "Medium Grid", [&] {
fileViewType = FileViewType::MEDIUM_GRID;
moreOptionsMenu = MoreOptionsMenu::CLOSED;
});
break;
}
case 2: {
text_transparent_option_button("Small Grid", "Small Grid", [&] {
fileViewType = FileViewType::SMALL_GRID;
moreOptionsMenu = MoreOptionsMenu::CLOSED;
});
break;
}
case 3: {
text_transparent_option_button("List", "List", [&] {
fileViewType = FileViewType::LIST;
moreOptionsMenu = MoreOptionsMenu::CLOSED;
});
break;
}
}
}
}
});
@ -541,6 +565,7 @@ void FileSelectScreen::text_transparent_option_button(const char* id, const char
text_button(gui, id, text, {
.drawType = SelectableButton::DrawType::TRANSPARENT_ALL,
.wide = true,
.growHeight = true,
.centered = false,
.onClick = onClick
});
@ -569,7 +594,7 @@ void FileSelectScreen::main_menu() {
gui.element<LayoutElement>("inner main menu element", [&] (LayoutElement*, const Clay_ElementId& lId) {
CLAY(lId, {
.layout = {
.sizing = {.width = CLAY_SIZING_FIXED(300.0f * mainMenuOpenAnim->get_val()), .height = CLAY_SIZING_GROW(0)},
.sizing = {.width = CLAY_SIZING_FIXED(200.0f * mainMenuOpenAnim->get_val()), .height = CLAY_SIZING_GROW(0)},
.padding = CLAY_PADDING_ALL(gui.io.theme->padding1),
.layoutDirection = CLAY_TOP_TO_BOTTOM,
},
@ -579,18 +604,18 @@ void FileSelectScreen::main_menu() {
selectedMenu = SelectedMenu::FILES;
update_file_list(fileList, savePath, false);
mainMenuOpenAnim->animation_trigger_reverse();
if(fileViewScrollArea) fileViewScrollArea->reset_scroll();
if(mainViewScrollArea) mainViewScrollArea->reset_scroll();
});
icon_text_transparent_option_selected_button("Trash", "data/icons/trash.svg", "Trash", selectedMenu == SelectedMenu::TRASH, [&] {
selectedMenu = SelectedMenu::TRASH;
update_file_list(fileList, trashPath, true);
mainMenuOpenAnim->animation_trigger_reverse();
if(fileViewScrollArea) fileViewScrollArea->reset_scroll();
if(mainViewScrollArea) mainViewScrollArea->reset_scroll();
});
icon_text_transparent_option_selected_button("Settings", "data/icons/RemixIcon/settings-3-line.svg", "Settings", selectedMenu == SelectedMenu::SETTINGS, [&] {
selectedMenu = SelectedMenu::SETTINGS;
mainMenuOpenAnim->animation_trigger_reverse();
if(fileViewScrollArea) fileViewScrollArea->reset_scroll();
if(mainViewScrollArea) mainViewScrollArea->reset_scroll();
});
}
}
@ -602,11 +627,6 @@ void FileSelectScreen::main_menu() {
}
void FileSelectScreen::file_view() {
if(selectedMenu == SelectedMenu::SETTINGS) {
fileViewScrollArea = nullptr;
return;
}
auto& gui = main.g.gui;
std::filesystem::path folderPath = (selectedMenu == SelectedMenu::TRASH) ? trashPath : savePath;
@ -615,14 +635,21 @@ void FileSelectScreen::file_view() {
gui.element<SelectableButton>("file button", SelectableButton::Data{
.isSelected = editMode && fileList[i].selected,
.onClick = [&, filePath, i] {
if(editMode)
if(selectedMenu == SelectedMenu::TRASH) {
if(!editMode)
start_edit_mode();
fileList[i].selected = !fileList[i].selected;
}
else {
CustomEvents::emit_event<CustomEvents::OpenInfiniPaintFileEvent>({
.isClient = false,
.saveThumbnail = true,
.filePathSource = filePath
});
if(editMode)
fileList[i].selected = !fileList[i].selected;
else {
CustomEvents::emit_event<CustomEvents::OpenInfiniPaintFileEvent>({
.isClient = false,
.saveThumbnail = true,
.filePathSource = filePath
});
}
}
},
.innerContent = [&](const SelectableButton::InnerContentCallbackParameters& c){
@ -701,7 +728,7 @@ void FileSelectScreen::file_view() {
};
if(fileViewType == FileViewType::LIST) {
fileViewScrollArea = gui.element<ManyElementScrollArea>("File selector list", ManyElementScrollArea::Options{
mainViewScrollArea = gui.element<ManyElementScrollArea>("File selector list", ManyElementScrollArea::Options{
.entryHeight = 150.0f,
.entryCount = fileList.size(),
.clipHorizontal = true,
@ -730,7 +757,7 @@ void FileSelectScreen::file_view() {
default:
break;
}
fileViewScrollArea = gui.element<GridScrollArea>("File selector grid", GridScrollArea::Options{
mainViewScrollArea = gui.element<GridScrollArea>("File selector grid", GridScrollArea::Options{
.entryWidth = entrySize.x(),
.childAlignmentX = CLAY_ALIGN_X_LEFT,
.entryHeight = entrySize.y(),
@ -743,6 +770,40 @@ void FileSelectScreen::file_view() {
}
}
void FileSelectScreen::settings_view() {
auto& gui = main.g.gui;
mainViewScrollArea = gui.element<ScrollArea>("settings scroll area", ScrollArea::Options{
.scrollVertical = true,
.clipVertical = true,
.scrollbarY = ScrollArea::ScrollbarType::NORMAL,
.innerContent = [&] (auto&) {
CLAY_AUTO_ID({
.layout = {
.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0)},
.layoutDirection = CLAY_LEFT_TO_RIGHT
},
}) {
CLAY_AUTO_ID({
.layout = {
.sizing = {.width = CLAY_SIZING_GROW(0, 300), .height = CLAY_SIZING_GROW(0)},
.childGap = gui.io.theme->childGap1,
.layoutDirection = CLAY_TOP_TO_BOTTOM
},
}) {
color_picker_button_field(gui, "defaultCanvasBackgroundColor", "Default canvas background color", &main.conf.defaultCanvasBackgroundColor, { .hasAlpha = false });
input_scalar_field(gui, "Max GUI Scale", "Max GUI Scale", &main.conf.guiScale, 1.0f, 2.0f, {
.decimalPrecision = 1,
.onEdit = [&] { main.g.window_update(); }
});
input_scalar_field(gui, "jump transition time", "Jump transition time", &main.conf.jumpTransitionTime, 0.01f, 1000.0f, {.decimalPrecision = 2});
checkbox_boolean_field(gui, "make all tools share same size", "Make all tools share size", &main.toolConfig.globalConf.useGlobalRelativeWidth);
}
}
}
});
}
void FileSelectScreen::menu_black_box() {
auto& gui = main.g.gui;
if(!mainMenuOpenAnim->is_at_start()) {

View file

@ -63,11 +63,12 @@ class FileSelectScreen : public Screen {
GUIStuff::GUIFloatAnimation* mainMenuOpenAnim = nullptr;
GUIStuff::GUIFloatAnimation* actionBarOpenAnim = nullptr;
GUIStuff::ScrollArea* fileViewScrollArea = nullptr;
GUIStuff::ScrollArea* mainViewScrollArea = nullptr;
void main_display();
void main_menu();
void file_view();
void settings_view();
void create_file_button();
void file_view_edit();
void menu_black_box();

View file

@ -174,6 +174,20 @@ void PhoneDrawingProgramScreen::top_toolbar_remaining_area() {
void PhoneDrawingProgramScreen::top_toolbar_hidden_button_popup(GUIStuff::Element* b, std::vector<TopToolbarRemainingAreaButton> l) {
auto& gui = main.g.gui;
l.emplace_back(TopToolbarRemainingAreaButton{
.name = "Add Image",
.svgPath = "data/icons/RemixIcon/image-add-line.svg",
.onClick = [&] {
open_file_selector("Open File", {{"Any File", "*"}}, [&](const std::filesystem::path& p, const auto& e) {
CustomEvents::emit_event<CustomEvents::AddFileToCanvasEvent>({
.type = CustomEvents::AddFileToCanvasEvent::Type::PATH,
.filePath = p,
.pos = main.window.size.cast<float>() / 2.0f
});
});
}
});
l.emplace_back(TopToolbarRemainingAreaButton{
.name = "Canvas Color",
.svgPath = "data/icons/RemixIcon/settings-3-line.svg",
@ -191,7 +205,7 @@ void PhoneDrawingProgramScreen::top_toolbar_hidden_button_popup(GUIStuff::Elemen
gui.set_z_index(gui.get_z_index() + 1, [&] {
dropdown_many_element_popup_layout(gui, "top toolbar hidden button popup", {
.button = b,
.isOpen = &topToolbarButtonPopupOpen,
.clickAwayCallback = [&] { topToolbarButtonPopupOpen = false; },
.entrySize = {150.0f, 30.0f},
.entryCount = l.size(),
.entryLayout = [&] (size_t i) {

View file

@ -17,11 +17,45 @@
*/
#include "Screen.hpp"
#include "../MainProgram.hpp"
Screen::Screen(MainProgram& m):
main(m)
{}
Screen::NativeFilePicker Screen::nativeFilePicker;
// You can't trust that filter wont be -1 on the platform youre on, so dont use the extension from the callback
void Screen::sdl_open_file_dialog_callback(void* userData, const char * const * fileList, int filter) {
if(!fileList) {
nativeFilePicker.isOpen = false;
return;
}
if(!(*fileList)) {
nativeFilePicker.isOpen = false;
return;
}
ExtensionFilter e;
if(filter >= 0)
e = nativeFilePicker.extensionFiltersComplete[filter];
nativeFilePicker.postSelectionFunc(fileList[0], e);
nativeFilePicker.isOpen = false;
}
void Screen::open_file_selector(const std::string& filePickerName, const std::vector<ExtensionFilter>& extensionFilters, OpenFileSelectorCallback postSelectionFunc, const std::string& fileName, bool isSaving) {
if(!nativeFilePicker.isOpen) {
nativeFilePicker.postSelectionFunc = postSelectionFunc;
nativeFilePicker.extensionFiltersComplete = extensionFilters;
nativeFilePicker.sdlFileFilters.clear();
for(auto& e : nativeFilePicker.extensionFiltersComplete)
nativeFilePicker.sdlFileFilters.emplace_back(e.name.c_str(), e.extensions.c_str());
if(isSaving)
SDL_ShowSaveFileDialog(sdl_open_file_dialog_callback, nullptr, main.window.sdlWindow, nativeFilePicker.sdlFileFilters.data(), nativeFilePicker.sdlFileFilters.size(), nullptr);
else
SDL_ShowOpenFileDialog(sdl_open_file_dialog_callback, nullptr, main.window.sdlWindow, nativeFilePicker.sdlFileFilters.data(), nativeFilePicker.sdlFileFilters.size(), nullptr, false);
}
}
void Screen::update() {}
void Screen::gui_layout_run() {}
bool Screen::app_close_requested() { return true; }

View file

@ -25,6 +25,20 @@ class Screen {
virtual void update();
virtual void draw(SkCanvas* canvas) = 0;
struct ExtensionFilter {
std::string name;
std::string extensions;
};
typedef std::function<void(const std::filesystem::path&, const ExtensionFilter& extensionSelected)> OpenFileSelectorCallback;
struct NativeFilePicker {
std::atomic<bool> isOpen = false;
std::vector<ExtensionFilter> extensionFiltersComplete;
std::vector<SDL_DialogFileFilter> sdlFileFilters;
OpenFileSelectorCallback postSelectionFunc;
};
static NativeFilePicker nativeFilePicker;
virtual void gui_layout_run();
virtual bool app_close_requested();
virtual void input_add_file_to_canvas_callback(const CustomEvents::AddFileToCanvasEvent& addFile);
@ -53,7 +67,11 @@ class Screen {
virtual void input_app_about_to_go_to_background_callback();
virtual std::optional<InputManager::TextBoxStartInfo> get_text_box_start_info();
virtual void open_file_selector(const std::string& filePickerName, const std::vector<ExtensionFilter>& extensionFilters, OpenFileSelectorCallback postSelectionFunc, const std::string& fileName = "", bool isSaving = false);
virtual ~Screen();
protected:
static void sdl_open_file_dialog_callback(void* userData, const char * const * fileList, int filter);
MainProgram& main;
};