Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1e77d7f

Browse files
focus_direction: also consider children
1 parent46d51ab commit1e77d7f

File tree

1 file changed

+28
-16
lines changed

1 file changed

+28
-16
lines changed

‎internal_filesystem/lib/mpos/ui/focus_direction.py‎

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
importlvglaslv
33
importmpos.util
44

5+
importmath
6+
57
defget_object_center(obj):
68
"""Calculate the center (x, y) of an object based on its position and size."""
79
width=obj.get_width()
@@ -30,9 +32,19 @@ def compute_angle_to_object(from_obj, to_obj):
3032
angle_deg=math.degrees(angle_rad)
3133
return (angle_deg+360)%360# Normalize to [0, 360)
3234

35+
defis_object_in_focus_group(focus_group,obj):
36+
"""Check if an object is in the focus group."""
37+
ifobjisNone:
38+
returnFalse
39+
forobjnrinrange(focus_group.get_obj_count()):
40+
iffocus_group.get_obj_by_index(objnr)isobj:
41+
returnTrue
42+
returnFalse
43+
3344
deffind_closest_obj_in_direction(focus_group,current_focused,direction_degrees,angle_tolerance=45):
3445
"""
35-
Find the closest object (including children) in the specified direction from the current focused object.
46+
Find the closest object in the specified direction from the current focused object.
47+
Only considers objects that are in the focus_group (including children of any object).
3648
Direction is in degrees: 0° = UP, 90° = RIGHT, 180° = DOWN, 270° = LEFT (clockwise).
3749
Returns the closest object within ±angle_tolerance of direction_degrees, or None.
3850
"""
@@ -54,22 +66,23 @@ def process_object(obj, depth=0):
5466
ifobjisNoneorobjiscurrent_focused:
5567
return
5668

57-
# Compute angle to the object
58-
angle_deg=compute_angle_to_object(current_focused,obj)
59-
60-
# Check if object is in the desired direction (within ±angle_tolerance)
61-
angle_diff=min((angle_deg-direction_degrees)%360, (direction_degrees-angle_deg)%360)
62-
ifangle_diff<=angle_tolerance:
63-
# Calculate Euclidean distance
64-
obj_x,obj_y=get_object_center(obj)
65-
distance=math.sqrt((obj_x-current_x)**2+ (obj_y-current_y)**2)
69+
# Check if the object is in the focus group and evaluate it
70+
ifis_object_in_focus_group(focus_group,obj):
71+
# Compute angle to the object
72+
angle_deg=compute_angle_to_object(current_focused,obj)
6673

67-
# Update closest object if this one is closer
68-
ifdistance<min_distance:
69-
min_distance=distance
70-
closest_obj=obj
74+
# Check if object is in the desired direction (within ±angle_tolerance)
75+
angle_diff=min((angle_deg-direction_degrees)%360, (direction_degrees-angle_deg)%360)
76+
ifangle_diff<=angle_tolerance:
77+
# Calculate Euclidean distance
78+
obj_x,obj_y=get_object_center(obj)
79+
distance=math.sqrt((obj_x-current_x)**2+ (obj_y-current_y)**2)
80+
# Update closest object if this one is closer
81+
ifdistance<min_distance:
82+
min_distance=distance
83+
closest_obj=obj
7184

72-
# Process children
85+
# Process children regardless of parent's focus group membership
7386
forchildnrinrange(obj.get_child_count()):
7487
child=obj.get_child(childnr)
7588
process_object(child,depth+1)
@@ -87,7 +100,6 @@ def process_object(obj, depth=0):
87100

88101
returnclosest_obj
89102

90-
91103
# This function is missing so emulate it using focus_next():
92104
defemulate_focus_obj(focusgroup,target):
93105
forobjnrinrange(focusgroup.get_obj_count()):

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp