Custom Text Control

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
Everydaydiesel
Earned some good credits
Earned some good credits
Posts: 111
Joined: Wed Oct 28, 2015 9:48 pm

Custom Text Control

Post by Everydaydiesel » Thu Oct 19, 2017 6:42 pm

Hello,

Can someone please help me make a control similar to this.
Image

I am pretty comfortable with c++ but I have no idea how to make my own control in wxWidgets.

1. the "A1" column should scroll with the text and anniotated version.
2. should have scroll bars so it can show multiple pages of text.

A basic template would be greatly appreciated.

Thanks in advance

User avatar
doublemax
Moderator
Moderator
Posts: 14196
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Custom Text Control

Post by doublemax » Thu Oct 19, 2017 7:49 pm

Can you user directly type into this or is it just for display?

In the latter case check out wxSimpleHtmlListBox. But it might be a little tricky to implement more than one column.

The next best choice would be wxVListBox.

If this should also be editable, you have a huge mountain to climb and i would suggest to avoid this ;)
Use the source, Luke!

Everydaydiesel
Earned some good credits
Earned some good credits
Posts: 111
Joined: Wed Oct 28, 2015 9:48 pm

Re: Custom Text Control

Post by Everydaydiesel » Thu Oct 19, 2017 8:05 pm

it is read only, no input from the user.

i will try a simple html list box but this is my first custom control. Any advice or example would be great, and thanks for helping me.

User avatar
doublemax
Moderator
Moderator
Posts: 14196
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Custom Text Control

Post by doublemax » Thu Oct 19, 2017 8:16 pm

I would use wxVListBox for this. It will handle all the scrolling, mouse handling etc for you.

All you need to do is to derive from wxVListBox and implement two virtual methods:
OnMeasureItem() which just returns the height for each item. In the simplest case you just return a constant value here.
OnDrawItem() which draws each item. Here you would enter the code that draws the text.

After that you only need to call SetItemCount() to set the number of items and you already have a working control. It's a "virtual" control, which means that it doesn't store information about the items. That's up to you.
Use the source, Luke!

User avatar
doublemax
Moderator
Moderator
Posts: 14196
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Custom Text Control

Post by doublemax » Thu Oct 19, 2017 8:35 pm

Small sample use wxHtmlListBox:

Code: Select all

class MyHtmlListBox : public wxHtmlListBox
{
public:
  MyHtmlListBox(wxWindow *parent) : wxHtmlListBox( parent, wxID_ANY )
  {
  };

  ~MyHtmlListBox() {};

protected:
  virtual wxString OnGetItem( size_t n ) const
  {
    return wxString::Format( wxT("<table border=0><tr><td width=30 align=center valign=middle>%d</td><td width=100%%>Some Text. <font color=red>some more text</font></td></tr></table>"), n );
  };

};
After creating an instance, call SetItemCount(100);

When using this, beware that this uses wxHtml internally, so no support for CSS, HTML5 etc.
Just the basics: http://docs.wxwidgets.org/trunk/overvie ... l_supptags
Use the source, Luke!

Post Reply