wxTextCtrl show full text
When we put wxTextCtrl to vertical sizers it not show maximum text. How setup SetInitialSize() to show full text, not only 1-2 lines? Meybe it need create a new options wxMaxSizeVertical in current font and up sizers.
similar python GetFullTextExtent() SetInitialSize(GetFullTextExtent(GetValue()));
@og1en , This sounds like a problem in your code.
Can you post how you add the control to the sizer and how did you create the control.
Also, did you try to submit this in the wxWidgets forum?
Do You know how read/set dimension wraped text?
wxSize d = self->GetDimension() like GetSize() of widget.
@og1en , Why? What problem you are trying to solve?
Thank you.
I am trying to set the SetInitialSize() value correctly. Now I am limited by the size of the main window. I want to know how much the wrapped text takes up in the width 'self'.
I want to set the minimum size to be larger than the main window.
Hi,
On Sat, Feb 24, 2024 at 6:42 AM ogień @.***> wrote:
I am trying to set the SetInitialSize() value correctly. Now I am limited by the size of the main window.
Why? Let the sizers algorithm do that for you.
This will not be accurate anyway - if the user moves the window across DPI, or if the program will run on a different platform.
Also - I'm not sure, but I think on GTK/Linux you control needs to be realised with the text, so that its size can be determined/set. I may be wrong here though.
Thank you.
I want to know how much the wrapped text takes up in the width 'self'.
— Reply to this email directly, view it on GitHub https://github.com/wxWidgets/wxWidgets/issues/24349#issuecomment-1962350732, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABGPQWEAYPT2OMRATPL2FBDYVHN23AVCNFSM6AAAAABDXOTVSOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNRSGM2TANZTGI . You are receiving this because you commented.Message ID: @.***>
Why you ask. Why do you keep asking the same question and not answering? Why don't you just want to write how to do it?
I don't know why I should waste my time explaining instead of coding.
If you give the control big enough initial size (either via size ctor parameter or by calling SetInitialSize() later), it will show more lines of text, so it's not really clear what are you asking as you already seem to know this.
Why don't you just want to write how to do it?
You haven't really explained what "it" is and, contrary to what you might be thinking, it's really not obvious. Please describe clearly what do you do, what you expect to happen and what actually happens.
I don't know why I should waste my time explaining instead of coding.
I'd also like to note that if everybody shared your attitude, nobody would waste time answering your questions at all.
If you give the control big enough initial size (either via
sizector parameter or by callingSetInitialSize()later), it will show more lines of text, so it's not really clear what are you asking as you already seem to know this.
I know how to give more size. But how to give the right size. How to set a size that would fit perfectly to display the text as long as it is. This is the crux of the question. How to figure out what size to put in there. That's what I'm asking.
GetTextExtent is no answer because it output a unwraped text.
If there is a function that counts the width and amount of text to be displayed, I'm looking for a function that would do that for all text at the current font and control size. At the same time, it would not stop in the calculation if the window size is smaller. And that it would stop in the calculation when it runs out of text if the text is less than the window size.
As for the clarity of my statement. Well, everyone thinks they are speaking clearly and accurately. I'm trying my best.
There is no function to get the size needed to display wrapped text currently.
But in practice, displaying enough lines for unwrapped text, i.e. using the size of N*GetCharHeight() is usually good enough, unless you have very long lines (or very narrow window).
There is no function to get the size needed to display wrapped text currently.
;( where is function, counting this? Can You help me located function and meybe correct it. Creating class with my own function for this?
But in practice, displaying enough lines for unwrapped text, i.e. using the size of
N*GetCharHeight()is usually good enough, unless you have very long lines (or very narrow window).
If the text is clear it probably will be ok. I'm try this. But if I use styles, bold etc is not correct. Thanks for reply
To count the number of lines you can use either wxTextCtrl::GetNumberOfLines() or simply count the number of \ns in the value.
To count the number of lines you can use either
wxTextCtrl::GetNumberOfLines()or simply count the number of\ns in the value.
I'm trying GetNumberOfLines ( ) bbut this show orginal lines string not wraped text in textCtrl. This is not good idea. I get output = 1. But line is long and when window is 200 i get 12 lines. You've given me hope, but it doesn't apply to the displayed text. The problem is still unsolved. How to write textctrl and initialization?
Does SetInitialSize() limit to window size even if the virtual window is larger? Is there any any indicator to show that there is still some text at the bottom. That what the control displays isn't all there is yet? for example '.....' ? ( BTW whete put wxDECLARE_DYNAMIC_CLASS(Tekst); ? and EVT_SIZE (Tekst::GetBestSize) )
tekst.h
#ifndef TEKST_H
#define TEKST_H
#include <wx/wx.h>
class Tekst : public wxTextCtrl
{
int t;
public:
Tekst(wxWindow* parent, wxString treść);
virtual wxSize GetBestSize() const;
private:
// wxDECLARE_DYNAMIC_CLASS(Tekst);
wxDECLARE_EVENT_TABLE();
};
#endif
and body tekst.cpp
#include <wx/wx.h>
#include "tekst.h"
Tekst::Tekst(wxWindow* parent, wxString treść) :
wxTextCtrl(parent, wxID_ANY, treść, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE|wxTE_READONLY|wxTE_BESTWRAP|wxTE_NO_VSCROLL)
{
wxSize m;
SetInitialSize(GetBestSize());
t = 1;
}
wxSize Tekst::GetBestSize()
{
wxSize w = GetSize();
// How change w.y size
return w;
}
BEGIN_EVENT_TABLE(Tekst, wxTextCtrl)
EVT_SIZE (Tekst::GetBestSize)
END_EVENT_TABLE()
I'm trying GetNumberOfLines ( ) bbut this show orginal lines string not wraped text in textCtrl. This is not good idea. I get output = 1. But line is long and when window is 200 i get 12 lines.
As I said, there is currently no function to perform text layout, including wrapping, and compute its size. You can probably approximate it yourself by dividing the number of characters by the average character width or using GetTextExtent().x and dividing it by the window width. This will certainly be inexact, but should be close enough to be usable in practice.