# Creating custom widget

**URL:** <https://www.ruby-forum.com/t/creating-custom-widget/212373>\
**Category:** wxRuby\
**Created:** [October 1, 2011, 11:49am UTC](https://www.ruby-forum.com/t/creating-custom-widget/212373 "2011-10-01T11:49:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [October 1, 2011, 11:49am UTC](https://www.ruby-forum.com/t/creating-custom-widget/212373/1 "2011-10-01T11:49:59Z")

</div>

Hi,

I’m trying to learn and experiment with Ruby a bit so I decided to make  
a simple diagram editor using wxruby.

The problem is, I will need to create a custom widget for the diagram  
components (e.g. rectangles, connections) and implement some custom  
events. I found these examples of how it’s done in generic wxWidgets:  
[http://wiki.wxwidgets.org/Painting\_your\_custom\_control](http://wiki.wxwidgets.org/Painting_your_custom_control)  
[http://docs.wxwidgets.org/2.9.2/overview\_customwidgets.html](http://docs.wxwidgets.org/2.9.2/overview_customwidgets.html)

Is something like this possible in wxRuby or is there any sample ruby  
code which I could look at?

Thank you for any suggestions.

Stano

---

<div class="post-metadata">

**Author:** ![stanozm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/54ee81/32.png) [@stanozm](https://www.ruby-forum.com/u/stanozm)\
**Post date:** [October 2, 2011, 3:16am UTC](https://www.ruby-forum.com/t/creating-custom-widget/212373/2 "2011-10-02T03:16:57Z")

</div>

hi

On 01/10/11 10:49, Stanislav Chren wrote:

> The problem is, I will need to create a custom widget for the diagram  
> components (e.g. rectangles, connections) and implement some custom  
> events. I found these examples of how it’s done in generic wxWidgets:  
> [Painting your custom control - WxWiki](http://wiki.wxwidgets.org/Painting_your_custom_control)  
> [http://docs.wxwidgets.org/2.9.2/overview\_customwidgets.html](http://docs.wxwidgets.org/2.9.2/overview_customwidgets.html)
> 
> Is something like this possible in wxRuby or is there any sample ruby  
> code which I could look at?

Have a look at samples/events/events.rb - it uses a custom class derived  
from Wx::Window that implements an on\_paint method and event handling.

cheers  
alex

---

<div class="post-metadata">

**Author:** ![stanozm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/54ee81/32.png) [@stanozm](https://www.ruby-forum.com/u/stanozm)\
**Post date:** [October 2, 2011, 3:34am UTC](https://www.ruby-forum.com/t/creating-custom-widget/212373/3 "2011-10-02T03:34:50Z")

</div>

Hello Stanislav, I’m sure that this is possible. Most of the methods in  
that  
code should have direct wxruby equivalents, you can derive from the  
native  
wxruby classes, but the event-handling syntax is quite different. Check  
out  
the wxRuby samples. Where they’re installed depends on what operating  
system  
you’re on and how you installed wxruby, but if you can’t find it then  
download the source and you can see them all in the “samples” folder. In  
particular, maybe check out samples/drawing/graphics\_drawing.rb
