Mercurial > libervia-desktop-kivy
diff cagou/core/menu.py @ 216:e42e0c45d384
core (menu): allow to specify size in SideMenu:
size menu now use 4 variable to open and close state:
- size_hint_close
- size_hint_open
- size_open
- size_close
if one value of size_hint_open or size_hint_close tuples is None, the corresponding size is used instead.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 24 Jun 2018 22:08:16 +0200 |
parents | c7d15ef4bfa8 |
children | a676cb07c1cb |
line wrap: on
line diff
--- a/cagou/core/menu.py Sun Jun 24 22:02:30 2018 +0200 +++ b/cagou/core/menu.py Sun Jun 24 22:08:16 2018 +0200 @@ -179,8 +179,10 @@ class SideMenu(BoxLayout): - base_size_hint_close = (0, 1) - base_size_hint_open = (0.4, 1) + size_hint_close = (0, 1) + size_hint_open = (0.4, 1) + size_close = (100, 100) + size_open = (0, 0) bg_color = properties.ListProperty([0, 0, 0, 1]) # callback will be called with arguments relevant to menu callback = properties.ObjectProperty() @@ -195,14 +197,38 @@ if self.cancel_cb is None: self.cancel_cb = self.onMenuCancelled + def _set_anim_kw(self, kw, size_hint, size): + """Set animation keywords + + for each value of size_hint it is used if not None, + else size is used. + If one value of size is bigger than the respective one of Window + the one of Window is used + """ + size_hint_x, size_hint_y = size_hint + width, height = size + if size_hint_x is not None: + kw['size_hint_x'] = size_hint_x + elif width is not None: + kw['width'] = min(width, Window.width) + + if size_hint_y is not None: + kw['size_hint_y'] = size_hint_y + elif height is not None: + kw['height'] = min(height, Window.height) + def show(self, caller_wid=None): Window.bind(on_keyboard=self.key_input) G.host.app.root.add_widget(self) - Animation(size_hint=self.base_size_hint_open, d=0.3, t='out_back').start(self) + kw = {'d': 0.3, 't': 'out_back'} + self._set_anim_kw(kw, self.size_hint_open, self.size_open) + Animation(**kw).start(self) def hide(self): Window.unbind(on_keyboard=self.key_input) - anim = Animation(size_hint=self.base_size_hint_close, d=0.2) + kw = {'d': 0.2} + self._set_anim_kw(kw, self.size_hint_close, self.size_close) + anim = Animation(**kw) anim.bind(on_complete=lambda anim, menu: self.parent.remove_widget(self)) anim.start(self) if self.callback_on_close: @@ -243,8 +269,8 @@ transfer_txt = _(u"Beware! The file will be sent to your server and stay unencrypted there\nServer admin(s) can see the file, and they choose how, when and if it will be deleted") send_txt = _(u"The file will be sent unencrypted directly to your contact (without transiting by the server), except in some cases") items_layout = properties.ObjectProperty() - base_size_hint_close = (1, 0) - base_size_hint_open = (1, 0.5) + size_hint_close = (1, 0) + size_hint_open = (1, 0.5) def __init__(self, **kwargs): super(TransferMenu, self).__init__(**kwargs) @@ -281,6 +307,10 @@ layout = properties.ObjectProperty() instructions = properties.StringProperty(_(u"Please select entities")) filter_input = properties.ObjectProperty() + size_hint_close = (None, 1) + size_hint_open = (None, 1) + size_open = (dp(250), 100) + size_close = (0, 100) def __init__(self, **kwargs): super(EntitiesSelectorMenu, self).__init__(**kwargs)