I'd need tips about a "wxNonStaticText", or a "wxReducedTextCtrl" component
I'd need tips about a "wxNonStaticText", or a "wxReducedTextCtrl" component
I have a "kiosk" application running on a BeagleBone Black with a small touchscreen.
I need a way to enter numbers but it has to be "simple". Right now i have a complex management of wxTextCtrl in order to make it appears like a label until the user touch it, then showing the "editing". Problem is that i don't want any cursor and any text selection.
All i want is replacing the actual value with the new digits, and confirm the new value with ENTER, or abort the editing with ESC.
So i'd need a control that looks like a wxStaticText, but that once "activated" (get focus?) it shows a different background (Static text doesn't show the background color on Linux, at least with GTK2) and that handles keystrokes and fires the events like a wxTextCtrl (at least the TextUpdated and TextEnter).
Form where should i start? Is it better to derive my class from a wxPanel and handling everything, derive from a StaticText and implementing what it lacks, or from a TextCtrl and ... "removing" (or hiding) some features?
What should be the most simple, secure, straightforward way?
Thanks
I need a way to enter numbers but it has to be "simple". Right now i have a complex management of wxTextCtrl in order to make it appears like a label until the user touch it, then showing the "editing". Problem is that i don't want any cursor and any text selection.
All i want is replacing the actual value with the new digits, and confirm the new value with ENTER, or abort the editing with ESC.
So i'd need a control that looks like a wxStaticText, but that once "activated" (get focus?) it shows a different background (Static text doesn't show the background color on Linux, at least with GTK2) and that handles keystrokes and fires the events like a wxTextCtrl (at least the TextUpdated and TextEnter).
Form where should i start? Is it better to derive my class from a wxPanel and handling everything, derive from a StaticText and implementing what it lacks, or from a TextCtrl and ... "removing" (or hiding) some features?
What should be the most simple, secure, straightforward way?
Thanks
-
- Super wx Problem Solver
- Posts: 469
- Joined: Tue Jun 20, 2006 6:47 pm
- Contact:
Re: I'd need tips about a "wxNonStaticText", or a "wxReducedTextCtrl" component
With wxStyledTextCtrl you can change the caret and selection styles to whatever you want them to be. However, I don't know if you can set a validator on it it restrict input to only numbers. If not, you should be able to handle the key events and block any non-number chars from getting through to the window although I do realize that's much less convenient.
Re: I'd need tips about a "wxNonStaticText", or a "wxReducedTextCtrl" component
uh... seems a very ... complex control.New Pagodi wrote: ↑Mon Nov 21, 2022 3:21 pm With wxStyledTextCtrl you can change the caret and selection styles to whatever you want them to be.
As i'm a non-native english speaker, i fear i've not been clear.
So, here a couple of images:
this is the "normal" state. Just showing the value.
When you touch it, it becomes like that. As you see there's the curson, which i don't want ....
.... 'cause the user can (an so, want) to move it by touching the screen. I instead want that it just writes a new value which overwrite the existing one.
Also (no screenshots, sorry, as the textctrl grabs the key combo that saves them) when writing the "cell" becomes white, another minor problem that i'd avoid.
So, can the wxStyledTextCtrl do what i need?
No problem, the keyboard on that device has only numbers and the dot.New Pagodi wrote: ↑Mon Nov 21, 2022 3:21 pm However, I don't know if you can set a validator on it it restrict input to only numbers.
-
- Super wx Problem Solver
- Posts: 469
- Joined: Tue Jun 20, 2006 6:47 pm
- Contact:
Re: I'd need tips about a "wxNonStaticText", or a "wxReducedTextCtrl" component
wxStyledTextCtrl is very complicated, but that's because almost everything with wxStyledTextCtrl is customizable. Here's a quick sample I threw together. The colors are like in t he sample you showed, the carret is hidden, and when the user selects the text the contents are erased so that a new value can be entered. (There is a second text box in the sample just to have another control that can take focus).
I don't know it this is what you're looking for, but it's just the first thing I thought of to create a control like you are requesting.
One thing that isn't done is that wxStyledTextCtrl is a multiline text control, so if the user presses enter, the control will move to the next line. This behavior can be avoided by catching the enter key with key events and not forwarding those key presses to the control.
I don't know it this is what you're looking for, but it's just the first thing I thought of to create a control like you are requesting.
One thing that isn't done is that wxStyledTextCtrl is a multiline text control, so if the user presses enter, the control will move to the next line. This behavior can be avoided by catching the enter key with key events and not forwarding those key presses to the control.
Code: Select all
#include <wx/wx.h>
#include <wx/stc/stc.h>
char* h_xpm[];
class stcFrame: public wxFrame
{
public:
stcFrame(wxWindow*);
private:
void OnSTCFocusIn(wxFocusEvent&);
void OnSTCFocusOut(wxFocusEvent&);
wxStyledTextCtrl* m_stc;
};
stcFrame::stcFrame(wxWindow* par)
:wxFrame(par,wxID_ANY,"App Title")
{
wxPanel* bg = new wxPanel(this,wxID_ANY);
bg->SetBackgroundColour(wxColour(0,0,66));
wxStaticBitmap* logo = new wxStaticBitmap(bg, wxID_ANY, wxBitmap(h_xpm));
m_stc = new wxStyledTextCtrl(bg, wxID_ANY,wxDefaultPosition,wxSize(-1,20),wxBORDER_NONE);
m_stc->SetMarginWidth(1,0);
m_stc->StyleSetBackground(wxSTC_STYLE_DEFAULT,wxColour(0,0,66) );
m_stc->StyleSetBackground(0,wxColour(0,0,66) );
m_stc->StyleSetForeground(0,wxColour(255,255,132) );
m_stc->SetUseHorizontalScrollBar(false);
m_stc->SetUseVerticalScrollBar(false);
m_stc->SetCaretLineBackground( wxColour(0,65,132) );
m_stc->SetCaretStyle(wxSTC_CARETSTYLE_INVISIBLE);
m_stc->Bind(wxEVT_SET_FOCUS,&stcFrame::OnSTCFocusIn,this);
m_stc->Bind(wxEVT_KILL_FOCUS,&stcFrame::OnSTCFocusOut,this);
wxBoxSizer* mainSzr = new wxBoxSizer(wxVERTICAL);
wxBoxSizer* szr = new wxBoxSizer(wxHORIZONTAL);
szr->Add(logo,wxSizerFlags(0));
szr->Add(m_stc,wxSizerFlags(1).Border(wxTOP|wxBOTTOM|wxRIGHT));
mainSzr->Add(szr);
wxTextCtrl* tc = new wxTextCtrl(bg,wxID_ANY);
tc->SetFocus();
m_stc->AppendText("8500");
mainSzr->Add(tc, wxSizerFlags(0).Border(wxALL));
bg->SetSizer(mainSzr);
Layout();
}
void stcFrame::OnSTCFocusIn(wxFocusEvent& event)
{
m_stc->ClearAll();
m_stc->SetCaretLineVisible(true);
event.Skip();
}
void stcFrame::OnSTCFocusOut(wxFocusEvent& event)
{
m_stc->SetCaretLineVisible(false);
event.Skip();
}
class stcApp : public wxApp
{
public:
bool OnInit() override
{
stcFrame* frame = new stcFrame(0L);
frame->Show();
return true;
}
};
wxIMPLEMENT_APP(stcApp);
char* h_xpm[] = {
"65 29 71 1",
" c #000042",
". c #313452",
"+ c #FFFF84",
"@ c #737163",
"# c #080842",
"$ c #ADAA6B",
"% c #5A5D5A",
"& c #525152",
"* c #292C4A",
"= c #848263",
"- c #848663",
"; c #424152",
"> c #5A595A",
", c #080C42",
"' c #9C9E6B",
") c #52555A",
"! c #E7E37B",
"~ c #F7F384",
"{ c #6B6D5A",
"] c #9C9A6B",
"^ c #EFEF7B",
"/ c #EFEF84",
"( c #000442",
"_ c #E7E77B",
": c #BDBE73",
"< c #29284A",
"[ c #18184A",
"} c #BDBA73",
"| c #F7F784",
"1 c #CECB73",
"2 c #31304A",
"3 c #737563",
"4 c #A5A26B",
"5 c #424552",
"6 c #D6D37B",
"7 c #63655A",
"8 c #C6C773",
"9 c #FFFB84",
"0 c #7B7D63",
"a c #6B695A",
"b c #21244A",
"c c #EFEB7B",
"d c #CECF7B",
"e c #21204A",
"f c #393852",
"g c #C6C373",
"h c #DEDF7B",
"i c #101042",
"j c #94966B",
"k c #B5B273",
"l c #4A4D52",
"m c #7B7963",
"n c #181C4A",
"o c #101442",
"p c #D6D77B",
"q c #4A4952",
"r c #ADAE6B",
"s c #B5B673",
"t c #393C52",
"u c #94926B",
"v c #949263",
"w c #8C8A63",
"x c #525552",
"y c #8C8E63",
"z c #A5A66B",
"A c #31344A",
"B c #63615A",
"C c #10144A",
"D c #ADAE73",
"E c #CECF73",
"F c #73715A",
" .++++++@ #+$ ",
" %++++++& *+= ",
" -+; >+> ",
" $+, '+)!~{ #]^/]( (-_~:< [}|1]+2 [$|!3 4+5^",
" 6+++++7 8980|/ $~*%+a 4^*b/6 8c<&++#(d!e>+f g_h+",
" |+++++5 ^^i :| b+j ,=;*+- k+i2+- 9! l+m i+3 ^+)#",
" n+' o+4 pp {+) 3+q r+o3+q 9} 0+++++{o+s ",
" ;+3 t+3 (9$ ]+2 ]+< 1^ ]+< b+u ]+e t+3 ",
" a+& 7+l <+= v+2 %3#w+. ,9' '+< 3+a =+< xb 7+q ",
" y++++++&y+b &+> &+0n!p 5+v#j^n {+z{c+; A+=ec: y+e ",
" s++++++*s9 m+2 =_~se {!|}* ,s|k]+< a!|}[ s| ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" .++++c3 b+y e+j ",
" %++++++> l+7 r- ;+3 ",
" -+5 B+k 3+t [9% ",
" $+n ,+: [$|!3 t1|^j (-_~:< '+Cr9( m+.B+++a'+C(-_~:< '+)!~{ ",
" 6~ #0+v(d!e>+f ^D,7~t 4^*b/6 8^ pp 4+, $+( 8^ 4^*b/6 8980|/ ",
" |+++++cnl+m i+3(+D( *+- k+i ^g(9$ 1_ Eh ^8*+- k+i ^^i :| ",
"n+++++kn 0+++++{ }+cji 3+q r+oo+]b+= ~: ~} o+'3+q r+oo+4 pp ",
";+w b+s ]+e ,w_+s ]+< 1^ t+Fl+> e+j [+u t+@]+< 1^ t+3 (9$ ",
"a+B E+[ =+< xb # s| w+. ,9' 7+qF+t m+{ f+{ 7+qw+. ,9' 7+l <+= ",
"y+f 3+3 A+=ec: z!ni1E 5+v#j^n y+ea+}w/+5 q+0(y+e5+v#j^n y+b &+> ",
"s+i n+p a!|}[ n}~~:< {!|}* s| C1|ry+e op97s| {!|}* s9 m+2 "};
Re: I'd need tips about a "wxNonStaticText", or a "wxReducedTextCtrl" component
Hi,
What about wxGetNujmberFromUser()?
Thank you.
What about wxGetNujmberFromUser()?
Thank you.
Re: I'd need tips about a "wxNonStaticText", or a "wxReducedTextCtrl" component
Sorry for the long delay on answering here; i experimented a lot and i'm almost done with wxStyledTextCtrl.New Pagodi wrote: ↑Mon Nov 21, 2022 6:00 pm wxStyledTextCtrl is very complicated, but that's because almost everything with wxStyledTextCtrl is customizable.
Still there's something i'm not able to make like i want, so here's a bunch of questions:
- I can't vertically center-align it. It will look always "Left-Top" aligned, no matter what i do with the tags. I was able to have it center-aligned only by forcing the control height to be less than the font size . What am i doing wrong?
- I use the control DoubleClick event to remove any selection made by the user. But still, if you do a "triple-click" (so, a third click in a time after the doubleclick) it still select the whole content (or the whole line, i dunno, as there's never more than one line). I'm not able to "trap" or catch this behaviour. How could i deny any kind of text selection?
- I think that's impossible 'cause the very purposes of the wxStyledTextCtrl , but i'd ask anyway: there's a way to right-align the text?
Sorry for the late reply, i think i missed your question.
The problem is that my App cannot loose focus, never. This is actually my biggest fear. 'cause the hardware, the main form is resposible to get the hardware keyboard signal that a key was pressed, and get the keycode using i2c messages.
That signal is "converted" by the Overlay to a Key Event (of an "impossible" key code, like F20 ).
So i can't have anything with focus AND in foreground that is'nt my frame.
(if someone can tell me how to raise a system-wide event/message when an hardware input changes state, using DeviceTreeOverlays in Debian, please PM me )
-
- Super wx Problem Solver
- Posts: 469
- Joined: Tue Jun 20, 2006 6:47 pm
- Contact:
Re: I'd need tips about a "wxNonStaticText", or a "wxReducedTextCtrl" component
I think alignment might be one thing that isn't customizable in wxSTC. I think left aligned is the only option. Sorry about that.Parduz wrote: ↑Wed Dec 14, 2022 9:22 am Still there's something i'm not able to make like i want, so here's a bunch of questions:
- I can't vertically center-align it. It will look always "Left-Top" aligned, no matter what i do with the tags. I was able to have it center-aligned only by forcing the control height to be less than the font size . What am i doing wrong?
- I use the control DoubleClick event to remove any selection made by the user. But still, if you do a "triple-click" (so, a third click in a time after the doubleclick) it still select the whole content (or the whole line, i dunno, as there's never more than one line). I'm not able to "trap" or catch this behaviour. How could i deny any kind of text selection?
- I think that's impossible 'cause the very purposes of the wxStyledTextCtrl , but i'd ask anyway: there's a way to right-align the text?
Re: I'd need tips about a "wxNonStaticText", or a "wxReducedTextCtrl" component
Are you answering to 1) or 3) ?New Pagodi wrote: ↑Wed Dec 14, 2022 2:36 pmI think alignment might be one thing that isn't customizable in wxSTC. I think left aligned is the only option. Sorry about that.Parduz wrote: ↑Wed Dec 14, 2022 9:22 am Still there's something i'm not able to make like i want, so here's a bunch of questions:
- I can't vertically center-align it. It will look always "Left-Top" aligned, no matter what i do with the tags. I was able to have it center-aligned only by forcing the control height to be less than the font size . What am i doing wrong?
- I use the control DoubleClick event to remove any selection made by the user. But still, if you do a "triple-click" (so, a third click in a time after the doubleclick) it still select the whole content (or the whole line, i dunno, as there's never more than one line). I'm not able to "trap" or catch this behaviour. How could i deny any kind of text selection?
- I think that's impossible 'cause the very purposes of the wxStyledTextCtrl , but i'd ask anyway: there's a way to right-align the text?
I may have not been clear: 1) is about aligning the control inside its parent, 3 about the text inside the control.
Thanks
-
- Super wx Problem Solver
- Posts: 469
- Joined: Tue Jun 20, 2006 6:47 pm
- Contact:
Re: I'd need tips about a "wxNonStaticText", or a "wxReducedTextCtrl" component
I guess I was answering 3. wxSTC was originally for making an editor for programming code, and code is usually left aligned and I don't think that can be changed. If you need right aligned text, maybe this won't work for you after all.
For aligning the control in the parent, are you using sizers? Usually with sizers, we center things either by setting a flag or putting spacers on both sides of the object we want centered.
For aligning the control in the parent, are you using sizers? Usually with sizers, we center things either by setting a flag or putting spacers on both sides of the object we want centered.
Re: I'd need tips about a "wxNonStaticText", or a "wxReducedTextCtrl" component
I don't know ... seems to me that the StyledTextControl just always expands itself, no matter what you set.New Pagodi wrote: ↑Wed Dec 21, 2022 4:02 pm For aligning the control in the parent, are you using sizers? Usually with sizers, we center things either by setting a flag or putting spacers on both sides of the object we want centered.
I'm replacing the textcontrols with Styled in a grid sizer, and while they have the same settings, the result is that the Styled control takes all the available space.
-
- Super wx Problem Solver
- Posts: 469
- Joined: Tue Jun 20, 2006 6:47 pm
- Contact:
Re: I'd need tips about a "wxNonStaticText", or a "wxReducedTextCtrl" component
I think that's the devfault size for a styled text control. I got around it by speficially setting a height for the control "wxSize(-1,20)". You can compute a value instead of 20 based on the size of text plus a little more for padding. I know usually we want to avoid hard coded sizes, but I couldn't find any other way to avoid the large windows like your showing other than setting the size.
edit:
But since I don't think there will be a way to right align the text like your showing, it might be best to abandon trying to use a wxSTC. Unfortunately, I can't think of a control that lets you change the caret color and allows right aligning text.
edit:
But since I don't think there will be a way to right align the text like your showing, it might be best to abandon trying to use a wxSTC. Unfortunately, I can't think of a control that lets you change the caret color and allows right aligning text.
Re: I'd need tips about a "wxNonStaticText", or a "wxReducedTextCtrl" component
I wonder if this should be considered a bug.... it's the only wxControl that i know which doesn't obey to the flag you set on it or on its sizer (and, actually, it affects the alignement of my whole pages).
Re: I'd need tips about a "wxNonStaticText", or a "wxReducedTextCtrl" component
The text alignment has nothing to do with the alignment of a control inside a sizer structure.
Seeing how long you're already dealing with this, it probably would have been much easier to write a new control from scratch.
Use the source, Luke!
-
- Super wx Problem Solver
- Posts: 469
- Joined: Tue Jun 20, 2006 6:47 pm
- Contact:
Re: I'd need tips about a "wxNonStaticText", or a "wxReducedTextCtrl" component
I was trying not to send him down that path, but that's probably the only way to get a control with all of the desired features. I think the caret sample shows some of the techniques needed for making such a custom control.
Re: I'd need tips about a "wxNonStaticText", or a "wxReducedTextCtrl" component
Parduz wrote that he doesn't want a cursor or selection. That should make this much easier.New Pagodi wrote: ↑Thu Dec 22, 2022 5:14 pmI was trying not to send him down that path, but that's probably the only way to get a control with all of the desired features. I think the caret sample shows some of the techniques needed for making such a custom control.
Use the source, Luke!