Skip to content

Commit

Permalink
Allow getting normal std::string for text (s6SM3t3gCS) & small updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Neko-Box-Coder committed May 21, 2023
1 parent 73682fb commit 0377fb3
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 72 deletions.
156 changes: 87 additions & 69 deletions Include/ssGUI/GUIObjectClasses/Text.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,40 +25,40 @@ namespace ssGUI
Variables & Constructor:
============================== C++ ==============================
protected:
bool RecalculateTextNeeded; //(Internal variable) Flag to recalculate all the cahracters locations
//TODO: Maybe just use redraw flag?
ssGUI::SegmentedVector<ssGUI::CharacterDetails> CurrentCharactersDetails; //See <GetCharacterDetails>
std::vector<ssGUI::CharacterRenderInfo> CharactersRenderInfos; //(Internal variable) Vertices for rendering characters
std::unordered_map<int, ssGUI::CharacterDetails> ProcessedCharacterDetails; //(Internal variable) Valid characters for rendering
bool Overflow; //See <IsOverflow>
float FontSize; //See <GetNewTextFontSize>
glm::u8vec4 TextColor; //See <GetNewTextColor>
bool TextUnderline; //See <IsNewTextUnderlined>
bool MultilineAllowed; //See <IsMultilineAllowed>
ssGUI::Enums::TextWrapping WrappingMode; //See <GetWrappingMode>
ssGUI::Enums::AlignmentHorizontal CurrentHorizontalAlignment; //See <GetTextHorizontalAlignment>
ssGUI::Enums::AlignmentVertical CurrentVerticalAlignment; //See <GetTextVerticalAlignment>
std::vector<ssGUI::Font*> CurrentFonts; //See <GetFont>
float HorizontalPadding; //See <GetTextHorizontalPadding>
float VerticalPadding; //See <GetTextVerticalPadding>
float CharacterSpace; //See <GetCharacterSpace>
float LineSpace; //See <GetLineSpace>
float TabSize; //See <GetTabSize>
bool SelectionAllowed; //See <IsTextSelectionAllowed>
int StartSelectionIndex; //See <GetStartSelectionIndex>
int EndSelectionIndex; //See <GetEndSelectionIndex>
glm::u8vec4 SelectionColor; //See <GetSelectionColor>
glm::u8vec4 TextSelectedColor; //See <GetTextSelectedColor>
uint32_t LastDefaultFontsID; //(Internal variable) Used to keep track if there's any changes to the default fonts
static int TextObjectCount; //(Internal variable) Used for deallocating default resources
static std::vector<ssGUI::Font*> DefaultFonts; //See <GetDefaultFont>
static uint32_t DefaultFontsChangeID; //(Internal variable) Used to track default font changes
bool RecalculateTextNeeded; //(Internal variable) Flag to recalculate all the cahracters locations
//TODO: Maybe just use redraw flag?
mutable ssGUI::SegmentedVector<ssGUI::CharacterDetails> CurrentCharactersDetails; //See <GetCharacterDetails>
std::vector<ssGUI::CharacterRenderInfo> CharactersRenderInfos; //(Internal variable) Vertices for rendering characters
std::unordered_map<int, ssGUI::CharacterDetails> ProcessedCharacterDetails; //(Internal variable) Valid characters for rendering
bool Overflow; //See <IsOverflow>
float FontSize; //See <GetNewTextFontSize>
glm::u8vec4 TextColor; //See <GetNewTextColor>
bool TextUnderline; //See <IsNewTextUnderlined>
bool MultilineAllowed; //See <IsMultilineAllowed>
ssGUI::Enums::TextWrapping WrappingMode; //See <GetWrappingMode>
ssGUI::Enums::AlignmentHorizontal CurrentHorizontalAlignment; //See <GetTextHorizontalAlignment>
ssGUI::Enums::AlignmentVertical CurrentVerticalAlignment; //See <GetTextVerticalAlignment>
std::vector<ssGUI::Font*> CurrentFonts; //See <GetFont>
float HorizontalPadding; //See <GetTextHorizontalPadding>
float VerticalPadding; //See <GetTextVerticalPadding>
float CharacterSpace; //See <GetCharacterSpace>
float LineSpace; //See <GetLineSpace>
float TabSize; //See <GetTabSize>
bool SelectionAllowed; //See <IsTextSelectionAllowed>
int StartSelectionIndex; //See <GetStartSelectionIndex>
int EndSelectionIndex; //See <GetEndSelectionIndex>
glm::u8vec4 SelectionColor; //See <GetSelectionColor>
glm::u8vec4 TextSelectedColor; //See <GetTextSelectedColor>
uint32_t LastDefaultFontsID; //(Internal variable) Used to keep track if there's any changes to the default fonts
static int TextObjectCount; //(Internal variable) Used for deallocating default resources
static std::vector<ssGUI::Font*> DefaultFonts; //See <GetDefaultFont>
static uint32_t DefaultFontsChangeID; //(Internal variable) Used to track default font changes
=================================================================
============================== C++ ==============================
Text::Text() : RecalculateTextNeeded(false),
Expand Down Expand Up @@ -130,40 +130,40 @@ namespace ssGUI
Text& operator=(Text const& other);

