Jump to content

How to move a widget beyond the scope of it's parent


HWG

Recommended Posts

Hello all,

As the name of the topic,

I am trying to place a widget beyond the scope of it's parent

Let's assume we create one Container Widget w_con on display, with size Width 20, Height 10

and then create TWO Image Widget,  w_img_a and  w_img_b as the children of the w_con, with size Width 20, Height 10,

w_img_a with the position (-10, 0), w_img_b with the position (10, 0)

By that way, I want to display only right half of the w_img_a and left half of the w_img_b.

 

But because of the Windows Manager, w_img_a and w_img_b will always be changed on position (0, 0)

no matter in the gfxconf.h, I place GWIN_NEED_WINDOWMANAGER or not.

 

So does anyone know how I can manage to do it?

Do I really need to write my own WindowsManager to make it?

 

Link to comment
Share on other sites

Hello @HWG and welcome to the µGFX community!

You definitely don't have to write your own window manager to achieve this :) 
The proper solution is to write a custom widget which is a lot easier than it sounds the interface is well documented and there are tons of examples and even a step-by-step guide on how to do that. However, there's an easier solution: You can take the container widget and write a custom rendering routine for it. In that custom rendering routine you draw your two images by using gdispGDrawImage(). That function allows to specify what portion of an image you want to draw. Writing a custom rendering function is also very easy and well documented and there's also a how-to guide: https://wiki.ugfx.io/index.php/Creating_a_custom_rendering_routine

I hope that helps. Please don't hesitate to ask if you have any further questions. We're happy to help wherever we can! :) 

Link to comment
Share on other sites

In uGFX, children windows are always clipped (and resized) to their parents. To do anything else is incredibly complex would require lots of code and significant amounts of RAM.

As Joel said, the correct solution is a custom draw on the container that will draw the 2 half images

Link to comment
Share on other sites

5 hours ago, Joel Bodenmann said:

Let us know if you'd like us to write a quick example for this.

If it's possible, it would be very appreciate for you to write a quick example for this.

I am think it's good to write a customized Container widget with that feature.

Then that customized container can  display other normal widget in the same way.

I am also trying to write a example for that.

I am looking for the HOWTO write a customized widget now  :)

Link to comment
Share on other sites

Okay, here's your example:

deleteme.thumb.jpg.72978ce025939a7a5b0e0804eb690192.jpg

And here's a ZIP containing the entire code, the two source images and Makefile to run it directly on a Windows machine: win32_custom_rendering.zip

There might be some issues with the calculation of the coordinates of the images (line 32 and 37) - I didn't spend much time on it. One of the things that comes to mind is that the image sections are not vertically centered. But this should definitely get you started.

There are other things which you might want to consider such as image caching.

Link to comment
Share on other sites

Thank you very much for the example Joel.

It works for the simple implement.

 

But I am looking for some universal or common solution for that.

Because sometimes we want to just display some part of one window.

The window can not only contains image, but also other widgets.

 

After investigate the uGFX code a while,

I think I manage it for the universal solution.

but I modified 2 file in uGFX lib.

it's src/gwin/gwin_widget.c and src/gwin/gwim_wm.c

The modified files is in attachment.

 

The modification in gwin_wm.c happens in function WM_Size and WM_Move

it makes no clip for Move and Resize movement,

in order to make it available to place the widget beyond the scope of its parents.

 

The modification in gwin_widget.c happens in void _gwidgetRedraw(GHandle gh)

it makes the clipper will also happened for the area of widget's ancients,

so the widget will not be drawn out of the scope of its ancients, and still can be place out of the scope of it's ancients.

 

Do you think that can be a new feature to add in uGFX?

I think it's useful for some implementation.

And only less than 50 lines change.

 

gwin_widget.c

gwin_wm.c

Link to comment
Share on other sites

Sorry to hear that the example is somewhat useless then. I guess I didn't understand you properly. I thought that you need something just for the specific case of having images.

I haven't looked at your modifications yet as I'm somewhat super-busy these couple of days. I'm gonna let @inmarket have a look at that.
In general you won't only have a clipping issue but also the problem that the default window manager doesn't handle overlapping windows. It's only supported for the special case of containers. As I haven't looked at your modifications I can't say whether you'll be okay in this case or not, @inmarket will definitely have a lot more input on this.

For the case where you have to write your own window manager: That is possible and actually foreseen by the GWIN module. So far all the custom window managers I came across were all for commercial customers that didn't want to make their code become publicly available so there's nothing I can share with you right now. however, I have a friend (who is also on this forum) that once wrote one. I'm not sure to what extend he completed it but it was definitely able to handle overlapping windows. I'll ask him about that. Here's a demo: 

 

Link to comment
Share on other sites

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...