mirror of
https://github.com/pocoproject/poco.git
synced 2025-05-08 18:02:01 +02:00
performance enhancements for layouts
This commit is contained in:
parent
b8489e9df1
commit
737331da3a
@ -45,6 +45,7 @@
|
|||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
namespace WebWidgets {
|
namespace WebWidgets {
|
||||||
|
class GridLayout;
|
||||||
namespace ExtJS {
|
namespace ExtJS {
|
||||||
|
|
||||||
|
|
||||||
@ -60,6 +61,8 @@ public:
|
|||||||
|
|
||||||
void renderHead(const Renderable* pRenderable, const RenderContext& context, std::ostream& ostr);
|
void renderHead(const Renderable* pRenderable, const RenderContext& context, std::ostream& ostr);
|
||||||
/// Emits code for the page header to the given output stream.
|
/// Emits code for the page header to the given output stream.
|
||||||
|
|
||||||
|
void renderParameters(const GridLayout* pLayout, const RenderContext& context, std::ostream& ostr);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -45,6 +45,7 @@
|
|||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
namespace WebWidgets {
|
namespace WebWidgets {
|
||||||
|
class HorizontalLayout;
|
||||||
namespace ExtJS {
|
namespace ExtJS {
|
||||||
|
|
||||||
|
|
||||||
@ -60,6 +61,8 @@ public:
|
|||||||
|
|
||||||
void renderHead(const Renderable* pRenderable, const RenderContext& context, std::ostream& ostr);
|
void renderHead(const Renderable* pRenderable, const RenderContext& context, std::ostream& ostr);
|
||||||
/// Emits code for the page header to the given output stream.
|
/// Emits code for the page header to the given output stream.
|
||||||
|
|
||||||
|
void renderParameters(const HorizontalLayout* pLayout, const RenderContext& context, std::ostream& ostr);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -66,16 +66,9 @@ 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, int horPad, int vertPad);
|
void renderLayout(const Layout* pLayout, const RenderContext& context, std::ostream& ostr, std::size_t cols, int padHorVal, int padVertVal);
|
||||||
/// 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, int horPad, int vertPad);
|
void renderParameters(const Layout* pLayout, const RenderContext& context, std::ostream& ostr, std::size_t cols, int padHorVal, int padVertVal);
|
||||||
/// Render the config parameters
|
|
||||||
|
|
||||||
void visitChildren(const Layout* pLayout, int cols, int horPad, int vertPad, const RenderContext& context, std::ostream& ostr);
|
|
||||||
/// Visits children
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -37,6 +37,8 @@
|
|||||||
#include "Poco/WebWidgets/ExtJS/GridLayoutRenderer.h"
|
#include "Poco/WebWidgets/ExtJS/GridLayoutRenderer.h"
|
||||||
#include "Poco/WebWidgets/ExtJS/Utility.h"
|
#include "Poco/WebWidgets/ExtJS/Utility.h"
|
||||||
#include "Poco/WebWidgets/GridLayout.h"
|
#include "Poco/WebWidgets/GridLayout.h"
|
||||||
|
#include "Poco/WebWidgets/Frame.h"
|
||||||
|
#include "Poco/WebWidgets/Panel.h"
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
|
|
||||||
@ -60,19 +62,8 @@ void GridLayoutRenderer::renderHead(const Renderable* pRenderable, const RenderC
|
|||||||
poco_assert_dbg (pRenderable != 0);
|
poco_assert_dbg (pRenderable != 0);
|
||||||
poco_assert_dbg (pRenderable->type() == typeid(Poco::WebWidgets::GridLayout));
|
poco_assert_dbg (pRenderable->type() == typeid(Poco::WebWidgets::GridLayout));
|
||||||
const GridLayout* pLayout = static_cast<const Poco::WebWidgets::GridLayout*>(pRenderable);
|
const GridLayout* pLayout = static_cast<const Poco::WebWidgets::GridLayout*>(pRenderable);
|
||||||
std::size_t cols = pLayout->columns();
|
|
||||||
int padHorVal = pLayout->getHorizontalPadding();
|
renderLayout(pLayout, context, ostr, pLayout->columns(), pLayout->getHorizontalPadding(), pLayout->getVerticalPadding());
|
||||||
int padVertVal = pLayout->getVerticalPadding();
|
|
||||||
std::string padding;
|
|
||||||
if (padHorVal > 0)
|
|
||||||
{
|
|
||||||
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, padHorVal, padVertVal);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -60,19 +60,8 @@ void HorizontalLayoutRenderer::renderHead(const Renderable* pRenderable, const R
|
|||||||
poco_assert_dbg (pRenderable != 0);
|
poco_assert_dbg (pRenderable != 0);
|
||||||
poco_assert_dbg (pRenderable->type() == typeid(Poco::WebWidgets::HorizontalLayout));
|
poco_assert_dbg (pRenderable->type() == typeid(Poco::WebWidgets::HorizontalLayout));
|
||||||
const HorizontalLayout* pLayout = static_cast<const Poco::WebWidgets::HorizontalLayout*>(pRenderable);
|
const HorizontalLayout* pLayout = static_cast<const Poco::WebWidgets::HorizontalLayout*>(pRenderable);
|
||||||
std::ostringstream layoutConfig;
|
|
||||||
std::size_t cols = pLayout->size();
|
|
||||||
int padVal = pLayout->getPadding();
|
|
||||||
|
|
||||||
if (padVal > 0)
|
|
||||||
{
|
|
||||||
cols = 2 * cols - 1;
|
|
||||||
}
|
|
||||||
layoutConfig << "{columns:" << cols << "}";
|
|
||||||
|
|
||||||
static std::string layout("table");
|
renderLayout(pLayout, context, ostr, pLayout->size(), pLayout->getPadding(), 0);
|
||||||
//static std::string layout("column"); -> this works with firefox but fails with IE7!
|
|
||||||
LayoutRenderer::renderLayoutHead(pLayout, context, ostr, layout, layoutConfig.str(), (int)cols, padVal, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -59,30 +59,6 @@ LayoutRenderer::~LayoutRenderer()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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);
|
|
||||||
View::Ptr ptrParent = pLayout->parent();
|
|
||||||
if (!(ptrParent && (ptrParent.cast<Frame>() || ptrParent.cast<Panel>())))
|
|
||||||
{
|
|
||||||
// the parent is not a panel
|
|
||||||
// assume that the direct parent is a panel
|
|
||||||
ostr << "new Ext.Panel({border:false,bodyBorder:false,";
|
|
||||||
ostr << "id:'" << pLayout->id() << "',";
|
|
||||||
if (!pLayout->isVisible())
|
|
||||||
ostr << "hidden:true,";
|
|
||||||
renderParameters(pLayout, context, ostr, layoutId, layoutConfig, cols, horPad, vertPad);
|
|
||||||
ostr << "})";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
renderParameters(pLayout, context, ostr, layoutId, layoutConfig, cols, horPad, vertPad);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void LayoutRenderer::renderBody(const Renderable* pRenderable, const RenderContext& context, std::ostream& ostr)
|
void LayoutRenderer::renderBody(const Renderable* pRenderable, const RenderContext& context, std::ostream& ostr)
|
||||||
{
|
{
|
||||||
const Layout* pLayout = static_cast<const Layout*>(pRenderable);
|
const Layout* pLayout = static_cast<const Layout*>(pRenderable);
|
||||||
@ -95,92 +71,64 @@ 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, int horPad, int vertPad)
|
void LayoutRenderer::renderLayout(const Layout* pLayout, const RenderContext& context, std::ostream& ostr, std::size_t cols, int padHorVal, int padVertVal)
|
||||||
{
|
{
|
||||||
poco_assert_dbg(pLayout != 0);
|
poco_assert_dbg (pLayout != 0);
|
||||||
bool writeComma = false;
|
|
||||||
if (pLayout->getWidth() > 0)
|
Renderable::ID id(0);
|
||||||
ostr << "width:" << pLayout->getWidth() << ",";
|
View::Ptr ptrParent = pLayout->parent();
|
||||||
if (!layoutId.empty())
|
bool parentIsNotPanel = !(ptrParent && (ptrParent.cast<Frame>() || ptrParent.cast<Panel>()));
|
||||||
|
if (parentIsNotPanel)
|
||||||
{
|
{
|
||||||
ostr << "layout:'" << layoutId << "'";
|
// the parent is not a panel
|
||||||
writeComma = true;
|
// assume that the direct parent is a panel
|
||||||
|
ostr << "new Ext.Panel({border:false,bodyBorder:false,";
|
||||||
|
ostr << "id:'" << pLayout->id() << "',";
|
||||||
|
if (!pLayout->isVisible())
|
||||||
|
ostr << "hidden:true,";
|
||||||
}
|
}
|
||||||
if (!layoutConfig.empty())
|
|
||||||
{
|
renderParameters(pLayout, context, ostr, cols, padHorVal, padVertVal);
|
||||||
if (writeComma)
|
|
||||||
ostr << ",layoutConfig:" << layoutConfig;
|
if (parentIsNotPanel)
|
||||||
else
|
ostr << "})";
|
||||||
ostr << ",layoutConfig:" << layoutConfig;
|
|
||||||
writeComma = true;
|
|
||||||
}
|
|
||||||
if (writeComma)
|
|
||||||
ostr << ",items:[";
|
|
||||||
else
|
|
||||||
ostr << "items:[";
|
|
||||||
visitChildren(pLayout, cols, horPad, vertPad, context, ostr);
|
|
||||||
ostr << "]";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void LayoutRenderer::visitChildren(const Layout* pLayout, int cols, int horPad, int vertPad, const RenderContext& context, std::ostream& ostr)
|
void LayoutRenderer::renderParameters(const Layout* pLayout, const RenderContext& context, std::ostream& ostr, std::size_t cols, int padHorVal, int padVertVal)
|
||||||
{
|
{
|
||||||
std::string padHor;
|
poco_assert_dbg(pLayout != 0);
|
||||||
|
if (padHorVal < 0)
|
||||||
|
padHorVal = 0;
|
||||||
|
if (padVertVal < 0)
|
||||||
|
padVertVal = 0;
|
||||||
|
|
||||||
|
if (pLayout->getWidth() > 0)
|
||||||
|
ostr << "width:" << pLayout->getWidth() << ",";
|
||||||
|
|
||||||
if (horPad > 0)
|
ostr << "layout:'table'";
|
||||||
|
ostr << ",layoutConfig:" << "{columns:" << cols << "}";
|
||||||
|
|
||||||
|
if (padHorVal > 0 || padVertVal > 0)
|
||||||
{
|
{
|
||||||
std::ostringstream pad;
|
ostr << ",defaults:{";
|
||||||
pad << "<p class=\"lbl\" style=\"margin-left:" << (horPad-4) << "px\"> </p>"; // -4 fixes size of
|
ostr << "bodyStyle:'";
|
||||||
padHor = pad.str();
|
ostr << "padding:" << padVertVal << "px " << padHorVal << "px";
|
||||||
|
ostr << "'";
|
||||||
|
ostr << "}";
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string padVert;
|
ostr << ",items:[";
|
||||||
if (vertPad > 0)
|
|
||||||
{
|
|
||||||
std::ostringstream pad;
|
|
||||||
pad << "<p style=\"margin-top:" << vertPad << "px\"></p>";
|
|
||||||
padVert = pad.str();
|
|
||||||
}
|
|
||||||
ContainerView::ConstIterator it = pLayout->begin();
|
ContainerView::ConstIterator it = pLayout->begin();
|
||||||
int cnt(0);
|
int cnt(0);
|
||||||
for (; it != pLayout->end(); ++it, ++cnt)
|
for (; it != pLayout->end(); ++it)
|
||||||
{
|
{
|
||||||
if (cnt > 0)
|
if (it != pLayout->begin())
|
||||||
{
|
|
||||||
ostr << ",";
|
ostr << ",";
|
||||||
if (cnt < cols && !padHor.empty())
|
|
||||||
{
|
|
||||||
ostr << "new Ext.Panel({border:false,bodyBorder:false,";
|
|
||||||
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)
|
if (*it)
|
||||||
{
|
{
|
||||||
|
|
||||||
//horizontallayout works only when children are panels
|
//horizontallayout works only when children are panels
|
||||||
ostr << "new Ext.Panel({border:false,bodyBorder:false,items:[";
|
ostr << "new Ext.Panel({border:false,bodyBorder:false,items:[";
|
||||||
(*it)->renderHead(context, ostr);
|
(*it)->renderHead(context, ostr);
|
||||||
@ -188,9 +136,8 @@ void LayoutRenderer::visitChildren(const Layout* pLayout, int cols, int horPad,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
ostr << "{}";
|
ostr << "{}";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
ostr << "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} } } // namespace Poco::WebWidgets::ExtJS
|
} } } // namespace Poco::WebWidgets::ExtJS
|
||||||
|
@ -61,15 +61,7 @@ void VerticalLayoutRenderer::renderHead(const Renderable* pRenderable, const Ren
|
|||||||
poco_assert_dbg (pRenderable->type() == typeid(Poco::WebWidgets::VerticalLayout));
|
poco_assert_dbg (pRenderable->type() == typeid(Poco::WebWidgets::VerticalLayout));
|
||||||
const VerticalLayout* pLayout = static_cast<const Poco::WebWidgets::VerticalLayout*>(pRenderable);
|
const VerticalLayout* pLayout = static_cast<const Poco::WebWidgets::VerticalLayout*>(pRenderable);
|
||||||
|
|
||||||
int padVal = pLayout->getPadding();
|
renderLayout(pLayout, context, ostr, 1, 0, pLayout->getPadding());
|
||||||
std::string padding;
|
|
||||||
if (padVal > 0)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
// 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, 0, padVal);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user