Created RichText namespace, and tweaked scrollbar behaviour
This commit is contained in:
parent
e0143f49f0
commit
435d9346a9
17 changed files with 163 additions and 139 deletions
|
|
@ -10,7 +10,7 @@
|
|||
#include <Helpers/SCollision.hpp>
|
||||
#include <Helpers/Serializers.hpp>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include "../../RichTextBox/RichTextBox.hpp"
|
||||
#include "../../RichText/TextBox.hpp"
|
||||
|
||||
using namespace Eigen;
|
||||
|
||||
|
|
@ -103,7 +103,7 @@ struct UpdateInputData {
|
|||
std::optional<std::string> textOut;
|
||||
} clipboard;
|
||||
|
||||
std::function<void(std::shared_ptr<RichTextBox>, std::shared_ptr<RichTextBox::Cursor>)> richTextBoxEdit;
|
||||
std::function<void(std::shared_ptr<RichText::TextBox>, std::shared_ptr<RichText::TextBox::Cursor>)> richTextBoxEdit;
|
||||
|
||||
SkFont get_font(float fSize) const;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
#include "Element.hpp"
|
||||
#include "../../RichTextBox/RichTextBox.hpp"
|
||||
#include "../../RichText/TextBox.hpp"
|
||||
#include <limits>
|
||||
#include <modules/skparagraph/include/TextStyle.h>
|
||||
|
||||
|
|
@ -73,7 +73,7 @@ template <typename T> class TextBox : public Element {
|
|||
|
||||
canvas->translate(bb.min.x() + 2.0f, bb.min.y());
|
||||
|
||||
RichTextBox::PaintOpts paintOpts;
|
||||
RichText::TextBox::PaintOpts paintOpts;
|
||||
if(selection.selected)
|
||||
paintOpts.cursor = *cur;
|
||||
paintOpts.cursorColor = {io.theme->fillColor1.fR, io.theme->fillColor1.fG, io.theme->fillColor1.fB};
|
||||
|
|
@ -97,11 +97,11 @@ template <typename T> class TextBox : public Element {
|
|||
if(data && (*data == oldData) && !reallyForce && textbox && cur)
|
||||
return;
|
||||
|
||||
textbox = std::make_shared<RichTextBox>();
|
||||
textbox = std::make_shared<RichText::TextBox>();
|
||||
textbox->set_font_collection(io.fontCollection);
|
||||
textbox->set_allow_newlines(!singleLine);
|
||||
|
||||
cur = std::make_shared<RichTextBox::Cursor>();
|
||||
cur = std::make_shared<RichText::TextBox::Cursor>();
|
||||
|
||||
if(data) {
|
||||
cur->pos = cur->selectionBeginPos = cur->selectionEndPos = textbox->insert({0, 0}, toStr(*data));
|
||||
|
|
@ -125,8 +125,8 @@ template <typename T> class TextBox : public Element {
|
|||
std::function<std::optional<T>(const std::string&)> fromStr;
|
||||
std::function<std::string(const T&)> toStr;
|
||||
|
||||
std::shared_ptr<RichTextBox> textbox;
|
||||
std::shared_ptr<RichTextBox::Cursor> cur;
|
||||
std::shared_ptr<RichText::TextBox> textbox;
|
||||
std::shared_ptr<RichText::TextBox::Cursor> cur;
|
||||
|
||||
SCollision::AABB<float> bb;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -669,7 +669,6 @@ void GUIManager::scroll_bar_area(const std::string& id, const std::function<void
|
|||
float currentScrollPos = 0.0f;
|
||||
bool isMoving = false;
|
||||
|
||||
bool clickedOnScroller = false;
|
||||
float scrollerStartPos;
|
||||
float mouseStartPos;
|
||||
|
||||
|
|
@ -749,20 +748,17 @@ void GUIManager::scroll_bar_area(const std::string& id, const std::function<void
|
|||
CLAY({ .layout = {.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0)}}}) {}
|
||||
if(Clay_Hovered() && io->mouse.leftClick) {
|
||||
sD.isMoving = true;
|
||||
sD.clickedOnScroller = isHoveringOverScroller;
|
||||
if(isHoveringOverScroller) {
|
||||
if(isHoveringOverScroller)
|
||||
sD.scrollerStartPos = scrollAreaBB.y + areaAboveScrollerSize + scrollerSize * 0.5f;
|
||||
sD.mouseStartPos = io->mouse.pos.y();
|
||||
}
|
||||
else
|
||||
sD.scrollerStartPos = std::clamp(io->mouse.pos.y(), scrollAreaBB.y + scrollerSize * 0.5f, scrollAreaBB.y + scrollAreaBB.height - scrollerSize * 0.5f);
|
||||
sD.mouseStartPos = io->mouse.pos.y();
|
||||
}
|
||||
if(!io->mouse.leftHeld)
|
||||
sD.isMoving = false;
|
||||
if(sD.isMoving) {
|
||||
float newScrollPosFrac;
|
||||
if(sD.clickedOnScroller)
|
||||
newScrollPosFrac = std::clamp((sD.scrollerStartPos - (sD.mouseStartPos - io->mouse.pos.y()) - scrollAreaBB.y - scrollerSize * 0.5f) / (scrollAreaBB.height - scrollerSize), 0.0f, 1.0f);
|
||||
else
|
||||
newScrollPosFrac = std::clamp((io->mouse.pos.y() - scrollAreaBB.y - scrollerSize * 0.5f) / (scrollAreaBB.height - scrollerSize), 0.0f, 1.0f);
|
||||
newScrollPosFrac = std::clamp((sD.scrollerStartPos - (sD.mouseStartPos - io->mouse.pos.y()) - scrollAreaBB.y - scrollerSize * 0.5f) / (scrollAreaBB.height - scrollerSize), 0.0f, 1.0f);
|
||||
sD.currentScrollPos = newScrollPosFrac * (-scrollPosMax);
|
||||
}
|
||||
sD.currentScrollPos = std::clamp(sD.currentScrollPos, -scrollPosMax, 0.0f);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue