Separating safe window area from window area

This commit is contained in:
Yousef Khadadeh 2026-04-26 15:47:28 +03:00
parent 97d299a346
commit b1f6f04d37
18 changed files with 121 additions and 102 deletions

View file

@ -438,36 +438,59 @@ void DrawingProgram::selection_action_menu(Vector2f popupPos) {
GUIStuff::GUIManager& gui = world.main.g.gui;
right_click_action_menu(popupPos, [&] {
text_label_light(gui, "Selection menu");
popup_menu_action_button("Paste", "Paste", [&, popupPos] {
selection.deselect_all();
selection.paste_clipboard(popupPos * world.main.g.final_gui_scale());
});
popup_menu_action_button("Paste Image", "Paste Image", [&, popupPos] {
selection.deselect_all();
world.main.input.call_paste(CustomEvents::PasteEvent::DataType::IMAGE, {
.pastePosition = popupPos * world.main.g.final_gui_scale()
});
});
if(selection.is_something_selected()) {
popup_menu_action_button("Copy", "Copy", [&] {
selection.selection_to_clipboard();
});
popup_menu_action_button("Cut", "Cut", [&] {
selection.selection_to_clipboard();
selection.delete_all();
});
popup_menu_action_button("Delete", "Delete", [&] {
selection.delete_all();
});
popup_menu_action_button("Bring to front of layer", "Bring to front of layer", [&] {
selection.push_selection_to_front();
});
popup_menu_action_button("Send to back of layer", "Send to back of layer", [&] {
selection.push_selection_to_back();
});
}
});
}
void DrawingProgram::right_click_action_menu(Vector2f popupPos, const std::function<void()>& innerContent) {
using namespace GUIStuff;
using namespace ElementHelpers;
GUIStuff::GUIManager& gui = world.main.g.gui;
gui.set_z_index(-1, [&] {
gui.element<PositionAdjustingPopupMenu>("Selection popup menu", popupPos, [&] {
text_label_light(gui, "Selection menu");
popup_menu_action_button("Paste", "Paste", [&, popupPos] {
selection.deselect_all();
selection.paste_clipboard(popupPos * world.main.g.final_gui_scale());
});
popup_menu_action_button("Paste Image", "Paste Image", [&, popupPos] {
selection.deselect_all();
world.main.input.call_paste(CustomEvents::PasteEvent::DataType::IMAGE, {
.pastePosition = popupPos * world.main.g.final_gui_scale()
});
});
if(selection.is_something_selected()) {
popup_menu_action_button("Copy", "Copy", [&] {
selection.selection_to_clipboard();
});
popup_menu_action_button("Cut", "Cut", [&] {
selection.selection_to_clipboard();
selection.delete_all();
});
popup_menu_action_button("Delete", "Delete", [&] {
selection.delete_all();
});
popup_menu_action_button("Bring to front of layer", "Bring to front of layer", [&] {
selection.push_selection_to_front();
});
popup_menu_action_button("Send to back of layer", "Send to back of layer", [&] {
selection.push_selection_to_back();
});
CLAY_AUTO_ID({
.layout = {
.sizing = {.width = CLAY_SIZING_FIT(100), .height = CLAY_SIZING_FIT(0)},
.padding = CLAY_PADDING_ALL(gui.io.theme->padding1),
.childGap = 1,
.childAlignment = { .x = CLAY_ALIGN_X_CENTER, .y = CLAY_ALIGN_Y_TOP},
.layoutDirection = CLAY_TOP_TO_BOTTOM
},
.backgroundColor = convert_vec4<Clay_Color>(gui.io.theme->backColor1),
.cornerRadius = CLAY_CORNER_RADIUS(gui.io.theme->windowCorners1)
}) {
innerContent();
}
}, LayoutElement::Callbacks{
.mouseButton = [&](LayoutElement* l, const InputManager::MouseButtonCallbackArgs& button) {

View file

@ -84,6 +84,7 @@ class DrawingProgram {
void update_downloading_dropped_files();
void selection_action_menu(Vector2f popupPos);
void right_click_action_menu(Vector2f popupPos, const std::function<void()>& innerContent);
void popup_menu_action_button(const char* id, const char* text, const std::function<void()>& onClick);
void rebuild_cache();

View file

@ -282,34 +282,27 @@ void TextBoxEditTool::right_click_popup_gui(Toolbar& t, Vector2f popupPos) {
auto& gui = drawP.world.main.g.gui;
auto& a = static_cast<TextBoxCanvasComponent&>(comp->obj->get_comp());
gui.set_z_index(-1, [&] {
gui.element<PositionAdjustingPopupMenu>("Text popup menu", popupPos, [&] {
text_label_light(gui, "Text menu");
InputManager& input = drawP.world.main.input;
drawP.popup_menu_action_button("Paste", "Paste", [&] {
drawP.world.main.input.call_paste(CustomEvents::PasteEvent::DataType::TEXT, { .allowRichText = true });
});
drawP.popup_menu_action_button("Paste without formatting", "Paste without formatting", [&] {
drawP.world.main.input.call_paste(CustomEvents::PasteEvent::DataType::TEXT, { .allowRichText = false });
});
if(a.cursor->selectionBeginPos != a.cursor->selectionEndPos) {
drawP.popup_menu_action_button("Copy", "Copy", [&] {
input.set_clipboard_plain_and_richtext_pair(a.textBox->process_copy(*a.cursor));
});
drawP.popup_menu_action_button("Cut", "Cut", [&] {
userInput->do_textbox_operation_with_undo([&]() {
input.set_clipboard_plain_and_richtext_pair(a.textBox->process_cut(*a.cursor));
});
commit_update_and_layout_func();
set_styles_at_selection(a);
});
}
}, LayoutElement::Callbacks{
.mouseButton = [&](LayoutElement*, const InputManager::MouseButtonCallbackArgs& button) {
if(button.down && button.button != InputManager::MouseButton::RIGHT)
drawP.clear_right_click_popup();
}
drawP.right_click_action_menu(popupPos, [&] {
text_label_light(gui, "Text menu");
InputManager& input = drawP.world.main.input;
drawP.popup_menu_action_button("Paste", "Paste", [&] {
drawP.world.main.input.call_paste(CustomEvents::PasteEvent::DataType::TEXT, { .allowRichText = true });
});
drawP.popup_menu_action_button("Paste without formatting", "Paste without formatting", [&] {
drawP.world.main.input.call_paste(CustomEvents::PasteEvent::DataType::TEXT, { .allowRichText = false });
});
if(a.cursor->selectionBeginPos != a.cursor->selectionEndPos) {
drawP.popup_menu_action_button("Copy", "Copy", [&] {
input.set_clipboard_plain_and_richtext_pair(a.textBox->process_copy(*a.cursor));
});
drawP.popup_menu_action_button("Cut", "Cut", [&] {
userInput->do_textbox_operation_with_undo([&]() {
input.set_clipboard_plain_and_richtext_pair(a.textBox->process_cut(*a.cursor));
});
commit_update_and_layout_func();
set_styles_at_selection(a);
});
}
});
}

View file

@ -100,7 +100,7 @@ void GUIHolder::update() {
void GUIHolder::window_update() {
calculate_final_gui_scale();
gui.update_window(main.window.safeArea.min, main.window.safeArea.dim(), final_gui_scale());
gui.update_window(main.window.size.cast<float>(), main.window.safeArea, final_gui_scale());
}
float GUIHolder::final_gui_scale() {

View file

@ -2,6 +2,7 @@
#include <include/core/SkPath.h>
#include <include/core/SkPathBuilder.h>
#include "../GUIManager.hpp"
#include "../../TimePoint.hpp"
namespace GUIStuff {

View file

@ -1,7 +1,6 @@
#pragma once
#include "Helpers/ConvertVec.hpp"
#include <include/core/SkCanvas.h>
#include "../../TimePoint.hpp"
#include <Eigen/Dense>
#include <include/core/SkFont.h>
#include <include/core/SkFontMgr.h>
@ -12,7 +11,6 @@
#include <Helpers/SCollision.hpp>
#include <Helpers/Serializers.hpp>
#include <nlohmann/json.hpp>
#include "../../RichText/TextBox.hpp"
#include "../../InputManager.hpp"
#include "../GUIManagerID.hpp"
@ -108,8 +106,8 @@ struct UpdateInputData {
float deltaTime = 0.0f;
float guiScaleMultiplier = 1.0f;
Vector2f windowPos = {0.0f, 0.0f};
Vector2f windowSize = {0.0f, 0.0f};
SCollision::AABB<float> safeWindowRect;
std::shared_ptr<FontData> fonts;
sk_sp<SkTypeface> textTypeface;

View file

@ -11,7 +11,7 @@ void PositionAdjustingPopupMenu::layout(const Clay_ElementId& id, Vector2f popup
auto& bb = layoutElement->get_bb().value();
if((popupPos.y() + bb.height()) > gui.io.windowSize.y())
popupPos.y() -= bb.height();
if((popupPos.x() + bb.width()) > gui.io.windowSize.x())
if((popupPos.x() + bb.width()) > gui.io.windowSize.y())
popupPos.x() -= bb.width();
}

View file

@ -1,5 +1,6 @@
#include "RadioButton.hpp"
#include "../GUIManager.hpp"
#include "../../TimePoint.hpp"
namespace GUIStuff {

View file

@ -73,7 +73,7 @@ template <typename T> void TextBox<T>::clay_draw(SkCanvas* canvas, UpdateInputDa
template <typename T> void TextBox<T>::select() {
if(!is_selected()) {
SCollision::AABB<float> rect = {(boundingBox.value().min + gui.io.windowPos) * gui.io.guiScaleMultiplier, (boundingBox.value().max + gui.io.windowPos) * gui.io.guiScaleMultiplier};
SCollision::AABB<float> rect = {boundingBox.value().min * gui.io.guiScaleMultiplier, boundingBox.value().max * gui.io.guiScaleMultiplier};
unsigned id = gui.io.input->set_text_box_front(rect, userInfo.textInputProps);
edit = TextEditData(id, textbox, cur);
}

View file

@ -74,11 +74,8 @@ void GUIManager::clip_rect_transform(SkCanvas* canvas, std::vector<SCollision::A
SCollision::AABB<float> c = clipRect.value();
c.min *= io.guiScaleMultiplier;
c.max *= io.guiScaleMultiplier;
c.min += io.windowPos;
c.max += io.windowPos;
canvas->clipIRect(c.get_sk_irect());
}
canvas->translate(io.windowPos.x(), io.windowPos.y());
canvas->scale(io.guiScaleMultiplier, io.guiScaleMultiplier);
}
@ -286,7 +283,6 @@ void GUIManager::draw(SkCanvas* c, bool skiaAA) {
void GUIManager::draw_force(SkCanvas* canvas, bool skiaAA) {
canvas->save();
canvas->translate(io.windowPos.x(), io.windowPos.y());
canvas->scale(io.guiScaleMultiplier, io.guiScaleMultiplier);
for(size_t i = 0; i < static_cast<size_t>(renderCommands.length); i++) {
@ -521,13 +517,15 @@ GUIFloatAnimation* GUIManager::float_animation(const char* animationID, const GU
return toRet;
}
void GUIManager::update_window(const Vector2f& windowPos, const Vector2f& windowSize, float guiScaleMultiplier) {
if(io.windowPos != windowPos || io.windowSize != windowSize || io.guiScaleMultiplier != guiScaleMultiplier) {
void GUIManager::update_window(const Vector2f& windowSize, const SCollision::AABB<float>& safeWindowRect, float guiScaleMultiplier) {
if(io.windowSize != windowSize || io.safeWindowRect != safeWindowRect || io.guiScaleMultiplier != guiScaleMultiplier) {
io.redrawSurface = true;
set_to_layout();
}
io.windowPos = windowPos;
io.windowSize = windowSize / guiScaleMultiplier;
io.safeWindowRect = safeWindowRect;
io.safeWindowRect.min /= guiScaleMultiplier;
io.safeWindowRect.max /= guiScaleMultiplier;
io.guiScaleMultiplier = guiScaleMultiplier;
}
@ -692,19 +690,16 @@ void GUIManager::input_key_callback(const InputManager::KeyCallbackArgs& key) {
}
void GUIManager::input_mouse_button_callback(InputManager::MouseButtonCallbackArgs button) {
button.pos -= io.windowPos;
button.pos /= io.guiScaleMultiplier;
mouse_callback(button.pos, [&button] (ElementContainer* e) { e->elem->input_mouse_button_callback(button); });
}
void GUIManager::input_mouse_motion_callback(InputManager::MouseMotionCallbackArgs motion) {
motion.pos -= io.windowPos;
motion.pos /= io.guiScaleMultiplier;
mouse_callback(motion.pos, [&motion] (ElementContainer* e) { e->elem->input_mouse_motion_callback(motion); });
}
void GUIManager::input_mouse_wheel_callback(InputManager::MouseWheelCallbackArgs wheel) {
wheel.mousePos -= io.windowPos;
wheel.mousePos /= io.guiScaleMultiplier;
mouse_callback(wheel.mousePos, [&wheel] (ElementContainer* e) { e->elem->input_mouse_wheel_callback(wheel); });
}

View file

@ -26,7 +26,7 @@ class GUIManager {
GUIFloatAnimation* float_animation(const char* animationID, const GUIFloatAnimationData& animation);
void update();
void update_window(const Vector2f& windowPos, const Vector2f& windowSize, float guiScaleMultiplier);
void update_window(const Vector2f& windowRect, const SCollision::AABB<float>& safeWindowRect, float guiScaleMultiplier);
UpdateInputData io;

View file

@ -128,7 +128,7 @@ void FileSelectScreen::main_display() {
main_menu();
CLAY_AUTO_ID({
.layout = {
.sizing = {.width = CLAY_SIZING_FIXED(gui.io.windowSize.x()), .height = CLAY_SIZING_GROW(0)},
.sizing = {.width = CLAY_SIZING_FIXED(gui.io.safeWindowRect.width()), .height = CLAY_SIZING_GROW(0)},
.childAlignment = { .x = CLAY_ALIGN_X_CENTER, .y = CLAY_ALIGN_Y_TOP },
.layoutDirection = CLAY_TOP_TO_BOTTOM,
},

View file

@ -22,35 +22,39 @@ void PhoneDrawingProgramScreen::gui_layout_run() {
}
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);
}
});
}
});
top_toolbar();
}
}
void PhoneDrawingProgramScreen::top_toolbar() {
auto& gui = main.g.gui;
auto& io = gui.io;
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

@ -8,5 +8,6 @@ class PhoneDrawingProgramScreen : public DrawingProgramScreen {
virtual void update() override;
virtual void gui_layout_run() override;
private:
void top_toolbar();
void main_display();
};

View file

@ -216,7 +216,7 @@ void Toolbar::layout_run() {
if(drawGui) {
CLAY_AUTO_ID({
.layout = {
.sizing = {.width = CLAY_SIZING_FIT(gui.io.windowSize.x()), .height = CLAY_SIZING_FIT(gui.io.windowSize.y())},
.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0)},
.padding = CLAY_PADDING_ALL(io.theme->padding1),
.childGap = io.theme->childGap1,
.childAlignment = { .x = CLAY_ALIGN_X_CENTER, .y = CLAY_ALIGN_Y_TOP},

View file

@ -1,6 +1,7 @@
#pragma once
#include "GUIStuff/Elements/ScrollArea.hpp"
#include "DrawData.hpp"
#include "TimePoint.hpp"
#include "Helpers/FileDownloader.hpp"
#include <filesystem>
#include <modules/skparagraph/include/Paragraph.h>