Skip to content
This repository has been archived by the owner on Dec 27, 2024. It is now read-only.

[Grid] replace Guidelines with viewBoxes #622

Merged
merged 5 commits into from
Jun 9, 2022

Conversation

jswong65
Copy link
Contributor

@jswong65 jswong65 commented Jun 1, 2022

This PR does two things:

  • it mainly replaced Guidelines with viewBoxes
  • it updated the return type of setters
  • it replaced the complicated data structures such as HashMap and Pair
  • it fixed an issue with responsive example in the GridExperiment
  • it updated activity_main.xml to show an example of a nested Grid.

To make the Grid more flexible, viewBoxes (Views) are created to replace Guidelines for widgets to add constraints to.
There are two main advantage of this approach:

  1. Only a less number of Views need to be created to arrange the widgets in the Grid.
  2. Offer the capability to create a nested Grid - (a Grid in another Grid)

The basic idea is that we create and place boxViews to constraint widgets. See the following figures for examples. Figure 1 shows how boxViews are created and rearranged for a 7 X 4 (rows X columns) Grid and Figure 2 shows an example of a 4 X 7 Grid.

The additional views needed to be created for the viewBox approach would be max(rows, columns). As for the Guideline approach, it would be (row - 1 + columns - 1).

Figure 1

Figure 2

@jswong65 jswong65 requested review from jafu888 and oscar-ad June 1, 2022 15:54
@jafu888
Copy link
Contributor

jafu888 commented Jun 8, 2022

  1. Remove Debug

  2. Remove HashMap<Integer, Pair<Integer, Integer>> type structures

  3. move to LayoutParams not Constraints

  4. change setters to "public void setXxxxxx(type value)"

  5. Gird should support 1x1 1xn nx1
    Support 1xN Nx1 1x1 grids (It ask constraintSet for 1x1 gird)

  6. Support not setting grid_col:

If grid_row and grid_col unspecified for n items make gird 
grid_row = cel(sqrt(n))
grid_col = cel(sqrt(n))

if only grid_row then grid_col = Math.cel(n/(float) grid_row)
if only grid_col then grid_row = Math.cel(n/(float) grid_col)
(this requires grid_row_specified and grid_col_specified  flags so that if unspecified it will auto adapt)
setRows(0)  reset to grid_row_spefied=false
setCol(0) reset to grid_col_spefied = false

  1. Add grid debug flag grid_debug="DESIGN_TIME|NEVER|ALWAYS"

Copy link
Contributor

@jafu888 jafu888 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing ConstraintSet
As an example of how you remove
assume you have

private ConstraintLayout.LayoutParams params(View v) {
  return  (ConstraintLayout.LayoutParams) view.getLayoutParams();
}

A chain is constraint like this
| | -> | |-> | |
start <- | View1 | | view2 | | view3 | -> end
| | <- | | <- | |
So if you are making a horizontal chain

int starId = StartView.getID();
int endId = EndView.getID();
int pre = startId
View[] toChain ... 
int [] chainIDs
for(int i = 0; i < toChain.length; i++){
     param= prams(toChain[i]) 
      if (i == 0)
      param.startToStart = pre;
      else 
       param.startToEnd = pre;
       if (i == lastInChain) 
       param.endToEnd = endId;
       else 
        param.endToStart = chainId[i+1];
          pre = chainId[i];
          toChain[i].setLayoutParams(param);
        }
        
        
        

@jafu888
Copy link
Contributor

jafu888 commented Jun 9, 2022

All other issues will be addressed in another PR

@jafu888 jafu888 merged commit 387efca into androidx:main Jun 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants