#2369 Custom FWT Widgets

SlimerDude Sun 26 Oct 2014

I was hoping to make my own custom FWT widgets, specifically a CTab and CTabPane so I could have fancy tabs with close buttons.

But I've stumbled at the first hurdle:

class CTab : Widget {
  new make() : super() { }
}

Internal method 'fwt::Widget.make' not accessible
BUILD FAILED [320ms]!

Could fwt::Widget.make be made public or protected so we can make our own Widgets?

EDIT: I've just noticed Pane, is that the preferred extension point?

andy Mon 27 Oct 2014

Yep - you should extend Pane (Widgets are reserved for the core native bound widgets).

SlimerDude Thu 20 Nov 2014

I've created native CTab and CTabPane FWT components that have fancy SWT tabs with close buttons:

SWT Fancy Tabs

Only to make it work I've had to alter fwt's WidgetPeer.java from:

public final void attach(fan.fwt.Widget self, Widget parentControl) {
  ...

  // create control and initialize
  // TODO: need to rework this
  if (parentControl instanceof TabItem) {

    TabItem item = (TabItem)parentControl;
    attachTo(create(item.getParent()));
    item.setControl((Control)this.control);

  } else {
    ...
  }

  ...
}

to

public final void attach(fan.fwt.Widget self, Widget parentControl) {
  ...

  // create control and initialize
  // TODO: need to rework this
  if (parentControl instanceof CTabItem) {

    CTabItem item = (CTabItem)parentControl;
    attachTo(create(item.getParent()));
    item.setControl((Control)this.control);

  } else if (parentControl instanceof TabItem) {

    TabItem item = (TabItem)parentControl;
    attachTo(create(item.getParent()));
    item.setControl((Control)this.control);

  } else {
    ...
  }

  ...
}

Is there a way WidgetPeer.java could be altered (for the next Fantom release) to create a hook for this change?

Or given CTabItem is a native SWT widget, maybe the above change could just be incorporated into WidgetPeer.java?

Note that the getParent() methods exist directly on TabItem and CTabItem so reflection would be the only way to query for their existence.

brian Thu 20 Nov 2014

As long as that change only depends on SWT classes and not your Fantom classes (which I think it does) then I don't think it hurts to make that change. Email me the patch and I'll work with you to incorporate it

Login or Signup to reply.