Skip to content

fix: send default alignment, padding and radius in shapes the renderer reads - #100

Open
AdamMusa wants to merge 1 commit into
mainfrom
fix/button-default-alignment-padding-radius
Open

AdamMusa wants to merge 1 commit into
mainfrom
fix/button-default-alignment-padding-radius

Conversation

@AdamMusa

Copy link
Copy Markdown
Owner

Fixes #94

What changed

Several controls gave their default arguments values in shapes the Flutter renderer cannot parse. They now send the shapes Flet sends for the same defaults:

DSL method Default before Default now
filled_icon_button, filled_tonal_icon_button, outlined_icon_button alignment: "center", padding: {"all" => 8} {"x" => 0.0, "y" => 0.0}, {"left" => 8, "top" => 8, "right" => 8, "bottom" => 8}
cupertino_button, cupertino_filled_button, cupertino_tinted_button alignment: "center", border_radius: {"all" => 8.0} {"x" => 0.0, "y" => 0.0}, {"top_left" => 8.0, "top_right" => 8.0, "bottom_left" => 8.0, "bottom_right" => 8.0}
cupertino_timer_picker alignment: "center" {"x" => 0.0, "y" => 0.0}
cupertino_text_field padding: {"all" => 7} {"left" => 7, "top" => 7, "right" => 7, "bottom" => 7}
  • Values an app passes explicitly are sent unchanged.
  • No app code change is needed.
  • Container already sends its "center" shorthand as {x: 0, y: 0} (normalize_container_props). This PR does the same for these defaults.

The renderer side is AdamMusa/ruflet-engine#119 (issue AdamMusa/ruflet-engine#118). It teaches the engine the old shapes, so apps on published gems get the fix after a template sync. This PR makes new gems render correctly on today's template without waiting for that sync.

Self-contained (--self) builds run the ruflet_core that is precompiled into the ruby_runtime VM artifacts. This PR does not rebuild them: the Android .so files are the owner's in-progress 16 KB work (D2). Those builds pick up the change when the VM is rebuilt for a release. Server-mode apps pick it up from the gem.

How verified

  • New packages/ruflet_core/test/default_value_wire_shapes_test.rb:

    • asserts the wire shapes above for all eight controls;
    • checks that explicit values still pass through unchanged;
    • builds every ControlFactory control that takes no arguments (395 of 458) and fails if any default sends an {"all" => n} map.
  • With the lib changes reverted (bug planted back), that file fails 5 of 6 tests. The guard lists cupertino_button.border_radius, cupertino_text_field.padding, filled_icon_button.padding, and the rest.

  • Updated the *_defaults_match_flet assertions in the cupertino button, timer picker, text field and three icon-button compatibility tests. They had asserted the unparseable values.

  • packages/ruflet_core: all 191 test files pass, one ruby -Ilib -Itest <file> process per file.

  • H1 goldens: cd packages/ruflet && ruby test/compat/compat.rb --jobs 4 checked 234 goldens with no differences. No golden contains these defaults.

  • I mounted the new wire on the unfixed engine parsers (codex/engine-initialization f44e7df7, flutter 3.41.2, both designs) with a throwaway widget probe. All 16 mounts render with no exception and no ErrorWidget:

    • IconButton padding EdgeInsets.all(8), alignment Alignment.center
    • iOS CupertinoButton radius BorderRadius.circular(8)
    • CupertinoTimerPicker.alignment Alignment.center
    • CupertinoTextField.padding EdgeInsets.all(7)

    ruflet-template main (e32c873d) vendors the same parsers and reads these keys at the same call sites (material_icon_button.dart:79-80, cupertino_button.dart:130-136, cupertino_timer_picker.dart:36, cupertino_textfield.dart:352).

Behavior changes

All bug fixes (D6).

  1. Crash becomes a rendered control. These controls built with default arguments used to show Flutter's error widget:

    • the three icon buttons, on both designs;
    • the Cupertino buttons, on iOS (template main; on the engine default branch also android);
    • the timer picker, on iOS.

    They now render, centered.

  2. Icon-button padding. An icon button built with an explicit alignment: and the default padding used to get 0 padding. It now gets 8, which is Flet's and Flutter's IconButton default.

  3. Cupertino button radius. A Cupertino button on iOS built with an explicit alignment: and the default radius used to get square corners. It now gets radius 8, the engine's own default.

  4. cupertino_text_field on iOS goes from 0 inner padding to 7. 7 is Flet's, Flutter's and the engine's declared default. This is the most visible change.

  5. props read-back. Code that reads these defaults back from control.props (for example button.props["alignment"]) now sees the Hash shapes in the table instead of "center" / {"all" => n}.

…r reads

Several controls gave their default arguments values the Flutter renderer
cannot parse:

- alignment "center" (filled_icon_button, filled_tonal_icon_button,
  outlined_icon_button, cupertino_button, cupertino_filled_button,
  cupertino_tinted_button, cupertino_timer_picker): the renderer's
  parseAlignment reads only {x, y} and threw on the String, so the control
  showed Flutter's error widget instead of rendering.
- padding {"all" => 8} (the three icon buttons) and {"all" => 7}
  (cupertino_text_field), border_radius {"all" => 8.0} (the three Cupertino
  buttons): the renderer reads only per-side and per-corner keys or a
  number, so these parsed as zero padding and square corners.

The defaults are now {"x" => 0.0, "y" => 0.0}, per-side padding and
per-corner radii, the shapes Flet sends for Alignment.CENTER,
Padding.all(n) and BorderRadius.all(n). Values an app passes are sent
unchanged. The engine also learns the old shapes (ruflet-engine#118) for
apps on published gems.

Fixes #94
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant