If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
- Earned some good credits
- Posts: 129
- Joined: Fri Aug 17, 2012 2:22 am
Visual Studio 2017
I want to draw text that fills a rectangle also centred. The font size
should be selected based on the text size ( single or mulitple lines )
relative to the size of the rectangle.
Code: Select all
std::wstring text = L"Hello, world!";
font.Scale(50); // Would want to determine the scale factor based in the size of text relative to wxRect
wxRect text_rect(screen.x, screen.y, screen.width, screen.height * 0.45f);
dc.DrawLabel(text, text_rect, wxALIGN_CENTRE);
- Posts: 15283
- Joined: Fri Apr 21, 2006 8:03 pm
- Location: $FCE2
There is nothing in wxWidgets that does this for you automatically. Pick a random font size, use wxDC::GetMultiLineTextExtent to calculate the size that you get, compare it with the size that you want, calculate a correction factor for the font size. Repeat until you're close enough to the target size.
Use the source, Luke!
- Filthy Rich wx Solver
- Posts: 223
- Joined: Fri Sep 14, 2012 8:26 am
- Location: Kontich, Belgium
I have attached the GraphTools module of my toolbox (7zip format). Maybe not the best code around but it might give you an insight and set you on the way to your solution. The methods are for displaying text in any fontsize, aligned left, right, centered, with an angle if needed. Also with a bounding rectangle, the line will be split into several lines.
Hope this may be usefull for you.
- (3.96 KiB) Downloaded 13 times