protected:
bool RecalculateTextNeeded; //(Internal variable) Flag to recalculate all the cahracters locations
//TODO: Maybe just use redraw flag?
ssGUI::SegmentedVector<ssGUI::CharacterDetails> CurrentCharactersDetails; //See <GetCharacterDetails>

std::vector<ssGUI::CharacterRenderInfo> CharactersRenderInfos; //(Internal variable) Vertices for rendering characters
std::unordered_map<int, ssGUI::CharacterDetails> ProcessedCharacterDetails; //(Internal variable) Valid characters for rendering

bool Overflow; //See <IsOverflow>
float FontSize; //See <GetNewTextFontSize>
glm::u8vec4 TextColor; //See <GetNewTextColor>
bool TextUnderline; //See <IsNewTextUnderlined>
bool MultilineAllowed; //See <IsMultilineAllowed>
ssGUI::Enums::TextWrapping WrappingMode; //See <GetWrappingMode>
ssGUI::Enums::AlignmentHorizontal CurrentHorizontalAlignment; //See <GetTextHorizontalAlignment>
ssGUI::Enums::AlignmentVertical CurrentVerticalAlignment; //See <GetTextVerticalAlignment>
std::vector<ssGUI::Font*> CurrentFonts; //See <GetFont>

float HorizontalPadding; //See <GetTextHorizontalPadding>
float VerticalPadding; //See <GetTextVerticalPadding>
float CharacterSpace; //See <GetCharacterSpace>
float LineSpace; //See <GetLineSpace>
float TabSize; //See <GetTabSize>
bool SelectionAllowed; //See <IsTextSelectionAllowed>
int StartSelectionIndex; //See <GetStartSelectionIndex>
int EndSelectionIndex; //See <GetEndSelectionIndex>

glm::u8vec4 SelectionColor; //See <GetSelectionColor>
glm::u8vec4 TextSelectedColor; //See <GetTextSelectedColor>

uint32_t LastDefaultFontsID; //(Internal variable) Used to keep track if there's any changes to the default fonts

static int TextObjectCount; //(Internal variable) Used for deallocating default resources
static std::vector<ssGUI::Font*> DefaultFonts; //See <GetDefaultFont>
static uint32_t DefaultFontsChangeID; //(Internal variable) Used to track default font changes
bool RecalculateTextNeeded; //(Internal variable) Flag to recalculate all the cahracters locations
//TODO: Maybe just use redraw flag?
mutable ssGUI::SegmentedVector<ssGUI::CharacterDetails> CurrentCharactersDetails; //See <GetCharacterDetails>

std::vector<ssGUI::CharacterRenderInfo> CharactersRenderInfos; //(Internal variable) Vertices for rendering characters
std::unordered_map<int, ssGUI::CharacterDetails> ProcessedCharacterDetails; //(Internal variable) Valid characters for rendering

