changeset 84:2caee196d19a

garden: context menu fixes: - fixed size so menus are displayed correclty on different screen resolutions - fixed position of ContextMenu on show these fixes haven been proposed upstream
author Goffi <goffi@goffi.org>
date Sat, 24 Dec 2016 14:20:40 +0100
parents 741a7d6d8c28
children c2a7234d13d2
files src/libs/garden/garden.contextmenu/app_menu.kv src/libs/garden/garden.contextmenu/context_menu.kv src/libs/garden/garden.contextmenu/context_menu.py
diffstat 3 files changed, 27 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/src/libs/garden/garden.contextmenu/app_menu.kv	Sat Dec 24 14:16:58 2016 +0100
+++ b/src/libs/garden/garden.contextmenu/app_menu.kv	Sat Dec 24 14:20:40 2016 +0100
@@ -1,5 +1,5 @@
 <AppMenu>:
-    height: 30
+    height: dp(30)
     size_hint: 1, None
 
     canvas.before:
@@ -14,11 +14,12 @@
     disabled: True
     size_hint: None, None
     on_children: self._check_submenu()
+    font_size: '15sp'
     background_normal: ""
     background_down: ""
     background_color: (0.2, 0.71, 0.9, 1.0) if self.state == 'down' else (0.2, 0.2, 0.2, 1.0)
     background_disabled_normal: ""
     background_disabled_down: ""
     border: (0, 0, 0, 0)
-    size: self.texture_size[0], 30
-    padding_x: 10
+    size: self.texture_size[0], dp(30)
+    padding_x: dp(10)
--- a/src/libs/garden/garden.contextmenu/context_menu.kv	Sat Dec 24 14:16:58 2016 +0100
+++ b/src/libs/garden/garden.contextmenu/context_menu.kv	Sat Dec 24 14:20:40 2016 +0100
@@ -6,16 +6,10 @@
     on_visible: self._on_visible(args[1])
     on_parent: self._on_visible(self.visible)
 
-#    canvas.before:
-#        Color:
-#            rgb: 1.0, 0, 0
-#        Rectangle:
-#            pos: self.pos
-#            size: self.size
     Widget:
         id: _spacer
         size_hint: 1, None
-        height: 3
+        height: dp(3)
         canvas.before:
             Color:
                 rgb: 0.2, 0.71, 0.9
@@ -39,11 +33,9 @@
     Widget:
         id: _submenu_arrow
         size_hint: None, None
-        width: 6
-        height: 11
-#        pos: 10, 10
-        pos: self.parent.width - self.width - 5, (self.parent.height - self.height) / 2
-#        on_pos: print(self.pos)
+        width: dp(6)
+        height: dp(11)
+        pos: self.parent.width - self.width - dp(5), (self.parent.height - self.height) / 2
         canvas.before:
             Translate:
                 xy: self.pos
@@ -58,7 +50,8 @@
 <ContextMenuText>:
     label: _label
     width: self.parent.width if self.parent else 0
-    height: 26
+    height: dp(26)
+    font_size: '15sp'
 
     Label:
         pos: 0,0
@@ -66,8 +59,7 @@
         text: self.parent.text
         color: self.parent.color
         font_size: self.parent.font_size
-        padding: 10, 0
-#        font_size:
+        padding: dp(10), 0
         halign: 'left'
         valign: 'middle'
         size: self.texture_size
@@ -85,8 +77,8 @@
 
 
 <ContextMenuDivider>:
-    font_size: '10dp'
-    height: 20 if len(self.label.text) > 0 else 1
+    font_size: '10sp'
+    height: dp(20) if len(self.label.text) > 0 else dp(1)
     canvas.before:
         Color:
             rgb: (0.25, 0.25, 0.25)
@@ -97,8 +89,8 @@
 
 <ContextMenuButton@Button>:
     size_hint: None, None
-    font_size: 12
-    height: 20
+    font_size: '12sp'
+    height: dp(20)
     background_normal: ""
     background_down: ""
     background_color: 0.2, 0.71, 0.9, 1.0
@@ -109,8 +101,8 @@
 
 <ContextMenuToggleButton@ToggleButton>:
     size_hint: None, None
-    font_size: '12px'
-    size: 30, 20
+    font_size: '12sp'
+    size: dp(30), dp(20)
     background_normal: ""
     background_down: ""
     background_color: (0.2, 0.71, 0.9, 1.0) if self.state == 'down' else (0.25, 0.25, 0.25, 1.0)
@@ -120,14 +112,14 @@
 
 
 <ContextMenuSmallLabel@Label>:
-    size: self.texture_size[0], 18
+    size: self.texture_size[0], dp(18)
     size_hint: None, None
-    font_size: '12dp'
+    font_size: '12sp'
 
 
 <ContextMenuTextInput@TextInput>:
     size_hint: None, None
-    height: 22
-    font_size: '12dp'
-    padding: 7, 3
-    multiline: False
\ No newline at end of file
+    height: dp(22)
+    font_size: '12sp'
+    padding: dp(7), dp(3)
+    multiline: False
--- a/src/libs/garden/garden.contextmenu/context_menu.py	Sat Dec 24 14:16:58 2016 +0100
+++ b/src/libs/garden/garden.contextmenu/context_menu.py	Sat Dec 24 14:20:40 2016 +0100
@@ -5,7 +5,6 @@
 from kivy.lang import Builder
 from kivy.clock import Clock
 from functools import partial
-import traceback
 
 import kivy.properties as kp
 import os
@@ -93,11 +92,11 @@
         # Choose the best position to open the menu
         if x is not None and y is not None:
             if point_relative_to_root[0] + self.width < root_parent.width:
-                pox_x = x
+                pos_x = x
             else:
-                pox_x = x - self.width
+                pos_x = x - self.width
                 if issubclass(self.parent.__class__, AbstractMenuItem):
-                    pox_x -= self.parent.width
+                    pos_x -= self.parent.width
 
             if point_relative_to_root[1] - self.height < 0:
                 pos_y = y
@@ -106,10 +105,7 @@
             else:
                 pos_y = y - self.height
 
-            parent_pos = root_parent.pos
-            pos = (pox_x + parent_pos[0], pos_y + parent_pos[1])
-
-            self.pos = pos
+            self.pos = pos_x, pos_y
 
     def self_or_submenu_collide_with_point(self, x, y):
         queue = self.menu_item_widgets
@@ -253,7 +249,6 @@
     def _on_hovered(self, new_hovered):
         if new_hovered:
             spacer_height = self.parent.spacer.height if self.parent.spacer else 0
-            point = self.right, self.top + spacer_height
             self.show_submenu(self.width, self.height + spacer_height)
         else:
             self.hide_submenu()