You are loading the kv file twice. By default the kv file with the same name as the App will be loaded. You can remove the explice Builder.load_file(), Note there is an warning in the log for loading the kv file twice.
[WARNING] [Lang ] The file C:\Users\ellio\PycharmProjects\KIvy-help-230\Degenerate Tech\slide_touch\ui12.kv is loaded multiples times, you might have unwanted behaviors.
This is why things worked when you added the "-", and you had problems without the "-".
To prevent the button from being pressed when moving, you can add a delay, if the move happens before the dealy completes the button is not touched. See below. Files are attached.
class UI12PanningLayout(FloatLayout):
obj=ObjectProperty(None)
extend=NumericProperty(dp(50))
_tou_up=BooleanProperty(False)
factor=0.15
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.x_displacement = 0
self.wait_for_move = None
def on_touch_down(self, touch):
if self.collide_point(*touch.pos):
touch.grab(self)
button = self.ids.button
if button.collide_point(*touch.pos):
# if a button is touched, wait 0.5 sec for a move
# if not moved, call the super().on_touch_down()
print('button pressed, wait for .5 sec for a move')
self.wait_for_move = Clock.schedule_once(lambda dt: self._button_touch(touch), 0.5)
return True
if self._tou_up:
self._tou_up=False
return super().on_touch_down(touch)
else:
return True
def _button_touch(self, touch):
return super().on_touch_down(touch)
def on_touch_move(self, touch):
if self.wait_for_move:
self.wait_for_move.cancel()
self.wait_for_move = None
if touch.grab_current is self:
#print(touch.dx)
# sum the touch.dx values, and scale size and position based on the sum of dx
self.x_displacement += touch.dx
# used the sort clamp the value x_displacement between self.ids.content.width and 0.
self.x_displacement = sorted([-self.ids.content.width+self.extend, self.x_displacement, 0])[1]
#print(f'{self.x_displacement=}')
self.ids.content.size = self.width + self.factor*self.x_displacement, self.height + self.factor*self.x_displacement
self.ids.content.pos = self.x_displacement, -(self.factor*self.x_displacement / 2)
#self.ids.menu.size = 300 + self.x_displacement, 600 + self.x_displacement
return super().on_touch_move(touch)