Jump to content

How to draw a garaph inside a container


Recommended Posts

Posted

You place the graph widget into the container - just as you would with any other widget/container combination:

// Create the container
wi.g.y = 10;
wi.g.x = 10;
wi.g.width = 320;
wi.g.height = 240;
wi.text = "Container";
ghContainer = gwinContainerCreate(0, &wi, GWIN_CONTAINER_BORDER);

// Create the graph
wi.g.x = 10;
wi.g.y = 10;
wi.g.width = 300;
wi.g.height = 200;
wi.g.parent = ghContainer;	// Specify the parent container
ghGraph = gwinGraphCreate(0, &wi.g);

 

  • 2 weeks later...
Posted

Hi

Look at this code ...

Its the widget example of UGFX that i add graph to containerpage0 ...

But when i click on change page the screen is white!!!!!

all of the pre-conditions is adjusted too.

58.PNG

Posted

The thing to remember about the graph window is that it doesn't store state. If the screen gets redrawn the user needs to redraw the graph as the default redraw action for the graph is just to fill with the background color waiting for the user to redraw the graph itself.

So, when the container the graph is on gets redrawn, the container then tells its children to redraw, the graph because it does not retain state just clears its background which leads to what you have seen.

To solve your problem you need to redraw your graph after your container becomes visible.

Another little gotcha is that window redrawing on ugfx often occurs on the delayed timer thread. The solution is to put a gfxYield call after making the container visible then redraw the graph after the gfxYield. 

The reason the graph does not maintain state is because to do so in a general manner would take too much ram. The application either already has the state or it will be redrawing new state (for a moving graph).

Posted (edited)

Hi dear..

What is gfxaYield? I could not  notice!  

May you give an example with gfxYield?

Of course I use keel rtx (os)

Thanks if answer 

Edited by 91321146
Posted

The function gfxYield() is a function provided by the GOS module. Yielding is a generic concept of operating systems. A thread can give up his remaining time slice of processor time to other threads by calling gfxYield(). The detailed behavior depends on the underlying system that is being used.

API documentation of gfxYield(): http://api.ugfx.io/group___g_o_s.html#ga48e13e354721ffac812c59d360956556

Posted

As @inmarket explained: The reason you get an empty box is because a graph is a window, not a widget. As explained in the documentation for the widgets, once of the differences between a window and a widget is that a widget is always able to redraw it self, whereas a windows doesn't know how to redraw itself. The graph is a window and not a widget because it is either too complex or too expensive for the GWIN module to buffer the graph data.

The thing about gfxYield() that @inmarket mentioned is only some additional background information. Solely using gfxYield() will not resolve your "problem".

To summarize: A graph is not able to redraw itself because it doesn't know the contents that it is displaying. This is a design decision that was made to keep everything small, fast & simple. It is up to the user (you) to redraw the graph when necessary.
If you have some very specific needs, it is always possible to implement a custom widget based on the graph window. In that custom widget you can store the data you want to display and do other things that are specific to your application.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...