22import lvgl as lv
33import mpos .util
44
5- import math
65
76def get_object_center (obj ):
87"""Calculate the center (x, y) of an object based on its position and size."""
@@ -33,8 +32,8 @@ def compute_angle_to_object(from_obj, to_obj):
3332return (angle_deg + 360 )% 360 # Normalize to [0, 360)
3433
3534def is_object_in_focus_group (focus_group ,obj ):
36- """Check if an object is in the focus group."""
37- if obj is None :
35+ """Check if an object is in the focus group and not hidden ."""
36+ if obj is None or obj . has_flag ( lv . obj . FLAG . HIDDEN ) :
3837return False
3938for objnr in range (focus_group .get_obj_count ()):
4039if focus_group .get_obj_by_index (objnr )is obj :
@@ -79,7 +78,7 @@ def get_closest_edge_point_and_distance(from_x, from_y, obj, direction_degrees,
7978angle_diff = min ((angle_deg - direction_degrees )% 360 , (direction_degrees - angle_deg )% 360 )
8079if angle_diff > 45 :
8180if debug :
82- print (f"{ obj } at ({ x } ,{ y } ) size ({ width } x{ height } ): closest point ({ closest_x :.1f} ,{ closest_y :.1f} ), angle{ angle_deg :.1f} °, diff{ angle_diff :.1f} ° > 45° , skipped" )
81+ print (f"{ obj } at ({ x } ,{ y } ) size ({ width } x{ height } ): closest point ({ closest_x :.1f} ,{ closest_y :.1f} ), angle{ angle_deg :.1f} °, diff{ angle_diff :.1f} ° > 45, skipped" )
8382return None
8483
8584if debug :
@@ -90,8 +89,8 @@ def get_closest_edge_point_and_distance(from_x, from_y, obj, direction_degrees,
9089def find_closest_obj_in_direction (focus_group ,current_focused ,direction_degrees ,debug = False ):
9190"""
9291 Find the closest object in the specified direction from the current focused object.
93- Only considers objects that are in the focus_group (including children of any object).
9492 Uses closest edge point for distance to handle object sizes intuitively.
93+ Only considers objects that are in the focus_group and not hidden (including children).
9594 Direction is in degrees: 0° = UP, 90° = RIGHT, 180° = DOWN, 270° = LEFT (clockwise).
9695 Returns the closest object or None.
9796 """
@@ -100,7 +99,8 @@ def find_closest_obj_in_direction(focus_group, current_focused, direction_degree
10099return None
101100
102101if debug :
103- print (f"Current focused object:{ current_focused } " )
102+ print ("Current focused object:" )
103+ mpos .util .print_lvgl_widget (current_focused )
104104print (f"Default focus group has{ focus_group .get_obj_count ()} items" )
105105
106106closest_obj = None
@@ -114,7 +114,7 @@ def process_object(obj, depth=0):
114114if obj is None or obj is current_focused :
115115return
116116
117- # Check if the object is in the focus group and evaluate it
117+ # Check if the object is in the focus group andnot hidden, then evaluate it
118118if is_object_in_focus_group (focus_group ,obj ):
119119result = get_closest_edge_point_and_distance (current_x ,current_y ,obj ,direction_degrees ,debug )
120120if result :
@@ -123,7 +123,8 @@ def process_object(obj, depth=0):
123123min_distance = distance
124124closest_obj = obj
125125if debug :
126- print (f" Updated closest:{ obj } , distance{ distance :.1f} , angle{ angle_deg :.1f} °" )
126+ print (f" Updated closest (distance{ distance :.1f} , angle{ angle_deg :.1f} °):" )
127+ mpos .util .print_lvgl_widget (obj ,depth = depth )
127128
128129# Process children regardless of parent's focus group membership
129130for childnr in range (obj .get_child_count ()):
@@ -137,7 +138,8 @@ def process_object(obj, depth=0):
137138
138139# Result
139140if closest_obj :
140- print (f"Closest object in direction{ direction_degrees } °:{ closest_obj } " )
141+ print (f"Closest object in direction{ direction_degrees } °:" )
142+ mpos .util .print_lvgl_widget (closest_obj )
141143else :
142144print (f"No object found in direction{ direction_degrees } °" )
143145