-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FLabel Text Wrapping, Not Obeying Max Size Hint #43
Comments
Thanks for your detailed description, which helped me to find some problems with the 1st problem: The widget default size is 1×1 character. This caused an unsigned integer underflow! I have a version committed (b7639f5) that fixes these problems. The main problem in your program is that you don't give the Here is the code of the method void FWidget::setSize (const FSize& size, bool adjust)
{
std::size_t width = size.getWidth();
std::size_t height = size.getHeight();
width = std::min (width, size_hints.max_width);
width = std::max (width, size_hints.min_width);
height = std::min (height, size_hints.max_height);
height = std::max (height, size_hints.min_height);
[...]
} Please try my variant with my last commit. #include <iostream>
#include <final/final.h>
namespace fc = finalcut;
class HelloDialog : public fc::FDialog
{
fc::FLabel labelDim{this};
public:
HelloDialog (fc::FWidget& parent)
: FDialog(&parent)
{
setText("Hello Finalcut - Size Issue");
setPos({10, 3});
setSize({40, 18});
labelDim.setFixedSize({getClientWidth(), 1}); // Sets the size hints
labelDim.setSize({9, 99}); // Sets the label size by using size hints
addTimer(100);
}
void onTimer (fc::FTimerEvent*) override
{
labelDim << "x";
redraw(); // Prints ellipsis ("..") on text overflow
}
};
int main (int argc, char* argv[])
{
fc::FApplication app{argc, argv};
HelloDialog dialog{app};
dialog.show();
app.setMainWidget(&dialog);
return app.exec();
} |
Glad the report could be of help :) Your patch does indeed fix the overflow, but without setting a size it does default to size 1x1 as you mentioned. I think I misunderstood the purpose of min/max size hints. I had figured there would be a size calculation based on text length up to the maximum size hint, thus no Looks like Also not sure if this is a bug or just something users need to be aware of, but if label minSize >= parent dialogs minSize, then there are overflow artifacts drawn. I attached a couple screenshots of what I mean. Seems like child should set minSize to parent's minSize minus the borders, e.g. (2?) for width, and 3 for height (extra +1 for the top title bar).
|
You have already correctly recognized that with What you are looking for is a dynamically adaptive layout. For this, you can overload the method Also, you have correctly recognized that a child widget of a dialog with a frame must always be smaller than its parent widget. Therefore, a widget can have a top, right, bottom, and left padding space, which results in a client width or client height. Width = LeftPadding + ClientWidth + RightPadding
A small example of how you can use adjustSize(): #include <iostream>
#include <final/final.h>
namespace fc = finalcut;
class HelloDialog : public fc::FDialog
{
fc::FLabel labelDim{this};
public:
HelloDialog (fc::FWidget& parent)
: FDialog(&parent)
{
setText("Hello Finalcut - Size Issue");
setPos({10, 3});
setSize({25, 7});
setResizeable();
// Changing the window size by clicking with the mouse
// on the lower right corner of the window.
setMinimumSize({25, 7});
fc::FSize client_size(getClientWidth(), getClientHeight());
labelDim.setText(fc::FString(40, L'\u263a'));
labelDim.setMinimumSize(client_size);
labelDim.setSize({999, 1});
}
void adjustSize() override
{
FDialog::adjustSize();
labelDim.setMinimumWidth(getClientWidth());
labelDim.setWidth(getClientWidth());
}
};
int main (int argc, char* argv[])
{
fc::FApplication app{argc, argv};
HelloDialog dialog{app};
dialog.show();
app.setMainWidget(&dialog);
return app.exec();
} By the way, I found a small error in the widget code (23ddf5d). |
Great, thanks again. I'll let you close this - I might ask some other questions in the user feedback issue =) |
In the meantime I have written a small chapter about the widget layout: |
Hello, was experimenting with finalcut (already a huge fan, absolutely brilliant work) and found
setMaximumWidth
,setMaximumSize
, etc. don't see to be obeyed when updating a label's text dynamically. Here's a minimal reproduction case for my scenario below.The output looks something like the screenshot attached, with dots wrapping line after line.
If you uncomment the commented two lines, I noticed it would enforce the minimum size as the maximum, and only 5 dots were displayed. Also to note, if I use
FLabel::setGeometry
orsetSize
, the maximum size is enforced, and no wrapping occurs.Perhaps I am not using
FLabel
the way it was intended, but as a newcomer it seems like this is probably not intended and maximum hints should be enforced. Or maybe I made a simple mistake?Thanks!
The text was updated successfully, but these errors were encountered: