fix(android): correct physical→logical px conversion for safe-area insets

`WindowInsets.getInsets(systemBars())` returns physical pixels (e.g. 84 px
on a 2.625× Pixel 7) but both Bevy's `Val::Px` (UI layer) and the world-
space layout coordinate system use logical pixels. Dividing by
`window.scale_factor()` before applying gives the correct 32 dp offset.

- `safe_area.rs::apply_safe_area_anchors`: query `Window`, divide `insets.top`
  by `scale_factor()` before writing `Val::Px(base_top + top_logical)`.
- `layout.rs::compute_layout`: new `safe_area_top: f32` parameter (logical px)
  subtracts from the vertical budget (`card_width_height_based`) and from
  `top_y` so both card sizing and pile positioning honour the status-bar band.
- `table_plugin.rs`: `setup_table` and `on_window_resized` now read
  `SafeAreaInsets` and divide by scale before passing `safe_area_top` to
  `compute_layout`. New `on_safe_area_changed` system fires a synthetic
  `WindowResized` when insets arrive (~frame 2-3 on Android) so the full
  resize pipeline (layout → pile markers → card snap) re-runs automatically.
- All test call-sites updated with `, 0.0` safe_area_top (desktop/no inset).
- Two regression tests added: shift amount equals `safe_area_top` exactly;
  horizontal layout is unaffected by vertical inset.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
funman300
2026-05-11 16:59:27 -07:00
parent 8a3e30bd16
commit cc161cc37f
7 changed files with 153 additions and 60 deletions
+6 -6
View File
@@ -1862,7 +1862,7 @@ mod tests {
// At game start waste is empty, so all 52 cards are across stock + tableau.
let g = GameState::new(42, solitaire_core::game_state::DrawMode::DrawOne);
let layout =
crate::layout::compute_layout(Vec2::new(1280.0, 800.0));
crate::layout::compute_layout(Vec2::new(1280.0, 800.0), 0.0);
let positions = card_positions(&g, &layout);
assert_eq!(positions.len(), 52);
}
@@ -1882,7 +1882,7 @@ mod tests {
.collect();
assert_eq!(waste_ids.len(), 3);
let layout = crate::layout::compute_layout(Vec2::new(1280.0, 800.0));
let layout = crate::layout::compute_layout(Vec2::new(1280.0, 800.0), 0.0);
let positions = card_positions(&g, &layout);
// Filter rendered positions to only waste cards (by card ID).
@@ -1911,7 +1911,7 @@ mod tests {
let waste_ids: std::collections::HashSet<u32> =
waste_pile.iter().map(|c| c.id).collect();
let layout = crate::layout::compute_layout(Vec2::new(1280.0, 800.0));
let layout = crate::layout::compute_layout(Vec2::new(1280.0, 800.0), 0.0);
let positions = card_positions(&g, &layout);
let mut waste_rendered: Vec<_> = positions
@@ -1936,7 +1936,7 @@ mod tests {
fn card_positions_tableau_cards_are_fanned_downward() {
let g = GameState::new(42, solitaire_core::game_state::DrawMode::DrawOne);
let layout =
crate::layout::compute_layout(Vec2::new(1280.0, 800.0));
crate::layout::compute_layout(Vec2::new(1280.0, 800.0), 0.0);
let positions = card_positions(&g, &layout);
// Collect positions for Tableau(6) (should have 7 cards).
@@ -2248,7 +2248,7 @@ mod tests {
#[test]
fn facedown_cards_use_tighter_fan_than_uniform_faceup_fan() {
let g = GameState::new(42, solitaire_core::game_state::DrawMode::DrawOne);
let layout = crate::layout::compute_layout(Vec2::new(1280.0, 800.0));
let layout = crate::layout::compute_layout(Vec2::new(1280.0, 800.0), 0.0);
let positions = card_positions(&g, &layout);
// Tableau(6) has 7 cards: 6 face-down + 1 face-up on top.
@@ -2409,7 +2409,7 @@ mod tests {
// Sanity-check: the new font size matches FONT_SIZE_FRAC × the
// post-resize card width, so the in-place path is using the
// refreshed Layout.
let expected_layout = crate::layout::compute_layout(Vec2::new(800.0, 600.0));
let expected_layout = crate::layout::compute_layout(Vec2::new(800.0, 600.0), 0.0);
let expected = expected_layout.card_size.x * FONT_SIZE_FRAC;
assert!(
(after - expected).abs() < 1e-3,