From bac114b6497cf487271fa77a2eb72eec69a0545e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=B2=D0=B0=D0=BD=D0=BE=D0=B2=20=D0=AE=D1=80=D0=B8?= =?UTF-8?q?=D0=B9?= Date: Tue, 21 May 2024 15:02:26 +0300 Subject: [PATCH] Fix https://github.com/kivymd/KivyMD/issues/1660 --- kivymd/uix/appbar/appbar.kv | 7 +++ kivymd/uix/appbar/appbar.py | 114 +++++++++++++++++++++--------------- 2 files changed, 73 insertions(+), 48 deletions(-) diff --git a/kivymd/uix/appbar/appbar.kv b/kivymd/uix/appbar/appbar.kv index 56df9ae82..87e9bfa90 100644 --- a/kivymd/uix/appbar/appbar.kv +++ b/kivymd/uix/appbar/appbar.kv @@ -20,6 +20,13 @@ + padding: + [ + self._appbar._left_padding, + 0, + self._appbar._right_padding, + 0, + ] font_style: { \ "small": "Title", \ diff --git a/kivymd/uix/appbar/appbar.py b/kivymd/uix/appbar/appbar.py index 176c98dd1..cb9694cb8 100755 --- a/kivymd/uix/appbar/appbar.py +++ b/kivymd/uix/appbar/appbar.py @@ -729,6 +729,12 @@ class MDTopAppBar( _trailing_button_container = ObjectProperty() _leading_button_container = ObjectProperty() _appbar_title = ObjectProperty() + _right_padding = NumericProperty(0) + _left_padding = NumericProperty(0) + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + Clock.schedule_once(lambda x: self.on_size(self, (0, 0))) def on_type(self, instance, value) -> None: def on_type(*args): @@ -745,16 +751,17 @@ def on_size(self, instance, size) -> None: self._appbar_title._title_width = ( self._appbar_title.texture_size[0] ) - Clock.schedule_once( - lambda x: self._appbar_title.on_pos_hint( - self._appbar_title, self._appbar_title.pos_hint - ) + self._right_padding = 0 + self._left_padding = 0 + self._appbar_title.on_pos_hint( + self._appbar_title, self._appbar_title.pos_hint ) def add_widget(self, widget, *args, **kwargs): if isinstance(widget, MDTopAppBarTitle): widget._appbar = self self._appbar_title = widget + widget.bind(text=lambda *x: self.on_size(*x)) Clock.schedule_once(lambda x: self._add_title(widget)) elif isinstance(widget, MDTopAppBarTrailingButtonContainer): self._trailing_button_container = widget @@ -779,81 +786,92 @@ def _set_padding_title(self, value): not self._trailing_button_container and self._leading_button_container ): - left_padding = (self.width // 2) - ( - self._leading_button_container.width - + (self._appbar_title._title_width // 2) - ) - self._appbar_title.padding = [left_padding, 0, 0, 0] + self._left_padding = ( + (self.width // 2) + - ( + self._leading_button_container.width + + (self._appbar_title._title_width // 2) + ) + ) - self._left_padding elif ( self._trailing_button_container and not self._leading_button_container ): - left_padding = (self.width // 2) - ( - self._appbar_title._title_width // 2 - ) - right_padding = (self.width // 2) - ( - self._trailing_button_container.width - + (self._appbar_title._title_width // 2) - ) - self._appbar_title.padding = [left_padding, 0, right_padding, 0] + self._left_padding = ( + (self.width // 2) - (self._appbar_title._title_width // 2) + ) - self._left_padding + self._right_padding = ( + (self.width // 2) + - ( + self._trailing_button_container.width + + (self._appbar_title._title_width // 2) + ) + ) - self._right_padding elif ( not self._trailing_button_container and not self._leading_button_container ): - left_padding = (self.width // 2) - ( - self._appbar_title._title_width // 2 - ) - right_padding = (self.width // 2) - ( - self._appbar_title._title_width // 2 - ) - self._appbar_title.padding = [left_padding, 0, right_padding, 0] + self._left_padding = ( + (self.width // 2) - (self._appbar_title._title_width // 2) + ) - self._left_padding + self._right_padding = ( + (self.width // 2) - (self._appbar_title._title_width // 2) + ) - self._right_padding elif ( self._trailing_button_container and self._leading_button_container ): - left_padding = (self.width // 2) - ( - self._leading_button_container.width - + (self._appbar_title._title_width // 2) - ) - right_padding = (self.width // 2) - ( - self._trailing_button_container.width - + (self._appbar_title._title_width // 2) - ) - self._appbar_title.padding = [left_padding, 0, right_padding, 0] + self._left_padding = ( + (self.width // 2) + - ( + self._leading_button_container.width + + (self._appbar_title._title_width // 2) + ) + ) - self._left_padding + self._right_padding = ( + (self.width // 2) + - ( + self._trailing_button_container.width + + (self._appbar_title._title_width // 2) + ) + ) - self._right_padding elif ( not value and self._trailing_button_container and self._leading_button_container ): if self.type == "small": - right_padding = self.width - ( - self._trailing_button_container.width - + self._leading_button_container.width - + self._appbar_title._title_width + + self._right_padding = ( + self.width + - ( + self._trailing_button_container.width + + self._leading_button_container.width + + self._appbar_title._title_width + ) + - self._right_padding ) - self._appbar_title.padding = [0, 0, right_padding, 0] elif ( not value and self._trailing_button_container and not self._leading_button_container ): if self.type == "small": - right_padding = self.width - ( - self._trailing_button_container.width - + self._appbar_title._title_width + self._right_padding = ( + self.width + - ( + self._trailing_button_container.width + + self._appbar_title._title_width + ) + - self._right_padding ) - self._appbar_title.padding = [ - dp(16), - 0, - right_padding - dp(16), - 0, - ] + self._left_padding = dp(16) elif ( not value and not self._trailing_button_container and not self._leading_button_container ): - self._appbar_title.padding_x = dp(16) + self._left_padding = dp(16) class MDBottomAppBar(