Grid and margins: draw the margins in the preview; fit them to the rows

The owner reported that the preview did not show the top and bottom
margins. On the emulator it did, but little: the rows share the height
the margins leave, so a first row moves by less than the margin, and
at about 40% of real size a 16 dp margin moves it some 6 dp. On a page
with few icons that is hard to see. At large values it also went wrong
the other way: a phone's grid (not scalable) does not shrink its icons
to fit shorter rows, so with labels on, 120 dp top and bottom cut off
the last row's labels (cell height 201 px, rows got 179 px).

Now:
- The preview draws the margins: tinted bands along the sides and
  above and below the rows, as wide as they are laid out, and a dashed
  outline around the rows (HomeMargins.Guides, through a new overlay
  slot in GridOverridesPreview). They show however empty the page is.
- Top and bottom margins take only the height the rows can spare
  beyond their icons and labels, cut in proportion
  (HomeMargins.fitTopBottom, in DeviceProfile.updateWorkspacePadding);
  DeviceProfile keeps what it laid out (flexeraTopMarginPx,
  flexeraBottomMarginPx) for the guides.
- When the grid has room for less than the sliders ask, a note under
  them says so and that fewer rows or columns leave more room.
- The class comment no longer claims that rows too short get smaller
  icons; that was wrong for these grids.

Tested on the emulator: guides on a 5x5 and a 4x9 grid line up with
the rows and columns; on 5x5 with labels 120/120 fits whole and no
label is cut; on 4x9 with labels the bands shrink to what fits and the
note shows; 8, 0, 0 leaves the layout as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
TMCandClaude Opus 5.5 committed 2026-11-18 14:44:33 +01:00
1 parent b092105ed9
commit 6e88f7c81b
5 files changed
+162 -8

No files matched your search

+18 -3
View File
@@ -352,6 +352,9 @@ public class DeviceProfile {
private int homeSideMarginDp;
private int homeTopMarginDp;
private int homeBottomMarginDp;
/** Flexera Launcher: the top and bottom margins as laid out, after fitting the rows. */
public int flexeraTopMarginPx;
public int flexeraBottomMarginPx;
private float widgetPaddingFactor;
// Flexera Launcher: widgets lined up with the icons (app.flexera.widget.FlexeraWidgets).
public boolean alignWidgetsWithIcons;
@@ -1827,9 +1830,21 @@ public class DeviceProfile {
int bottomHotseatReserve = Math.min(hotseatBarSizePx, paddingBottom);
paddingBottom = bottomHotseatReserve
+ Math.round((paddingBottom - bottomHotseatReserve) * workspacePaddingVerticalFactor);
// Flexera Launcher: the owner's top and bottom margins (app.flexera.home.HomeMargins).
paddingTop += app.flexera.home.HomeMargins.topBottomPx(homeTopMarginDp, mMetrics);
paddingBottom += app.flexera.home.HomeMargins.topBottomPx(homeBottomMarginDp, mMetrics);
// Flexera Launcher: the owner's top and bottom margins (app.flexera.home.HomeMargins),
// as far as the rows can spare the room. This grid does not shrink its icons to fit
// shorter rows, so taller margins would cut off the labels of the last row.
int rowsNeed = cellHeightPx * inv.numRows
+ cellLayoutBorderSpacePx.y * (inv.numRows - 1);
int spare = mDeviceProperties.getAvailableHeightPx()
- Math.max(paddingTop, cellLayoutPaddingPx.top)
- Math.max(paddingBottom, cellLayoutPaddingPx.bottom) - rowsNeed;
int[] margins = app.flexera.home.HomeMargins.fitTopBottom(
app.flexera.home.HomeMargins.topBottomPx(homeTopMarginDp, mMetrics),
app.flexera.home.HomeMargins.topBottomPx(homeBottomMarginDp, mMetrics), spare);
flexeraTopMarginPx = margins[0];
flexeraBottomMarginPx = margins[1];
paddingTop += margins[0];
paddingBottom += margins[1];
padding.set(paddingLeft, paddingTop, paddingRight, paddingBottom);
}