KivyMD icon indicating copy to clipboard operation
KivyMD copied to clipboard

Issue in MDIconButton

Open AnEx07 opened this issue 4 years ago • 13 comments

in android MDIconButton.set_size calculating bg size is too big

i fix it with def set_size(self, interval): print("here...") self.width = ( "48sp" if not self.user_font_size else self.user_font_size + sp(25) ) self.height = ( "48sp" if not self.user_font_size else self.user_font_size + sp(25) )

AnEx07 avatar Sep 11 '21 19:09 AnEx07

@AnEx07 Please edit the example code and attach screenshots that show the icon size before and after your changes...

HeaTTheatR avatar Sep 11 '21 20:09 HeaTTheatR

Screenshot from 2021-09-13 21-31-05 output in desktop Screenshot_2021-09-13-21-35-58-928_anex pack test_app output in android

    __version__ = "0.0.1"
    
    from kivy.lang import Builder
    
    from kivymd.app import MDApp
    from kivymd.uix.button import MDIconButton
    from kivy.metrics import sp
    
    
    KV = '''
    MDScreen:
    
        MDIconButton:
            icon: "language-python"
            pos_hint: {"center_x": .5, "center_y": .75}
            md_bg_color: [1,0,0,1]
            user_font_size: "30sp"
            
    
        NewMDIconButton:
            icon: "language-python"
            pos_hint: {"center_x": .5, "center_y": .35}
            md_bg_color: [1,0,0,1]
            user_font_size: "30sp"
    
        
    '''
    
    class NewMDIconButton(MDIconButton):
        def set_size(self, interval):
            print("here...")
            self.width = (
                "48sp" if not self.user_font_size else self.user_font_size + sp(25)
            )
            self.height = (
                "48sp" if not self.user_font_size else self.user_font_size + sp(25)
            )
    
    
    
    
    class Example(MDApp):
        def build(self):
            return Builder.load_string(KV)
    
    
    Example().run()

AnEx07 avatar Sep 13 '21 16:09 AnEx07

and also my suggestion is to use sp as a default metrics it behave same almost same in android and desktop

AnEx07 avatar Sep 13 '21 16:09 AnEx07

@AnEx07 I don't see any problem ...

HeaTTheatR avatar Sep 13 '21 16:09 HeaTTheatR

the problem is the background size is too big for a given user_font_size in current MDIconButton as shown in upper icon button of output on android screenshot but the background size in lower icon button is seems to be ok while user_font_size is same in both

AnEx07 avatar Sep 13 '21 17:09 AnEx07

here real issue i face... Screenshot from 2021-09-13 22-57-46 output in desktop Screenshot from 2021-09-13 22-58-14 also output in desktop but similar ratio Screenshot_2021-09-13-23-00-38-080_anex pack test_app output in android..

AnEx07 avatar Sep 13 '21 17:09 AnEx07

@AnEx07 I don't see this behavior on mobile devices ...

HeaTTheatR avatar Sep 13 '21 17:09 HeaTTheatR

@AnEx07 Please attach the minimal code that reproduces this behavior...

HeaTTheatR avatar Sep 13 '21 17:09 HeaTTheatR

__version__ = "0.0.1"



from kivy.lang import Builder

from kivymd.app import MDApp
from kivymd.uix.button import MDIconButton
from baseimport import *
from kivy.metrics import sp


KV = '''
MDScreen:
    MDIconButton:
        id: top1
        icon: "delete-sweep"
        pos_hint: {"center_x": 0.5,"center_y": 0.75}
        right: self.parent.right - sp(50)
        
        user_font_size: "25sp"
        mipmap: True
        md_bg_color: [0.8,0,0,0.5]

    MDIconButton:
        icon: "delete-sweep"
        x: top1.x-sp(30)
        y: top1.y-sp(30)

        right: self.parent.right - sp(50)
        
        user_font_size: "25sp"
        mipmap: True
        md_bg_color: [0.8,0,0,0.5]

    MDIconButton:
        icon: "delete-sweep"
        x: top1.x+sp(30)
        y: top1.y-sp(30)

        right: self.parent.right - sp(50)
        
        user_font_size: "25sp"
        mipmap: True
        md_bg_color: [0.8,0,0,0.5]
        
    NewMDIconButton:
        id: top2
        icon: "delete-sweep"
        pos_hint: {"center_x": 0.5,"center_y": 0.35}
        right: self.parent.right - sp(50)
        
        user_font_size: "25sp"
        mipmap: True
        md_bg_color: [0.8,0,0,0.5]

    NewMDIconButton:
        icon: "delete-sweep"
        x: top2.x-sp(30)
        y: top2.y-sp(30)

        right: self.parent.right - sp(50)
        
        user_font_size: "25sp"
        mipmap: True
        md_bg_color: [0.8,0,0,0.5]

    NewMDIconButton:
        icon: "delete-sweep"
        x: top2.x+sp(30)
        y: top2.y-sp(30)

        right: self.parent.right - sp(50)
        
        user_font_size: "25sp"
        mipmap: True
        md_bg_color: [0.8,0,0,0.5]
    


'''

class NewMDIconButton(MDIconButton):
    def set_size(self, interval):
        print("here...")
        self.width = (
            "48sp" if not self.user_font_size else self.user_font_size + sp(25)
        )
        self.height = (
            "48sp" if not self.user_font_size else self.user_font_size + sp(25)
        )




class Example(MDApp):
    def build(self):
        return Builder.load_string(KV)


Example().run()




AnEx07 avatar Sep 13 '21 17:09 AnEx07

please try that one

AnEx07 avatar Sep 13 '21 17:09 AnEx07

Screenshot_2021-09-13-23-28-29-202_anex pack test_app

AnEx07 avatar Sep 13 '21 17:09 AnEx07


print("current...")
print(self.user_font_size) # >>> 59.125 
print(dp(self.user_font_size)) # >>> 162.59375
print(dp(23)) # >>> 63.25
print(dp(self.user_font_size + 23)) # >>> 225.84375
print("48dp" if not self.user_font_size else dp(self.user_font_size + 23)) # >>> 225.84375

print("new...")
print(self.user_font_size) # >>> 59.125
print(sp(25)) # >>> 59.125
print(self.user_font_size + sp(25)) # >>> 118.25 
print("48sp" if not self.user_font_size else self.user_font_size + sp(25)) # >>> 118.25


here is output comparison of current and my script in android... please let me know if i can help with anything else.

AnEx07 avatar Sep 15 '21 06:09 AnEx07

I think the problem occurs when you trying to specify the font size in Kivy language and in Class with (def set size) together. Hope this is what you looking for. I have tested the code works fine on my Samsung phone. version = "0.0.1"

  from kivy.lang import Builder
  from kivymd.app import MDApp
  from kivymd.uix.button import MDIconButton
  from kivy.metrics import sp
  
  
  KV = '''
  MDScreen:
      MDIconButton:
          id: top1
          icon: "delete-sweep"
          pos_hint: {"center_x": 0.5,"center_y": 0.75}
          right: self.parent.right - sp(50)
          
          user_font_size: "25sp"
          mipmap: True
          md_bg_color: [0.8,0,0,0.5]
  
      MDIconButton:
          icon: "delete-sweep"
          x: top1.x-sp(30)
          y: top1.y-sp(30)
  
          right: self.parent.right - sp(50)
          
          user_font_size: "25sp"
          mipmap: True
          md_bg_color: [0.8,0,0,0.5]
  
      MDIconButton:
          icon: "delete-sweep"
          x: top1.x+sp(30)
          y: top1.y-sp(30)
  
          right: self.parent.right - sp(50)
          
          user_font_size: "25sp"
          mipmap: True
          md_bg_color: [0.8,0,0,0.5]
          
      NewMDIconButton:
          id: top2
          icon: "delete-sweep"
          pos_hint: {"center_x": 0.5,"center_y": 0.35}
          right: self.parent.right - sp(50)
          
          user_font_size: "25sp"
          mipmap: True
          md_bg_color: [0.8,0,0,0.5]
  
      NewMDIconButton:
          icon: "delete-sweep"
          x: top2.x-sp(30)
          y: top2.y-sp(30)
  
          right: self.parent.right - sp(50)
          
          user_font_size: "25sp"
          mipmap: True
          md_bg_color: [0.8,0,0,0.5]
  
      NewMDIconButton:
          icon: "delete-sweep"
          x: top2.x+sp(30)
          y: top2.y-sp(30)
  
          right: self.parent.right - sp(50)
          
          user_font_size: "25sp"
          mipmap: True
          md_bg_color: [0.8,0,0,0.5]
      
  
  
  '''
  
  class NewMDIconButton(MDIconButton):
      pass
  
  class MDIconButton(MDIconButton):
      pass
  
  class Example(MDApp):
      def build(self):
          return Builder.load_string(KV)
  
  
  Example().run()
  

sollarp avatar Sep 28 '21 21:09 sollarp