I'd need tips about a "wxNonStaticText", or a "wxReducedTextCtrl" component

Are you writing your own components and need help with how to set them up or have questions about the components you are deriving from ? Ask them here.
Post Reply
User avatar
Parduz
I live to help wx-kind
I live to help wx-kind
Posts: 150
Joined: Fri Jan 30, 2015 1:48 pm
Location: Bologna, Italy

I'd need tips about a "wxNonStaticText", or a "wxReducedTextCtrl" component

Post by Parduz »

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
New Pagodi
Super wx Problem Solver
Super wx Problem Solver
Posts: 428
Joined: Tue Jun 20, 2006 6:47 pm
Contact:

Re: I'd need tips about a "wxNonStaticText", or a "wxReducedTextCtrl" component

Post by New Pagodi »

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.
User avatar
Parduz
I live to help wx-kind
I live to help wx-kind
Posts: 150
Joined: Fri Jan 30, 2015 1:48 pm
Location: Bologna, Italy

Re: I'd need tips about a "wxNonStaticText", or a "wxReducedTextCtrl" component

Post by Parduz »

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.
uh... seems a very ... complex control.

As i'm a non-native english speaker, i fear i've not been clear.

So, here a couple of images:
Screenshot_05.png
Screenshot_05.png (2.71 KiB) Viewed 571 times
this is the "normal" state. Just showing the value.

Screenshot_06.png
Screenshot_06.png (2.73 KiB) Viewed 571 times
When you touch it, it becomes like that. As you see there's the curson, which i don't want ....
Screenshot_08.png
Screenshot_08.png (2.73 KiB) Viewed 571 times
.... '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?
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.
No problem, the keyboard on that device has only numbers and the dot.
New Pagodi
Super wx Problem Solver
Super wx Problem Solver
Posts: 428
Joined: Tue Jun 20, 2006 6:47 pm
Contact:

Re: I'd need tips about a "wxNonStaticText", or a "wxReducedTextCtrl" component

Post by New Pagodi »

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.

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",
"               [email protected]                           #+$            ",
"               %++++++&                           *+=            ",
"               -+;                                >+>            ",
"               $+,     '+)!~{  #]^/]( (-_~:<  [}|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 [email protected]]+<  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 "};

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 6420
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: I'd need tips about a "wxNonStaticText", or a "wxReducedTextCtrl" component

Post by ONEEYEMAN »

Hi,
What about wxGetNujmberFromUser()?

Thank you.
Post Reply