From c97cd0691badfcbe55601e9e8891642b78962a23 Mon Sep 17 00:00:00 2001 From: Jouni Koivuviita Date: Thu, 20 Sep 2007 12:35:03 +0000 Subject: [PATCH] New improved size calculations. Contained layout now attached to DOM before we try to update its contents. svn changeset:2353/svn branch:trunk --- .../terminal/gwt/client/ui/IPanel.java | 37 +++++++++++-------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/IPanel.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/IPanel.java index 3be27b2306..5e657130d4 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/IPanel.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/IPanel.java @@ -63,32 +63,37 @@ public class IPanel extends FlowPanel implements Paintable { add(caption); } - // Size panel - // TODO support for different units - String widthUnit = "px"; - String heightUnit = "px"; - int captionHeight = caption.getOffsetHeight(); - int height = uidl.hasVariable("height")? uidl.getIntVariable("height") : -1; - int w = uidl.hasVariable("width")? uidl.getIntVariable("width") : -1; - int h = -1; - if(height != -1) - h = height < captionHeight? 0 : height - captionHeight; - setWidth(w>=0?w+widthUnit:"auto"); - content.setHeight(h>=0?h+heightUnit:"auto"); - // Render content UIDL layoutUidl = uidl.getChildUIDL(0); Widget layout = client.getWidget(layoutUidl); - ((Paintable)layout).updateFromUIDL(layoutUidl, client); content.setWidget(layout); - add(content); + ((Paintable)layout).updateFromUIDL(layoutUidl, client); - // Add a decoration element for shadow + // Add a decoration element for additional styling deco = DOM.createDiv(); DOM.setElementProperty(deco, "className", CLASSNAME+"-deco"); DOM.appendChild(getElement(), deco); + // Size panel + String h = uidl.hasVariable("height")? uidl.getStringVariable("height") : null; + String w = uidl.hasVariable("width")? uidl.getStringVariable("width") : null; + + setWidth(w!=null? w : ""); + + // Try to approximate the height as close as possible + if(h!=null) { + // First, calculate needed pixel height + setHeight(h); + int neededHeight = getOffsetHeight(); + setHeight("auto"); + // Then calculate the size the content area needs to be + content.setHeight("0"); + int height = getOffsetHeight(); + content.setHeight(neededHeight-height + "px"); + } else + content.setHeight(""); + } } -- 2.39.5