fixes to layout to be pixel exact

This commit is contained in:
Peter Schojer
2008-07-01 09:37:42 +00:00
parent dcc35155fc
commit 0d34d4b64f
6 changed files with 58 additions and 39 deletions

View File

@@ -66,15 +66,15 @@ public:
/// Emits code for the page body to the given output stream. /// Emits code for the page body to the given output stream.
protected: protected:
void renderLayoutHead(const Layout* pLayout, const RenderContext& context, std::ostream& ostr, const std::string& layoutId, const std::string& layoutConfig, int cols, const std::string& htmlPadding); void renderLayoutHead(const Layout* pLayout, const RenderContext& context, std::ostream& ostr, const std::string& layoutId, const std::string& layoutConfig, int cols, int horPad, int vertPad);
/// layoutId contains the id for the layout parameter (e.g. table for GridLayoutRenderer) /// layoutId contains the id for the layout parameter (e.g. table for GridLayoutRenderer)
/// layoutConfig contains the string for the layoutConfig parameter (e.g. {columns:3}) /// layoutConfig contains the string for the layoutConfig parameter (e.g. {columns:3})
/// htmlPadding contains the optional padding string to use, e.g.:'<p class=\"lbl\" style=\"padding-left:10px\">&nbsp;</p>' /// htmlPadding contains the optional padding string to use, e.g.:'<p class=\"lbl\" style=\"padding-left:10px\">&nbsp;</p>'
void renderParameters(const Layout* pLayout, const RenderContext& context, std::ostream& ostr, const std::string& layoutId, const std::string& layoutConfig, int cols, const std::string& htmlPadding); void renderParameters(const Layout* pLayout, const RenderContext& context, std::ostream& ostr, const std::string& layoutId, const std::string& layoutConfig, int cols, int horPad, int vertPad);
/// Render the config parameters /// Render the config parameters
void visitChildren(const Layout* pLayout, int cols, const std::string& htmlPadding, const RenderContext& context, std::ostream& ostr); void visitChildren(const Layout* pLayout, int cols, int horPad, int vertPad, const RenderContext& context, std::ostream& ostr);
/// Visits children /// Visits children
}; };

View File

@@ -64,25 +64,15 @@ void GridLayoutRenderer::renderHead(const Renderable* pRenderable, const RenderC
int padHorVal = pLayout->getHorizontalPadding(); int padHorVal = pLayout->getHorizontalPadding();
int padVertVal = pLayout->getVerticalPadding(); int padVertVal = pLayout->getVerticalPadding();
std::string padding; std::string padding;
if (padHorVal > 0 || padVertVal > 0) if (padHorVal > 0)
{ {
std::ostringstream pad;
// or style=\"background:#deecfd;padding-left:10px\"
// or transparent gif: <img src=\"resources/images/default/s.gif\" width=\"10\" height=\"1\" alt=\"\">'
pad << "<p style=\"";
if (padHorVal > 0)
pad << "padding-left:" << padHorVal << "px; ";
if (padVertVal > 0)
pad << "padding-top:" << padVertVal << "px ";
pad << "\">&nbsp;</p>";
padding = pad.str();
cols = 2 * cols - 1; cols = 2 * cols - 1;
} }
std::ostringstream layoutConfig; std::ostringstream layoutConfig;
layoutConfig << "{columns:" << cols << "}"; layoutConfig << "{columns:" << cols << "}";
std::string layout("table"); std::string layout("table");
// when padding is used we can no longer use LayoutRenderer // when padding is used we can no longer use LayoutRenderer
LayoutRenderer::renderLayoutHead(pLayout, context, ostr, layout, layoutConfig.str(), (int)cols, padding); LayoutRenderer::renderLayoutHead(pLayout, context, ostr, layout, layoutConfig.str(), (int)cols, padHorVal, padVertVal);
} }

View File

