mirror of
https://github.com/pocoproject/poco.git
synced 2025-01-18 00:15:27 +01:00
fixes to layout to be pixel exact
This commit is contained in:
parent
dcc35155fc
commit
0d34d4b64f
@ -66,15 +66,15 @@ public:
|
||||
/// Emits code for the page body to the given output stream.
|
||||
|
||||
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)
|
||||
/// 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\"> </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
|
||||
|
||||
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
|
||||
};
|
||||
|
||||
|
@ -64,25 +64,15 @@ void GridLayoutRenderer::renderHead(const Renderable* pRenderable, const RenderC
|
||||
int padHorVal = pLayout->getHorizontalPadding();
|
||||
int padVertVal = pLayout->getVerticalPadding();
|
||||
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 << "\"> </p>";
|
||||
padding = pad.str();
|
||||
cols = 2 * cols - 1;
|
||||
}
|
||||
std::ostringstream layoutConfig;
|
||||
layoutConfig << "{columns:" << cols << "}";
|
||||
std::string layout("table");
|
||||
// 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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -63,21 +63,16 @@ void HorizontalLayoutRenderer::renderHead(const Renderable* pRenderable, const R
|
||||
std::ostringstream layoutConfig;
|
||||
std::size_t cols = pLayout->size();
|
||||
int padVal = pLayout->getPadding();
|
||||
std::string padding;
|
||||
|
||||
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\"> </p>";
|
||||
padding = pad.str();
|
||||
cols = 2 * cols - 1;
|
||||
}
|
||||
layoutConfig << "{columns:" << cols << "}";
|
||||
|
||||
static std::string layout("table");
|
||||
//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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -41,6 +41,7 @@
|
||||
#include "Poco/WebWidgets/VerticalLayout.h"
|
||||
#include "Poco/WebWidgets/Frame.h"
|
||||
#include "Poco/WebWidgets/Panel.h"
|
||||
#include <sstream>
|
||||
|
||||
|
||||
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);
|
||||
Renderable::ID id(0);
|
||||
@ -68,12 +69,12 @@ void LayoutRenderer::renderLayoutHead(const Layout* pLayout, const RenderContext
|
||||
// the parent is not a panel
|
||||
// assume that the direct parent is a panel
|
||||
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 << "})";
|
||||
}
|
||||
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);
|
||||
bool writeComma = false;
|
||||
@ -107,29 +108,67 @@ void LayoutRenderer::renderParameters(const Layout* pLayout, const RenderContext
|
||||
ostr << ",items:[";
|
||||
else
|
||||
ostr << "items:[";
|
||||
visitChildren(pLayout, cols, htmlPadding, context, ostr);
|
||||
visitChildren(pLayout, cols, horPad, vertPad, context, 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();
|
||||
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\"> </p>"; // -4 fixes size of
|
||||
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)
|
||||
{
|
||||
if (it != pLayout->begin())
|
||||
{
|
||||
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 << "html:'" << htmlPadding << "'}),";
|
||||
ostr << "html:'" << padHor << "'}),";
|
||||
++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)
|
||||
{
|
||||
|
@ -65,16 +65,11 @@ void VerticalLayoutRenderer::renderHead(const Renderable* pRenderable, const Ren
|
||||
std::string padding;
|
||||
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\"> </p>";
|
||||
padding = pad.str();
|
||||
}
|
||||
// a vertical layout is a table with one column
|
||||
std::string layoutConfig("{columns:1}");
|
||||
std::string layout("table");
|
||||
LayoutRenderer::renderLayoutHead(pLayout, context, ostr, layout, layoutConfig, 1, padding);
|
||||
LayoutRenderer::renderLayoutHead(pLayout, context, ostr, layout, layoutConfig, 1, 0, padVal);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1472,7 +1472,7 @@ void ExtJSTest::testHorizontalLayout()
|
||||
|
||||
Page::Ptr ptr = new Page("test");
|
||||
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("b2", "But2"));
|
||||
pHor->add(new Button("b3", "But3"));
|
||||
|
Loading…
x
Reference in New Issue
Block a user