在Kial Vertex指令上在ModalView上绘制阴影边框?

问题描述

我正在尝试使用ModalView Canvas顶点指令为Line绘制阴影。即ModalView底部和左侧在打开时应具有轻微的阴影覆盖。我尝试调用ModalView属性overlay_color无效,并且Canvas Line顶点指令不能产生正确的效果。但是我似乎不能只画出阴影效果底部和左侧边框。

<PopScrollModal>
    on_open: app.root._is_modal_open = True
    on_dismiss: app.root._is_modal_open = False
    id: popscroll
    auto_dismiss: True
    orientation: 'vertical'
    size_hint: (0.94,0.41)
    border: [50,50,16,16]
    overlay_color: [0.1,0.1,0.4]
    pos_hint: {'top': 0.72}
    background_normal: ''
    background_color: (1,1,0)
    background: 'white.png'
    canvas:
        Color:
            rgba: app.theme_cls.bg_dark
        RoundedRectangle:
            size: self.size
            pos: self.pos
            radius: [7,]
    canvas.after:
        Color:
            rgba: (0.2,0.2,0.4)
        Line:
            width: 1.
            rounded_rectangle: (self.x,self.y,self.width,self.height,7)
    RecycleView:
        id: view_popscroll
        viewclass: 'PopScrollBut'
        pos_hint: {'top': 1}
        size_hint: [1,0.99]
        do_scroll_y: True
        RecycleGridLayout:
            cols: 1
            spacing: 1
            default_size: None,70
            default_size_hint: 1,None
            size_hint: 1,None
            size: self.minimum_size

此行指令绘制在底部,但不遵循画布的半径:

canvas.after:
        Color:
            rgba: (0.2,0.4)
        Line:
            width: 1.
            close: False
            points: self.pos[0],self.pos[1],self.pos[0] + self.size[0],self.pos[1]]

Line指令仅在ModalView周围画一条线。 有人可以帮助您了解如何设置Points以便它们只出现在左侧和底部还是以相同的方式设置overlay_color

解决方法

您可以使用BorderImage进行操作。它没有很好的文档记录,很难理解它实际上是如何工作的。但这是一个示例,该示例主要执行您想要的操作:

class MyPop(Popup):
    pass

kv = '''
<MyPop>:
    canvas.before:
        BorderImage:
            source: 'shadow32.png'
            border: 30,30
            pos: self.x - 30,self.y - 30
            size: self.width + 60,self.height + 60
'''

这是上面使用的shadow32.png

enter image description here