@@ -63,21 +63,16 @@ void HorizontalLayoutRenderer::renderHead(const Renderable* pRenderable, const R
std::ostringstream layoutConfig; std::ostringstream layoutConfig;
std::size_t cols = pLayout->size(); std::size_t cols = pLayout->size();
int padVal = pLayout->getPadding(); int padVal = pLayout->getPadding();
std::string padding;
if (padVal > 0) if (padVal > 0)
{ {
std::ostringstream pad;
// or style=\"background:#deecfd;padding-left:10px\"
// or transparent gif: <img src=\"resources/images/default/s.gif\" width=\"10\" height=\"1\" alt=\"\">'
pad << "<p style=\"padding-left:" << padVal << "px\">&nbsp;</p>";
padding = pad.str();
cols = 2 * cols - 1; cols = 2 * cols - 1;
} }
layoutConfig << "{columns:" << cols << "}"; layoutConfig << "{columns:" << cols << "}";
static std::string layout("table"); static std::string layout("table");
//static std::string layout("column"); -> this works with firefox but fails with IE7! //static std::string layout("column"); -> this works with firefox but fails with IE7!
LayoutRenderer::renderLayoutHead(pLayout, context, ostr, layout, layoutConfig.str(), (int)cols, padding); LayoutRenderer::renderLayoutHead(pLayout, context, ostr, layout, layoutConfig.str(), (int)cols, padVal, 0);
} }

View File

@@ -41,6 +41,7 @@
#include "Poco/WebWidgets/VerticalLayout.h" #include "Poco/WebWidgets/VerticalLayout.h"
#include "Poco/WebWidgets/Frame.h" #include "Poco/WebWidgets/Frame.h"
#include "Poco/WebWidgets/Panel.h" #include "Poco/WebWidgets/Panel.h"
#include <sstream>
namespace Poco { namespace Poco {
@@ -58,7 +59,7 @@ LayoutRenderer::~LayoutRenderer()
} }
void LayoutRenderer::renderLayoutHead(const Layout* pLayout, const RenderContext& context, std::ostream& ostr, const std::string& layoutId, const std::string& layoutConfig, int cols, const std::string& htmlPadding) void LayoutRenderer::renderLayoutHead(const Layout* pLayout, const RenderContext& context, std::ostream& ostr, const std::string& layoutId, const std::string& layoutConfig, int cols, int horPad, int vertPad)
{ {
poco_assert_dbg(pLayout != 0); poco_assert_dbg(pLayout != 0);
Renderable::ID id(0); Renderable::ID id(0);
@@ -68,12 +69,12 @@ void LayoutRenderer::renderLayoutHead(const Layout* pLayout, const RenderContext
// the parent is not a panel // the parent is not a panel
// assume that the direct parent is a panel // assume that the direct parent is a panel
ostr << "new Ext.Panel({border:false,bodyBorder:false,"; ostr << "new Ext.Panel({border:false,bodyBorder:false,";
renderParameters(pLayout, context, ostr, layoutId, layoutConfig, cols, htmlPadding); renderParameters(pLayout, context, ostr, layoutId, layoutConfig, cols, horPad, vertPad);
ostr << "})"; ostr << "})";
} }
else else
{ {
renderParameters(pLayout, context, ostr, layoutId, layoutConfig, cols, htmlPadding); renderParameters(pLayout, context, ostr, layoutId, layoutConfig, cols, horPad, vertPad);
} }
} }
@@ -84,7 +85,7 @@ void LayoutRenderer::renderBody(const Renderable* pRenderable, const RenderConte
} }
void LayoutRenderer::renderParameters(const Layout* pLayout, const RenderContext& context, std::ostream& ostr, const std::string& layoutId, const std::string& layoutConfig, int cols, const std::string& htmlPadding) void LayoutRenderer::renderParameters(const Layout* pLayout, const RenderContext& context, std::ostream& ostr, const std::string& layoutId, const std::string& layoutConfig, int cols, int horPad, int vertPad)
{ {
poco_assert_dbg(pLayout != 0); poco_assert_dbg(pLayout != 0);
bool writeComma = false; bool writeComma = false;
@@ -107,29 +108,67 @@ void LayoutRenderer::renderParameters(const Layout* pLayout, const RenderContext
ostr << ",items:["; ostr << ",items:[";
else else
ostr << "items:["; ostr << "items:[";
visitChildren(pLayout, cols, htmlPadding, context, ostr); visitChildren(pLayout, cols, horPad, vertPad, context, ostr);
ostr << "]"; ostr << "]";
} }
void LayoutRenderer::visitChildren(const Layout* pLayout, int cols, const std::string& htmlPadding, const RenderContext& context, std::ostream& ostr) void LayoutRenderer::visitChildren(const Layout* pLayout, int cols, int horPad, int vertPad, const RenderContext& context, std::ostream& ostr)
{ {
ContainerView::ConstIterator it = pLayout->begin(); ContainerView::ConstIterator it = pLayout->begin();
int cnt(0); int cnt(0);
const VerticalLayout* pVert = dynamic_cast<const VerticalLayout*>(pLayout); std::string padHor;
if (horPad > 0)
{
std::ostringstream pad;
pad << "<p class=\"lbl\" style=\"margin-left:" << (horPad-4) << "px\">&nbsp;</p>"; // -4 fixes size of &nbsp;
padHor = pad.str();
}
std::string padVert;
if (vertPad > 0)
{
std::ostringstream pad;
pad << "<p style=\"margin-top:" << vertPad << "px\"></p>";
padVert = pad.str();
}
for (; it != pLayout->end(); ++it, ++cnt) for (; it != pLayout->end(); ++it, ++cnt)
{ {
if (it != pLayout->begin()) if (it != pLayout->begin())
{ {
ostr << ","; ostr << ",";
if (!htmlPadding.empty() && (cnt % cols != 0 || pVert)) if (cnt < cols && !padHor.empty())
{ {
// if padding, insert an additional empty html element that defines padding
ostr << "new Ext.Panel({border:false,bodyBorder:false,"; ostr << "new Ext.Panel({border:false,bodyBorder:false,";
ostr << "html:'" << htmlPadding << "'}),"; ostr << "html:'" << padHor << "'}),";
++cnt; ++cnt;
} }
else
{
if (cnt >= cols)
{
if (cnt % cols == 0) //first row
{
if (!padVert.empty())
{
//insert a complete line!
for (int i= 0; i < cols; ++i)
{
ostr << "new Ext.Panel({border:false,bodyBorder:false,";
ostr << "html:'" << padVert << "'}),";
}
} // else no hor padding for first row!
}
else if (!padHor.empty())
{
ostr << "new Ext.Panel({border:false,bodyBorder:false,";
ostr << "html:'" << padHor << "'}),";
++cnt;
}
}
}
} }
if (*it) if (*it)
{ {

View File

@@ -65,16 +65,11 @@ void VerticalLayoutRenderer::renderHead(const Renderable* pRenderable, const Ren
std::string padding; std::string padding;
if (padVal > 0) if (padVal > 0)
{ {
std::ostringstream pad;
// or style=\"background:#deecfd;padding-left:10px\"
// or transparent gif: <img src=\"resources/images/default/s.gif\" width=\"10\" height=\"1\" alt=\"\">'
pad << "<p style=\"padding-top:" << padVal << "px\">&nbsp;</p>";
padding = pad.str();
} }
// a vertical layout is a table with one column // a vertical layout is a table with one column
std::string layoutConfig("{columns:1}"); std::string layoutConfig("{columns:1}");
std::string layout("table"); std::string layout("table");
LayoutRenderer::renderLayoutHead(pLayout, context, ostr, layout, layoutConfig, 1, padding); LayoutRenderer::renderLayoutHead(pLayout, context, ostr, layout, layoutConfig, 1, 0, padVal);
} }

View File

@@ -1472,7 +1472,7 @@ void ExtJSTest::testHorizontalLayout()
Page::Ptr ptr = new Page("test"); Page::Ptr ptr = new Page("test");
webApp.setCurrentPage(ptr); webApp.setCurrentPage(ptr);
HorizontalLayout::Ptr pHor(new HorizontalLayout(10)); HorizontalLayout::Ptr pHor(new HorizontalLayout(1));
pHor->add(new Button("b1", "But1")); pHor->add(new Button("b1", "But1"));
pHor->add(new Button("b2", "But2")); pHor->add(new Button("b2", "But2"));
pHor->add(new Button("b3", "But3")); pHor->add(new Button("b3", "But3"));