Browse Source

Fix for #2231 - Allow border and padding for Labels

svn changeset:6023/svn branch:trunk
tags/6.7.0.beta1
Artur Signell 15 years ago
parent
commit
208c5c570b

+ 8
- 0
WebContent/ITMILL/themes/tests-tickets/styles.css View File

@@ -229,6 +229,14 @@
padding-left: 20px;
}

.ticket2231 {
margin: 50px;
}

.ticket2231-border {
border: 2em solid red;
}

/*****************************************************************************/
/* Ticket 2232 */
/*****************************************************************************/

+ 94
- 6
src/com/itmill/toolkit/terminal/gwt/client/Util.java View File

@@ -286,10 +286,55 @@ public class Util {
- element.getParentElement().getAbsoluteLeft();
}

public static void setWidthExcludingPadding(Element element,
int requestedWidth, int paddingGuess) {
public static int setHeightExcludingPaddingAndBorder(Widget widget,
String height, int paddingBorderGuess) {
if (height.equals("")) {
setHeight(widget, "");
return paddingBorderGuess;
} else if (height.endsWith("px")) {
int pixelHeight = Integer.parseInt(height.substring(0, height
.length() - 3));
return setHeightExcludingPaddingAndBorder(widget.getElement(),
pixelHeight, paddingBorderGuess, false);
} else {
// Set the height in unknown units
setHeight(widget, height);
// Use the offsetWidth
return setHeightExcludingPaddingAndBorder(widget.getElement(),
widget.getOffsetHeight(), paddingBorderGuess, true);
}
}

private static void setWidth(Widget widget, String width) {
DOM.setStyleAttribute(widget.getElement(), "width", width);
}

private static void setHeight(Widget widget, String height) {
DOM.setStyleAttribute(widget.getElement(), "height", height);
}

int widthGuess = requestedWidth - paddingGuess;
public static int setWidthExcludingPaddingAndBorder(Widget widget,
String width, int paddingBorderGuess) {
if (width.equals("")) {
setWidth(widget, "");
return paddingBorderGuess;
} else if (width.endsWith("px")) {
int pixelWidth = Integer.parseInt(width.substring(0,
width.length() - 2));
return setWidthExcludingPaddingAndBorder(widget.getElement(),
pixelWidth, paddingBorderGuess, false);
} else {
setWidth(widget, width);
return setWidthExcludingPaddingAndBorder(widget.getElement(),
widget.getOffsetWidth(), paddingBorderGuess, true);
}
}

public static int setWidthExcludingPaddingAndBorder(Element element,
int requestedWidth, int horizontalPaddingBorderGuess,
boolean requestedWidthIncludesPaddingBorder) {

int widthGuess = requestedWidth - horizontalPaddingBorderGuess;
if (widthGuess < 0) {
widthGuess = 0;
}
@@ -300,12 +345,55 @@ public class Util {

int actualPadding = captionOffsetWidth - widthGuess;

if (actualPadding != paddingGuess) {
DOM.setStyleAttribute(element, "width", requestedWidth
- actualPadding + "px");
if (requestedWidthIncludesPaddingBorder) {
actualPadding += actualPadding;
}

if (actualPadding != horizontalPaddingBorderGuess) {
int w = requestedWidth - actualPadding;
if (w < 0) {
// Cannot set negative width even if we would want to
w = 0;
}
DOM.setStyleAttribute(element, "width", w + "px");

}

return actualPadding;

}

public static int setHeightExcludingPaddingAndBorder(Element element,
int requestedHeight, int verticalPaddingBorderGuess,
boolean requestedHeightIncludesPaddingBorder) {

int heightGuess = requestedHeight - verticalPaddingBorderGuess;
if (heightGuess < 0) {
heightGuess = 0;
}

DOM.setStyleAttribute(element, "height", heightGuess + "px");
int captionOffsetHeight = DOM.getElementPropertyInt(element,
"offsetHeight");

int actualPadding = captionOffsetHeight - heightGuess;

if (requestedHeightIncludesPaddingBorder) {
actualPadding += actualPadding;
}

if (actualPadding != verticalPaddingBorderGuess) {
int h = requestedHeight - actualPadding;
if (h < 0) {
// Cannot set negative height even if we would want to
h = 0;
}
DOM.setStyleAttribute(element, "height", h + "px");

}

return actualPadding;

}

public static String getSimpleName(Object widget) {

+ 15
- 0
src/com/itmill/toolkit/terminal/gwt/client/ui/ILabel.java View File

@@ -10,11 +10,14 @@ import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection;
import com.itmill.toolkit.terminal.gwt.client.ITooltip;
import com.itmill.toolkit.terminal.gwt.client.Paintable;
import com.itmill.toolkit.terminal.gwt.client.UIDL;
import com.itmill.toolkit.terminal.gwt.client.Util;

public class ILabel extends HTML implements Paintable {

public static final String CLASSNAME = "i-label";
private ApplicationConnection client;
private int verticalPaddingBorder = 0;
private int horizontalPaddingBorder = 0;

public ILabel() {
super();
@@ -60,4 +63,16 @@ public class ILabel extends HTML implements Paintable {
setText("");
}
}

@Override
public void setHeight(String height) {
verticalPaddingBorder = Util.setHeightExcludingPaddingAndBorder(this,
height, verticalPaddingBorder);
}

@Override
public void setWidth(String width) {
horizontalPaddingBorder = Util.setWidthExcludingPaddingAndBorder(this,
width, horizontalPaddingBorder);
}
}

+ 7
- 6
src/com/itmill/toolkit/terminal/gwt/client/ui/IPanel.java View File

@@ -272,13 +272,14 @@ public class IPanel extends SimplePanel implements Container {
int parentWidthExcludingPadding = getElement().getOffsetWidth()
- parentPadding;

Util.setWidthExcludingPadding(captionNode,
parentWidthExcludingPadding - getCaptionMarginLeft(), 26);
Util.setWidthExcludingPaddingAndBorder(captionNode,
parentWidthExcludingPadding - getCaptionMarginLeft(), 26,
false);

int contentMarginLeft = getContentMarginLeft();

Util.setWidthExcludingPadding(contentNode,
parentWidthExcludingPadding - contentMarginLeft, 2);
Util.setWidthExcludingPaddingAndBorder(contentNode,
parentWidthExcludingPadding - contentMarginLeft, 2, false);

}

@@ -298,8 +299,8 @@ public class IPanel extends SimplePanel implements Container {
}

if (BrowserInfo.get().isIE7()) {
Util.setWidthExcludingPadding(captionNode, width
- getCaptionMarginLeft(), 26);
Util.setWidthExcludingPaddingAndBorder(captionNode, width
- getCaptionMarginLeft(), 26, false);
}

super.setWidth(width + "px");

+ 41
- 0
src/com/itmill/toolkit/tests/tickets/Ticket2231.java View File

@@ -0,0 +1,41 @@
package com.itmill.toolkit.tests.tickets;

import com.itmill.toolkit.Application;
import com.itmill.toolkit.ui.Label;
import com.itmill.toolkit.ui.OrderedLayout;
import com.itmill.toolkit.ui.Window;

public class Ticket2231 extends Application {

public void init() {
Window w = new Window(getClass().getSimpleName());
setMainWindow(w);
setTheme("tests-tickets");
createUI((OrderedLayout) w.getLayout());
}

private void createUI(OrderedLayout layout) {
layout.setSizeUndefined();
layout.setMargin(false);
layout.setStyleName("borders");
Label l = new Label("Margin-label");

l.setStyleName("ticket2231");

layout.addComponent(l);

for (int i = 0; i < 5; i++) {
l = new Label("This is a label with border");
l.setStyleName("ticket2231-border");
if (i == 2) {
l.setWidth("100%");
l.setValue("100% wide");
} else if (i == 4) {
l.setWidth("20em");
l.setValue("20em wide");
}
// l.addStyleName("ticket2231");
layout.addComponent(l);
}
}
}

Loading…
Cancel
Save