MCPcopy Create free account
hub / github.com/TurningWheel/Barony / reflowTextToFit

Method reflowTextToFit

src/ui/Field.cpp:791–893  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

789}
790
791void Field::reflowTextToFit(const int characterOffset, bool check) {
792 if ( text == nullptr || textlen <= 1 ) {
793 return;
794 }
795
796 if (check) {
797 if (auto getText = Text::get(text, font.c_str(), textColor, outlineColor)) {
798 if (getText->getWidth() <= (getSize().w)) {
799 // no work to do
800 return;
801 }
802 }
803 }
804 std::string reflowText = "";
805
806#ifndef EDITOR
807 bool usePreciseStringWidth = bUsePreciseFieldTextReflow;
808#else
809 bool usePreciseStringWidth = true;
810#endif
811 if ( usePreciseStringWidth )
812 {
813 // more expensive, but accurate text reflow.
814 std::vector<std::string> allLines;
815 char* nexttoken;
816 char* token = text;
817 do {
818 nexttoken = tokenize(token, "\n");
819 std::string tokenStr(token);
820 std::vector<std::string> result;
821 reflowTextLine(tokenStr, (getSize().w), font.c_str(), result);
822 for ( size_t i = 0; i < result.size(); ++i )
823 {
824 allLines.push_back(result[i]);
825 }
826 } while ( (token = nexttoken) != NULL );
827
828 for ( auto it = allLines.begin(); it != allLines.end(); ++it )
829 {
830 reflowText += (*it);
831 auto nextStr = std::next(it);
832 if ( nextStr != allLines.end() )
833 {
834 reflowText += '\n';
835 }
836 }
837 setText(reflowText.c_str());
838 return;
839 }
840
841 Font* actualFont = Font::get(font.c_str());
842 if ( !actualFont )
843 {
844 return;
845 }
846
847 int charWidth = 0;
848 actualFont->sizeText("_", &charWidth, nullptr);

Callers 8

createBookMethod · 0.80
updateShopMethod · 0.80
updateTinkerMenuMethod · 0.80
updateAlchemyMenuMethod · 0.80
updateFeatherMenuMethod · 0.80
updateItemEffectMenuMethod · 0.80
updateMailMenuMethod · 0.80
updateFrameTooltipMethod · 0.80

Calls 8

tokenizeFunction · 0.85
reflowTextLineFunction · 0.85
c_strMethod · 0.80
sizeTextMethod · 0.80
getWidthMethod · 0.45
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected