Setting widget depth in .kv language

244 views
Skip to first unread message

Adrian Forbes

unread,
Jun 21, 2017, 7:55:16 PM6/21/17
to kivy-...@googlegroups.com

Hi,
The app I am developing has a horizontal button bar (FloatLayout) along the top of the window. 
Beneath that is a BoxLayout containing a Scatter, which contains an Image.

I want to be able to scale the image without the image covering the buttons. 

For this to happen, either: 
  • the image must either be behind the button bar (i.e., deeper into the window)
      or ideally, 
  •  when the Scatter is scaled, its contents should not be displayed past the bounds of the BoxLayout

Here are two screenshots of the app:

Before scaling the image, image does not cover buttons:


After scaling the Scatter using its scale() method:


As you can see, the image covers the buttons when it is scaled.


Here is a snippet of .kv:
FloatLayout:
   
# Button bar
   
# Buttons etc.

BoxLayout:
   
...

   
Scatter:
       
BoxLayout:
           
size: self.parent.size
            id
: image_container
            orientation
: 'vertical'
           
pos: 0, 0
            
Image:
                id
:disc_image
                size_hint
: 1,1
                pos
: 0, 0
                allow_stretch
: True
                keep_ratio
: True
                opacity
: 0
                source
: None

Since I am adding the Scatter in kv language, I cannot set the depth with add_widget()'s index parameter as I would be able to in python code.
However, if I was to use the index parameter, I believe the BoxLayout that the button bar and Scatter are nested under would 
change their order as well as their depth, which is even less desirable.

It would seem that this is a fundamental problem in Kivy; it is necessary to be able to set widget depth and BoxLayout's order independently of each other.

Is there a way to set only the depth of widgets in the kv language?

Matthew Einhorn

unread,
Jun 22, 2017, 3:08:18 PM6/22/17
to Kivy users support
In kv-lang, the index is automatically set based on the order in which the widget children are listed. I think that should resolve your issue by re-ordering the widgets.

change their order as well as their depth, which is not favorable.

It would seem that this is a fundamental problem in Kivy; it is necessary to be able to set widget depth and order independently of each other.

Is there a way to set the depth of widgets in the kv language?

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Adrian Forbes

unread,
Jun 22, 2017, 4:48:43 PM6/22/17
to kivy-...@googlegroups.com
Thanks for the reply matham,
but re-ordering the widgets in a BoxLayout does not only change their depth but also their order in the y direction. In other words, the button bar would be at the bottom of the window instead of the top if I were to re-order the widgets. 

I am guessing there is no way around this then?

Thanks,
Adrian
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.

Wolfmanjm

unread,
Jun 22, 2017, 6:51:58 PM6/22/17
to Kivy users support
instead of z order you could use ScissorPush  and ScissorPop around the scatter.. eg

          Scatter:
                id: surface
                do_collide_after_children: True
                do_rotation: False
                canvas.before:
                    ScissorPush:
                        # without this we can see the scatter underneath the buttons in the rest of the window
                        x: self.parent.pos[0]
                        y: self.parent.pos[1]
                        width: self.parent.width
                        height: self.parent.height

                    Color:
                        rgb: 1, 1, 1, 1
                    Rectangle:
                        size: self.size

                canvas.after:
                    ScissorPop:

Bill Janssen

unread,
Jun 24, 2017, 11:07:54 PM6/24/17
to Kivy users support
Or you could use two different full-screen layouts, one for the buttons, and one for the image.  Remember that layouts are transparent unless you draw on them.

Bill


On Thursday, June 22, 2017 at 1:48:43 PM UTC-7, Adrian Forbes wrote:
Reply all
Reply to author
Forward
0 new messages