32 FXIMPLEMENT(
MFXDynamicLabel, FXLabel, MFXLabelMap, ARRAYNUMBER(MFXLabelMap))
42 MFXDynamicLabel::
MFXDynamicLabel(FXComposite* p, const FXString& text, FXIcon* ic, FXuint opts, FXint x, FXint y, FXint w, FXint h, FXint pl, FXint pr, FXint pt, FXint pb,
std::
string indent):
43 FXLabel(p, text, ic, opts, x, y, w, h, pl, pr, pt, pb), myOriginalString(text.text()), myIndentString(indent), myPreviousWidth(0) {
50 const int curWidth = getWidth();
55 return FXLabel::onUpdate(sender, sel, ptr);
61 FXLabel::setText(text);
69 FXLabel::position(x, y, w, h);
76 int pWidth = getParent()->getWidth();
78 FXFrame* frame =
dynamic_cast<FXFrame*
>(getParent());
80 if (frame !=
nullptr) {
81 padding = frame->getPadLeft() + frame->getPadRight();
85 return FXLabel::getDefaultHeight();
101 const int preferredWidth = curWidth - getPadLeft() - getPadRight();
102 const int textWidth = getApp()->getNormalFont()->getTextWidth(label);
103 if (textWidth <= preferredWidth || preferredWidth < 1) {
106 std::string newLine =
"\n" + std::string(
myIndent,
' ');
107 const int newLineOffset = (int)newLine.size();
110 int finalPos = (int)msg.size() - 1;
111 std::string::size_type nextLineBreak;
112 while (pos < finalPos) {
113 nextLineBreak = msg.find(
'\n', pos);
114 int subPos = (nextLineBreak != std::string::npos) ? (
int)nextLineBreak : finalPos;
115 if (getApp()->getNormalFont()->getTextWidth(msg.substr(pos, subPos - pos).c_str()) <= preferredWidth) {
123 const int endPos = (nextLineBreak != std::string::npos) ? (
int)nextLineBreak - 1 : finalPos;
124 std::string::size_type nextSpace = std::string::npos;
125 int lastSpacePos = -1;
127 while (pos2 < endPos) {
128 nextSpace = msg.find(
' ', pos2);
129 if (nextSpace != std::string::npos && (
int)nextSpace <= pos +
myIndent) {
130 nextSpace = std::string::npos;
132 }
else if (nextSpace != std::string::npos && (
int)nextSpace < endPos) {
133 std::string testString = msg.substr(pos, nextSpace - pos);
134 if (getApp()->getNormalFont()->getTextWidth(msg.substr(pos, nextSpace - pos).c_str()) > preferredWidth) {
135 if (lastSpacePos > 0) {
136 msg.replace(lastSpacePos, 1, newLine);
137 pos2 = lastSpacePos + newLineOffset;
138 finalPos += newLineOffset;
140 msg.replace(nextSpace, 1, newLine);
141 pos2 = (int)nextSpace + newLineOffset;
142 finalPos += newLineOffset;
146 pos2 = (int)nextSpace + 1;
147 if (msg.find(
' ', pos2) == std::string::npos && lastSpacePos > 0) {
148 msg.replace(lastSpacePos, 1, newLine);
149 pos2 += newLineOffset;
153 lastSpacePos = (int)nextSpace;
FXDEFMAP(MFXDynamicLabel) MFXLabelMap[]
A list item which allows for custom coloring.
void reformatLineBreaks(const int curWidth)
MFXDynamicLabel()
fox needs this
void setText(const FXString &text)
overload text label updates to store the original string as backup for when width changes again
void position(FXint x, FXint y, FXint w, FXint h)
overload position to be informed when the parent has done the layout
void computeIndentation()
long onUpdate(FXObject *sender, FXSelector, void *)
overload to be informed when the label text has to be reformatted due to width changes
std::string myOriginalString
std::string myIndentString