KivyMD icon indicating copy to clipboard operation
KivyMD copied to clipboard

Positioning of MDTopAppBar elements #2

Open AHiXilTOr opened this issue 1 year ago • 7 comments

Description of the Bug

pos_hint: {"center_x": .5} doesn't work

Code and Logs

from kivymd.app import MDApp
from kivy.lang import Builder

kv = """
MDScreen:
    md_bg_color: self.theme_cls.secondaryContainerColor

    MDTopAppBar:
        type: "small"
        size_hint_x: .8
        pos_hint: {"center_x": .5, "center_y": .5}

        MDTopAppBarLeadingButtonContainer:

            MDActionTopAppBarButton:
                icon: "menu"

        MDTopAppBarTitle:
            text: "AppBar small"
            pos_hint: {"center_x": .5}

        MDTopAppBarTrailingButtonContainer:

            MDActionTopAppBarButton:
                icon: "account-circle-outline"
"""

class App(MDApp):
    def build(self):
        return Builder.load_string(kv)

App().run()
"""


class MainApp(App):
    def build(self):
        self.root = Builder.load_string(kv)


if __name__ == '__main__':
    MainApp().run()

Screenshots

333584429-86ae5ae8-2665-48a5-8985-04b59746f130

Versions

  • OS: Any
  • Python: Any
  • Kivy: Any
  • KivyMD: dev

AHiXilTOr avatar May 29 '24 10:05 AHiXilTOr

What is the use case of centering that icon?

It does not matches material design spec.

https://m3.material.io/components/top-app-bar/specs

(It does not declare anywhere to center icons)

T-Dynamos avatar May 29 '24 12:05 T-Dynamos

What is the use case of centering that icon?

It does not matches material design spec.

https://m3.material.io/comComponents/top-app-bar/specs

(It does not declare anywhere to center icons)

Not an icon, but a title.

AHiXilTOr avatar May 29 '24 15:05 AHiXilTOr

I also encountered the same problem

WangZhongDian avatar Jun 05 '24 08:06 WangZhongDian

I also encountered the same problem

nattokukun avatar Jul 10 '24 05:07 nattokukun

I also encountered the same problem

jporta09 avatar Jul 12 '24 01:07 jporta09

I also encountered the same problem

The problem seems to happen only when you try to center align the title. If you remove the alignment (pos_hint: {"center_x": .5}) Then everything works fine.

theolaos avatar Jul 17 '24 20:07 theolaos

I see solved. thank you very much.

nattokukun avatar Jul 18 '24 02:07 nattokukun

I also face the same issue, and removing "pos_hint: {"center_x": .5}" does not help. However, the problem goes away if I update the text from code, or resize window. It seems the problem is in some order of updates.

MaxSavenkov avatar Oct 31 '24 21:10 MaxSavenkov

Fixed it by adding very small padding to the parent layout that contains the MDTopAppBar, and never leaving it completely empty.

Example:

MDBoxLayout:
        orientation: 'vertical'
        size_hint: 1, 1
        padding: 0.1, 0.1    # This is insignificant and cant be seen, but fixes the bug without requiring re-sizing the windows

        MDTopAppBar:
            type: "small"
                    
            MDTopAppBarLeadingButtonContainer:
                MDActionTopAppBarButton:
                    icon: "menu"
                    
            MDTopAppBarTitle:
                text: " "    # Empty space, otherwise wont work. Works with anything but empty.

            MDTopAppBarTrailingButtonContainer:
                MDActionTopAppBarButton:
                    icon: "dots-vertical"

Took the idea from PR https://github.com/kivymd/KivyMD/pull/1746

LoloCG avatar Nov 28 '24 23:11 LoloCG