11import arcade
2- from arcade .easing import linear
2+ from arcade .anim import Easing
33from arcade .gui import UIManager , TransitionChain , TransitionAttr , TransitionAttrIncr
44from arcade .gui .transition import TransitionAttrSet
55from arcade .gui .widgets .buttons import UIFlatButton
66
77
8+ class AutoSizeButton (UIFlatButton ):
9+ def __init__ (self , ** kwargs ):
10+ super ().__init__ (** kwargs )
11+ self .ui_label .fit_content ()
12+
13+ def prepare_layout (self ):
14+ # update size hint min to fit children
15+ min_w = max (map (lambda c : c .width , self .children ))
16+ min_h = max (map (lambda c : c .height , self .children ))
17+ self .size_hint_min = (min_w , min_h )
18+
19+
820class DemoWindow (arcade .Window ):
921 def __init__ (self ):
1022 super ().__init__ (800 , 600 , "UI Mockup" , resizable = True )
@@ -14,7 +26,7 @@ def __init__(self):
1426 self .manager = UIManager ()
1527 self .manager .enable ()
1628
17- button = self .manager .add (UIFlatButton (text = "Click me I can move!" ))
29+ button = self .manager .add (AutoSizeButton (text = "Click me I can move!" ))
1830 button .center_on_screen ()
1931
2032 @button .event
@@ -29,16 +41,20 @@ def on_click(event):
2941 chain .add (TransitionAttrIncr (attribute = "center_x" , increment = 100 , duration = 1.0 ))
3042 chain .add (
3143 TransitionAttrIncr (
32- attribute = "center_y" , increment = 100 , duration = 1 , ease_function = linear
44+ attribute = "center_y" , increment = 100 , duration = 1 , ease_function = Easing . LINEAR
3345 )
3446 )
3547
3648 # Go back
3749 chain .add (
38- TransitionAttr (attribute = "center_x" , end = start_x , duration = 1 , ease_function = linear )
50+ TransitionAttr (
51+ attribute = "center_x" , end = start_x , duration = 1 , ease_function = Easing .LINEAR
52+ )
3953 )
4054 chain .add (
41- TransitionAttr (attribute = "center_y" , end = start_y , duration = 1 , ease_function = linear )
55+ TransitionAttr (
56+ attribute = "center_y" , end = start_y , duration = 1 , ease_function = Easing .LINEAR
57+ )
4258 )
4359 chain .add (TransitionAttrSet (attribute = "disabled" , value = False , duration = 0 ))
4460
@@ -50,4 +66,5 @@ def on_draw(self):
5066
5167
5268if __name__ == "__main__" :
69+ arcade .resources .load_kenney_fonts ()
5370 DemoWindow ().run ()
0 commit comments