Page 1 of 1

Custom Text Control

Posted: Thu Oct 19, 2017 6:42 pm
by Everydaydiesel
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

Re: Custom Text Control

Posted: Thu Oct 19, 2017 7:49 pm
by doublemax
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 ;)

Re: Custom Text Control

Posted: Thu Oct 19, 2017 8:05 pm
by Everydaydiesel
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.

Re: Custom Text Control

Posted: Thu Oct 19, 2017 8:16 pm
by doublemax
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.

Re: Custom Text Control

Posted: Thu Oct 19, 2017 8:35 pm
by doublemax
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