当前位置: 首页>>代码示例>>C++>>正文


C++ WWidget::setMargin方法代码示例

本文整理汇总了C++中WWidget::setMargin方法的典型用法代码示例。如果您正苦于以下问题:C++ WWidget::setMargin方法的具体用法?C++ WWidget::setMargin怎么用?C++ WWidget::setMargin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在WWidget的用法示例。


在下文中一共展示了WWidget::setMargin方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: updateDom

void WContainerWidget::updateDom(DomElement& element, bool all)
{
  if (contentAlignmentChanged_ || all) {
    switch(contentAlignment_) {
    case AlignLeft:
      if (contentAlignmentChanged_)
	element.setProperty(PropertyStyleTextAlign, "left");
      break;
    case AlignRight:
      element.setProperty(PropertyStyleTextAlign, "right");
      break;
    case AlignCenter:
      element.setProperty(PropertyStyleTextAlign, "center");
      break;
    case AlignJustify:
      element.setProperty(PropertyStyleTextAlign, "justify");
    }

    /*
     * Welcome to CSS hell.
     *
     * Apparently, the text-align property only applies to inline elements.
     * To center non-inline children, the standard says to set its left and
     * right margin to 'auto'.
     *
     * I assume the same applies for aligning to the right ?
     */
    for (unsigned i = 0; i < children().size(); ++i) {
      WWidget *child = children()[i];

      if (!child->isInline()) {
	if (contentAlignment_ == AlignCenter) {
	  if (!child->margin(Left).isAuto())
	    child->setMargin(WLength(), Left);
	  if (!child->margin(Right).isAuto())
	    child->setMargin(WLength(), Right);
	}
	if (contentAlignment_ == AlignRight) {
	  if (!child->margin(Left).isAuto())
	    child->setMargin(WLength(), Left);
	}
      }
    }

    contentAlignmentChanged_ = false;
  }

  if (paddingsChanged_ || all) {
    if (paddingsChanged_
	|| !padding_[0].isAuto()
	|| !padding_[1].isAuto()
	|| !padding_[2].isAuto()
	|| !padding_[3].isAuto()) {
      if ((padding_[0] == padding_[1])
	  && (padding_[0] == padding_[2])
	  && (padding_[0] == padding_[3]))
	element.setProperty(PropertyStylePadding,
			    padding_[0].cssText());
      else
	element.setProperty(PropertyStylePadding,
			    padding_[0].cssText()
			    + " " + padding_[1].cssText()
			    + " " + padding_[2].cssText()
			    + " " + padding_[3].cssText());
    }

    paddingsChanged_ = false;
  }

  WInteractWidget::updateDom(element, all);

  bool wasEmpty 
    = (((addedChildren_ ? addedChildren_->size() : 0) == children_->size())
       && (otherImpl_ ? (otherImpl_->scriptFunctions_
			? otherImpl_->scriptFunctions_->empty() : true)
	   : true));
  element.setWasEmpty(wasEmpty);

  if (addedChildren_) {
    for (unsigned i = 0; i < addedChildren_->size(); ++i) {
      DomElement *c = (*addedChildren_)[i]->webWidget()->createSDomElement();
      element.addChild(c);
    }

    delete addedChildren_;
    addedChildren_ = 0;
  }
}
开发者ID:,项目名称:,代码行数:88,代码来源:

示例2: updateDom

void WContainerWidget::updateDom(DomElement& element, bool all)
{
  if (all && element.type() == DomElement_LI && isInline())
    element.setProperty(PropertyStyleDisplay, "inline");

  if (flags_.test(BIT_CONTENT_ALIGNMENT_CHANGED) || all) {
    AlignmentFlag hAlign = contentAlignment_ & AlignHorizontalMask;

    bool ltr = WApplication::instance()->layoutDirection() == LeftToRight;

    switch (hAlign) {
    case AlignLeft:
      if (flags_.test(BIT_CONTENT_ALIGNMENT_CHANGED))
	element.setProperty(PropertyStyleTextAlign, ltr ? "left" : "right");
      break;
    case AlignRight:
      element.setProperty(PropertyStyleTextAlign, ltr ? "right" : "left");
      break;
    case AlignCenter:
      element.setProperty(PropertyStyleTextAlign, "center");
      break;
    case AlignJustify:
#ifndef WT_NO_LAYOUT
      if (!layout_)
#endif // WT_NO_LAYOUT
	element.setProperty(PropertyStyleTextAlign, "justify");
      break;
    default:
      break;
    }

    if (domElementType() == DomElement_TD) {
      AlignmentFlag vAlign = contentAlignment_ & AlignVerticalMask;
      switch (vAlign) {
      case AlignTop:
	if (flags_.test(BIT_CONTENT_ALIGNMENT_CHANGED))
	  element.setProperty(PropertyStyleVerticalAlign, "top");
	break;
      case AlignMiddle:
	element.setProperty(PropertyStyleVerticalAlign, "middle");
	break;
      case AlignBottom:
	element.setProperty(PropertyStyleVerticalAlign, "bottom");
      default:
	break;
      }
    }
  }

  if (flags_.test(BIT_ADJUST_CHILDREN_ALIGN)
      || flags_.test(BIT_CONTENT_ALIGNMENT_CHANGED) || all) {
    /*
     * Welcome to CSS hell.
     *
     * Apparently, the text-align property only applies to inline elements.
     * To center non-inline children, the standard says to set its left and
     * right margin to 'auto'.
     *
     * I assume the same applies for aligning to the right ?
     */
    for (unsigned i = 0; i < children_->size(); ++i) {
      WWidget *child = (*children_)[i];

      if (!child->isInline()) {
	AlignmentFlag ha = contentAlignment_ & AlignHorizontalMask;
	if (ha == AlignCenter) {
	  if (!child->margin(Left).isAuto())
	    child->setMargin(WLength::Auto, Left);
	  if (!child->margin(Right).isAuto())
	    child->setMargin(WLength::Auto, Right);
	} else if (ha == AlignRight) {
	  if (!child->margin(Left).isAuto())
	    child->setMargin(WLength::Auto, Left);
	}
      }
    }

    flags_.reset(BIT_CONTENT_ALIGNMENT_CHANGED);
    flags_.reset(BIT_ADJUST_CHILDREN_ALIGN);
  }

  if (flags_.test(BIT_PADDINGS_CHANGED)
      || (all && padding_ &&
	  !(   padding_[0].isAuto() && padding_[1].isAuto()
	    && padding_[2].isAuto() && padding_[3].isAuto()))) {

    if ((padding_[0] == padding_[1])
	&& (padding_[0] == padding_[2])
	&& (padding_[0] == padding_[3]))
      element.setProperty(PropertyStylePadding,
			  padding_[0].cssText());
    else
      element.setProperty(PropertyStylePadding,
			  padding_[0].cssText()
			  + " " + padding_[1].cssText()
			  + " " + padding_[2].cssText()
			  + " " + padding_[3].cssText());

    flags_.reset(BIT_PADDINGS_CHANGED);
  }
//.........这里部分代码省略.........
开发者ID:StevenFarley,项目名称:wt,代码行数:101,代码来源:WContainerWidget.C


注:本文中的WWidget::setMargin方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。