Jump to content

[SOLVED] User Widget


photo

Recommended Posts

I creating my own widget and want to inherit it from base widget class like this :
 

class ProgressBarWidget : Widget
{
     ProgressBarWidget(Gui gui, string name): Widget(gui, name) { ....something....}
};

calling in other script

....
ProgressBarWidget pbar = new ProgressBarWidget();
gui.addChild(pbar.extern, GUI_ALIGN_CENTER);
....


and i have the following message 
post-1525-0-74946000-1417001279_thumb.png

Is there some sintaxis error?

 

Link to comment

Hi,

 

There is no easy way to inherit from base class. Could you please try to inherit from Unigine::Widgets. For example, using this code:

#include <core/systems/widgets/widget.h>

using Unigine::Widgets;

class ProgressBarWidget : Widget
{
 int width = 150;
 
 ProgressBarWidget(int w) {
  __Widget__(w);
}
 
 ~ProgressBarWidget() {
  __Widget__();
 }
};

Thanks!

How to submit a good bug report
---
FTP server for test scenes and user uploads:

Link to comment

Actually, you have a lot of options here:

 

1) Inherit from WidgetExternBase. That way you'll be able to create your custom widget from C++ side as well as from the script.

2) Don't use inheritance at all and use WidgetCanvas instead to draw custom graphics and event handling. So your custom widget will be a wrapper class over WidgetCanvas.

3) Inherit from Unigine::Widgets::Widget class in the script as it has support for both multi- and single window modes. That's the way silent had suggested you.

 

By the way, I've modified your code so it's working now. Please find it in the attachments.

 

Have a good weekend!

Empty.zip

Link to comment

Thank you very much!

it works great, I'll use 3'rd way.

I need to drow some custom texture inside widget with local (relatively to container coordinates), i think WidgetCanvas cant do this.

WidgetExternBase is ok but all GUI part of my application is already in scripts now, its bad to separate my code, and put widgets to c++ code.

Link to comment

I still have trouble adding my custom ProgressBarWidget widget to ObjectGui. 
 

ObjectGui object_gui = add_editor(new ObjectGui(30.0f, 30.0f));
object_gui.setPosition(dvec3(0, 0, 10 + 15));
object_gui.setBillboard(1);
object_gui.setBackground(0);
object_gui.setMaterial("gui_base","*");
object_gui.setProperty("surface_base","*");
object_gui.setScreenSize(300, 300);
object_gui.setControlDistance(100000.0f);
Gui gui = object_gui.getGui();
 
 
ProgressBarWidget pbw = new ProgressBarWidget(10, gui);
pbw.stop();
 
WidgetVBox allContainer = new WidgetVBox(gui);
allContainer.addChild(pbw);
gui.addChild(allContainer, GUI_ALIGN_CENTER);

Empty.rar

I got this message
post-1525-0-74449600-1417271550_thumb.png


there is no trouble when i add widget:
addChild(pbw,ALIGN_CENTER);

 
Link to comment

That's because Unigine::Widgets::Widget script class is not inherited from C++ Widget class, it's a wrapper. That said, it won't work with gui.addChild method that way yet there're few ways to solve this.

 

You can either access its inner field

ProgressBarWidget pbw = new ProgressBarWidget(10,gui);

gui.addChild(pbw.widget, GUI_ALIGN_EXPAND);

or just use addChild method.

Link to comment
×
×
  • Create New...