Comments (5)
Thanks for your detailed description, which helped me to find some problems with the FLabel
widget.
1st problem: The widget default size is 1×1 character. This caused an unsigned integer underflow!
2nd problem: I stupidly implemented the code of setMaximumSize()
in setMaximumHeight()
.
I have a version committed (b7639f5) that fixes these problems.
The main problem in your program is that you don't give the FLabel
a size. Therefore the set size hints for minimum and maximum are ignored. The widget still has its default size of 1x1 characters. The size hints are only considered in the methods setWidth()
, setHeight()
, setSize()
, and setGeometry()
.
Here is the code of the method setSize()
for explanation:
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();
}
from finalcut.
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 setSize
call. From the code snippet you pasted, it looks like Min/Max size hints are just to enforce a range for calls to setSize
. This seems useful for resizeable windows/dialogs - using hints to prevent the user from resizing it too small or too large, right?
Looks like setSize
is really just what I need to use with a sane value for my particular layout - and not so much using the size hints for labels. Would you agree with that ?
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).
setMinimumSize({25, 4})
labelDim.setMinimumSize({25,4})
setMinimumSize({15, 4})
labelDim.setMinimumSize({25, 4})
from finalcut.
You have already correctly recognized that with setMinimumSize()
and setMaximumSize()
only a validity range can be defined.
What you are looking for is a dynamically adaptive layout. For this, you can overload the method adjustSize()
. See https://github.com/gansm/finalcut/blob/master/doc/first-steps.md#dynamic-layout
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
Height = TopPadding + ClientHeight + BottomPadding
◄────────── getWidth() ──────────►
┌────────────────────────────────┐
│ │
│ │
│◄────── getClientWidth() ──────►│
│ │
│ │
└────────────────────────────────┘
▲ ▲
│ │
│ └── getRightPadding()
└─────────────────────────────────── getLeftPadding()
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).
from finalcut.
Great, thanks again. I'll let you close this - I might ask some other questions in the user feedback issue =)
from finalcut.
In the meantime I have written a small chapter about the widget layout:
https://github.com/gansm/finalcut/wiki/First-steps#widget-layout
from finalcut.
Related Issues (20)
- Align Right for FLineedit HOT 2
- How to acces FLineEdit text after event FFocusEvent HOT 2
- Problem with FLabel drawing double HOT 2
- Dynamic Layout issue HOT 1
- FListView crashing HOT 7
- Catching the terminal focus and unfocus signal in finalcut HOT 2
- ColorPalette not resetting after close HOT 2
- pretty last moment to get a newer version into debian HOT 1
- Does it support MSYS2 MinGW64? HOT 2
- Failed to build on MSYS2 MinGW64 HOT 2
- Compile error with clang++ -std=c++20 HOT 2
- FListview hide columns HOT 2
- Make it work on touchscreens HOT 4
- Build failed on ubuntu 22.04.2 LTS HOT 1
- can i recomend you guys an acscii 3d game HOT 2
- show windows on frame buffer HOT 4
- Enabling text selection HOT 3
- does it need ncurses?? HOT 1
- [FIX] Unable to build latest "main" without this HOT 1
- building problem with gcc-14 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from finalcut.