bool Overflow; //See <IsOverflow>
float FontSize; //See <GetNewTextFontSize>
glm::u8vec4 TextColor; //See <GetNewTextColor>
bool TextUnderline; //See <IsNewTextUnderlined>
bool MultilineAllowed; //See <IsMultilineAllowed>
ssGUI::Enums::TextWrapping WrappingMode; //See <GetWrappingMode>
ssGUI::Enums::AlignmentHorizontal CurrentHorizontalAlignment; //See <GetTextHorizontalAlignment>
ssGUI::Enums::AlignmentVertical CurrentVerticalAlignment; //See <GetTextVerticalAlignment>
std::vector<ssGUI::Font*> CurrentFonts; //See <GetFont>

float HorizontalPadding; //See <GetTextHorizontalPadding>
float VerticalPadding; //See <GetTextVerticalPadding>
float CharacterSpace; //See <GetCharacterSpace>
float LineSpace; //See <GetLineSpace>
float TabSize; //See <GetTabSize>
bool SelectionAllowed; //See <IsTextSelectionAllowed>
int StartSelectionIndex; //See <GetStartSelectionIndex>
int EndSelectionIndex; //See <GetEndSelectionIndex>

glm::u8vec4 SelectionColor; //See <GetSelectionColor>
glm::u8vec4 TextSelectedColor; //See <GetTextSelectedColor>

uint32_t LastDefaultFontsID; //(Internal variable) Used to keep track if there's any changes to the default fonts

static int TextObjectCount; //(Internal variable) Used for deallocating default resources
static std::vector<ssGUI::Font*> DefaultFonts; //See <GetDefaultFont>
static uint32_t DefaultFontsChangeID; //(Internal variable) Used to track default font changes


Text(Text const& other);
Expand Down Expand Up @@ -239,10 +239,28 @@ namespace ssGUI
//function: RemoveText
//Remove text in range
virtual void RemoveText(int startIndex, int exclusiveEndIndex);

//function: GetText
//Gets the text being shown
virtual void GetText(std::wstring& retText) const;

//function: GetText
//Gets the text being shown
virtual void GetText(std::string& retText) const;

//function: GetText
//Gets the text being shown
virtual std::wstring GetText();
template<typename T>
T GetText() const
{
T retString;
GetText(retString);
return retString;
}

//function: GetText (deprecated)
//Gets the text being shown. This is deprecated, use the template version instead.
virtual std::wstring GetText() const;

//function: GetCharacterCount
//Gets the number of characters for the text being shown
Expand Down
2 changes: 1 addition & 1 deletion Src/Tests/AutoTests/GUIObjectTests/TextTest_Auto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ int main()
std::string newString = " new text";
TestText->AddText(newString);

ssTEST_OUTPUT_ASSERT(TestText->GetText() == converter.from_bytes(TestString + newString));
ssTEST_OUTPUT_ASSERT(TestText->GetText<std::string>() == TestString + newString);

ssTEST_CALL_CLEAN_UP();
ssTEST_CALL_SET_UP();
Expand Down
18 changes: 16 additions & 2 deletions Src/ssGUI/GUIObjectClasses/Text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1437,8 +1437,22 @@ namespace ssGUI
RemoveCharacterDetails(startIndex, exclusiveEndIndex);
RedrawObject();
}

std::wstring Text::GetText()

void Text::GetText(std::wstring& retText) const
{
for(int i = 0; i < CurrentCharactersDetails.Size(); i++)
retText += CurrentCharactersDetails[i].Character;
}

void Text::GetText(std::string& retText) const
{
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;

for(int i = 0; i < CurrentCharactersDetails.Size(); i++)
retText += converter.to_bytes(CurrentCharactersDetails[i].Character);
}

std::wstring Text::GetText() const
{
std::wstring currentText = L"";
for(int i = 0; i < CurrentCharactersDetails.Size(); i++)
Expand Down

0 comments on commit 0377fb3

Please sign in to comment.