kivymd / KivyMD

KivyMD is a collection of Material Design compliant widgets for use with Kivy, a framework for cross-platform, touch-enabled graphical applications. https://youtube.com/c/KivyMD https://twitter.com/KivyMD https://habr.com/ru/users/kivymd https://stackoverflow.com/tags/kivymd
https://kivymd.readthedocs.io
MIT License
2.14k stars 655 forks source link

MDFabBottomAppBarButton Widget Positioning Issue #1630

Open AHiXilTOr opened 4 months ago

AHiXilTOr commented 4 months ago

When the screen expands sharply, the MDFabBottomAppBarButton widget goes out of frame. I have read that it is a FloatLayout, but when expanded a little (adding size), the widget does not change position relative to the position of MDBottomAppBar.

Code

from kivy.core.window import Window
from kivy.lang import Builder
from kivy.metrics import dp

from kivymd.uix.appbar import MDActionBottomAppBarButton
from kivymd.uix.boxlayout import MDBoxLayout
from kivymd.app import MDApp

KV = """
AdaptiveLayout:

    MDScreen:

        MDBoxLayout:
            orientation: "vertical"

            MDBottomAppBar:
                id: bottom_appbar

                MDFabBottomAppBarButton:
                    icon: "plus"
                    theme_bg_color: "Custom"
                    md_bg_color: "#373A22"
                    theme_icon_color: "Custom"
                    icon_color: "#ffffff"
"""

class AdaptiveLayout(MDBoxLayout):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.bind(size=self.on_window_size, pos=self.on_window_size)

    def on_window_size(self, instance, value):
        if Window.width > dp(600):
            instance.size_hint_x = None
            instance.width = dp(600)
            instance.pos_hint = {"center_x": 0.5}
        else:
            instance.size_hint_x = 1

class BottomAppBarButton(MDActionBottomAppBarButton):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.theme_bg_color = "Custom"
        self.md_bg_color = "#373A22"
        self.theme_icon_color = "Custom"
        self.icon_color = "#ffffff"

class Example(MDApp):
    selected_cards = False

    def build(self):
        return Builder.load_string(KV)

    def on_start(self):
        self.root.ids.bottom_appbar.action_items = [
            BottomAppBarButton(icon="magnify"),
            BottomAppBarButton(icon="trash-can-outline"),
            BottomAppBarButton(icon="download-box-outline"),
        ]

Example().run()

Screenshots

image

Versions

HeaTTheatR commented 4 months ago

Yes, it looks like a bug.

AHiXilTOr commented 4 months ago

Yes, it looks like a bug.

this happens due to binding to the screen, and not to the parent, please change the on_size path using this method from kivymd.uix.appbar import MDBottomAppBar

     def on_size(self, *args) -> None:
         #Fired when the root screen is resized.

         if self._fab_bottom_app_bar_button:
             self._fab_bottom_app_bar_button.x = Window.width - (dp(56) + dp(16))

on

     def on_size(self, *args) -> None:
         #Fired when the root widget is resized.

         if self._fab_bottom_app_bar_button:
             self._fab_bottom_app_bar_button.x = self.parent.width - (dp(56) + dp(16))