Skip to content
This repository was archived by the owner on Dec 31, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,37 @@ public MasonryLayout(int columnWidth) {
this();
getState().columnWidth = columnWidth;
}

/**
* Create new masonry layout with defined column width
* @param columnWidth Column width used to calculate left positions of items. Can not be changed after start.
* Remember to update horizontal values of CSS rules to match with this.
*/

/**
* Create new masonry layout with defined column width and gutter width
* @param columnWidth Column width used to calculate left positions of items. Can not be changed after start.
* @param gutter Gutter width (default 10). To set vertical space use margin CSS rule. (margin-bottom:10px). Can not be changed after start.
*/
public MasonryLayout(int columnWidth, int gutter) {
this();
getState().columnWidth = columnWidth;
getState().gutter = gutter;
}

/**
* Create new masonry layout with defined column width, gutter width and transition duration
* @param columnWidth columnWidth Column width used to calculate left positions of items. Can not be changed after start.
* @param gutter gutter Gutter width (default 10). To set vertical space use margin CSS rule. (margin-bottom:10px). Can not be changed after start.
* @param transitionDuration Duration of the transition when items change position or appearance, set in a CSS time format. Default 0.4s. Can not be changed after start.
*/
public MasonryLayout(int columnWidth, int gutter, String transitionDuration) {
this();
getState().columnWidth = columnWidth;
getState().gutter = gutter;
getState().transitionDuration = transitionDuration;
}


// We must override getState() to cast the state to MyComponentState
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,14 @@ public void onStateChanged(StateChangeEvent stateChangeEvent) {
clickEventHandler.handleEventHandlerRegistration();

// call always, will be ignored after first time
getWidget().initialize(getState().columnWidth);
getWidget().initialize(getState().columnWidth, getState().gutter, getState().transitionDuration);

}

@Override
public void onConnectorHierarchyChange(ConnectorHierarchyChangeEvent event) {

getWidget().initialize(getState().columnWidth);
getWidget().initialize(getState().columnWidth, getState().gutter, getState().transitionDuration);

for (ComponentConnector child : event.getOldChildren()) {
if (child.getParent() != this) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ public class MasonryLayoutState extends AbstractLayoutState {


public int columnWidth = 300;

public int gutter = 10;

public String transitionDuration = "0.4s";

/**
* Addtional stylenames for items (usually related to sizing)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ public MasonryPanel() {
setElement(Document.get().createDivElement());
}

public void initialize(int columnWidth) {
public void initialize(int columnWidth, int gutter, String transitionDuration) {
if(msnry != null) {
return;
}

msnry = initializeMasonry(getElement(), createMasonryProperties(columnWidth).getJavaScriptObject());
msnry = initializeMasonry(getElement(), createMasonryProperties(columnWidth, gutter, transitionDuration).getJavaScriptObject());
}

public void setVisible(boolean visible) {
Expand Down Expand Up @@ -136,10 +136,12 @@ protected static native void nativeDestroy(JavaScriptObject msnry)
msnry.destroy();
}-*/;

protected static JSONObject createMasonryProperties(int columnWidth) {
protected static JSONObject createMasonryProperties(int columnWidth, int gutter, String transitionDuration) {
JSONObject obj = new JSONObject();
obj.put("columnWidth", new JSONNumber(columnWidth));
obj.put("itemSelector", new JSONString("." + ITEM_CLASSNAME));
obj.put("gutter", new JSONNumber(gutter));
obj.put("transitionDuration", new JSONString(transitionDuration));
return obj;
}

Expand Down