縦横比の固定

子の縦横比を固定するwidget。 FlutterのAspectRatio が基。

(Tested on CPython3.9.7 + Kivy2.1.0)

KXAspectRatio:
    Button:
_images/1to1.png
KXAspectRatio:
    aspect_ratio: 2 / 3
    Button:
_images/2to3.png
KXAspectRatio:
    aspect_ratio: 2 / 3
    halign: 'left'
    Button:
_images/2to3_left.png
KXAspectRatio:
    aspect_ratio: 2
    valign: 'bottom'
    Button:
_images/2to1_bottom.png

Warning

一般的に縦横比の為だけにwidgetを一つ増やすというのは負荷の割に見合わないらしいので大規模なアプリではこのwidgetを作りすぎないよう注意。

class kivyx.uix.aspectratio.KXAspectRatio(*args, **kwargs)[source]

Bases: Layout

aspect_ratio = 1.0

子の縦横比。1で正方形、1より大きいと横長、1より小さいと縦長になる。

halign = 'center'

横にゆとりがある時に子をどこに寄せるか。 centermiddle は中央、 left は左、 right は右に寄せる。

valign = 'center'

縦にゆとりがある時に子をどこに寄せるか。 centermiddle は中央、 bottom は下、 top は上に寄せる。