Skip to content

Commit 5f7e55c

Browse files
myNameArnavCursor Grok 4.6
andcommitted
applib: draw attached action bars from their laid-out frame
is_on_right() is the desired side for new bars. Press animation and round fill were using that live value, so a Settings toggle or late opt-in could flip drawing while the strip stayed put. Co-authored-by: Cursor Grok 4.6 <noreply@cursor.com> Signed-off-by: Arnav Jain <arnjain3@gmail.com>
1 parent 1fdb88d commit 5f7e55c

2 files changed

Lines changed: 16 additions & 6 deletions

File tree

src/fw/applib/ui/action_bar_layer.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ bool action_bar_layer_is_on_right(void) {
6969
return true;
7070
}
7171

72+
// Laid-out frame side. Drawing must not follow a live pref/opt-in change.
73+
static bool prv_attached_bar_is_on_right(const ActionBarLayer *action_bar) {
74+
if (!action_bar->window) {
75+
return action_bar_layer_is_on_right();
76+
}
77+
return action_bar->layer.frame.origin.x != 0;
78+
}
79+
7280
int16_t action_bar_layer_get_content_origin_x(void) {
7381
return action_bar_layer_is_on_right() ? 0 : prv_width();
7482
}
@@ -206,7 +214,7 @@ static GPoint prv_get_button_press_offset(ActionBarLayer *action_bar, uint8_t bu
206214
GPoint(0, animation_offset),
207215
};
208216
// MoveLeft is "toward content" when the bar is on the right; flip when it is on the left.
209-
if (!action_bar_layer_is_on_right()) {
217+
if (!prv_attached_bar_is_on_right(action_bar)) {
210218
offset[ActionBarLayerIconPressAnimationMoveLeft].x = animation_offset;
211219
offset[ActionBarLayerIconPressAnimationMoveRight].x = -animation_offset;
212220
}
@@ -224,7 +232,7 @@ void prv_draw_background_round(ActionBarLayer *action_bar, GContext *ctx, GColor
224232
GRect action_bar_circle_frame = (GRect) {
225233
.size = GSize(action_bar_circle_diameter, action_bar_circle_diameter)
226234
};
227-
const GAlign align = action_bar_layer_is_on_right() ? GAlignLeft : GAlignRight;
235+
const GAlign align = prv_attached_bar_is_on_right(action_bar) ? GAlignLeft : GAlignRight;
228236
grect_align(&action_bar_circle_frame, &action_bar->layer.bounds, align, false /* clips */);
229237
graphics_fill_oval(ctx, action_bar_circle_frame, GOvalScaleModeFitCircle);
230238
}
@@ -280,7 +288,7 @@ void action_bar_update_proc(ActionBarLayer *action_bar, GContext* ctx) {
280288
grect_align(&icon_rect, &rect, GAlignCenter, clip);
281289
#if PBL_ROUND
282290
// Offset needed because the curvature of the action bar makes the icons look off-center
283-
const int32_t icon_horizontal_offset = action_bar_layer_is_on_right() ? -2 : 2;
291+
const int32_t icon_horizontal_offset = prv_attached_bar_is_on_right(action_bar) ? -2 : 2;
284292
icon_rect.origin.x += icon_horizontal_offset;
285293
#endif
286294
icon_rect.origin.x += offset.x;

src/fw/applib/ui/action_bar_layer.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,12 +291,14 @@ void action_bar_layer_set_background_color(ActionBarLayer *action_bar, GColor ba
291291
//! Process-wide: affects every action bar in this app. Third-party apps default
292292
//! to the right edge; system and kernel UI always follow orientation. Call before
293293
//! \ref action_bar_layer_add_to_window(); it does not move a bar already
294-
//! attached to a window.
294+
//! attached to a window. Toggling Left-Handed Mode in Settings likewise leaves
295+
//! attached bars in place until the window is reopened or the bar is added again.
295296
//! @param follow true to place action bars on the button side in Left-Handed Mode
296297
void action_bar_layer_set_follows_display_orientation(bool follow);
297298

298-
//! Whether the action bar sits on the right edge of the window.
299-
//! @return true if the bar is (or will be) on the right, false if on the left
299+
//! Desired side for new bars (and for the inset helpers), not the frame of an
300+
//! already-attached bar.
301+
//! @return true if a newly added bar will sit on the right, false if on the left
300302
bool action_bar_layer_is_on_right(void);
301303

302304
//! X origin of the content area beside the action bar (0 when the bar is on the right).

0 commit comments

Comments
 (0)