예제 #1
0
void PopupWindow::onPreferredSize(PreferredSizeEvent& ev)
{
    ScreenGraphics g;
    g.setFont(getFont());
    Size resultSize(0, 0);

    if (hasText())
        resultSize = g.fitString(getText(),
                                 (getClientBounds() - getBorder()).w,
                                 getAlign());

    resultSize.w += border_width.l + border_width.r;
    resultSize.h += border_width.t + border_width.b;

    if (!getChildren().empty()) {
        Size maxSize(0, 0);
        Size reqSize;

        UI_FOREACH_WIDGET(getChildren(), it) {
            Widget* child = *it;

            reqSize = child->getPreferredSize();

            maxSize.w = MAX(maxSize.w, reqSize.w);
            maxSize.h = MAX(maxSize.h, reqSize.h);
        }
예제 #2
0
void PopupWindow::onSizeHint(SizeHintEvent& ev)
{
  ScreenGraphics g;
  g.setFont(font());
  Size resultSize(0, 0);

  if (hasText())
    resultSize = g.fitString(text(),
                             (clientBounds() - border()).w,
                             align());

  resultSize.w += border().width();
  resultSize.h += border().height();

  if (!children().empty()) {
    Size maxSize(0, 0);
    Size reqSize;

    for (auto child : children()) {
      reqSize = child->sizeHint();

      maxSize.w = MAX(maxSize.w, reqSize.w);
      maxSize.h = MAX(maxSize.h, reqSize.h);
    }

    resultSize.w = MAX(resultSize.w, maxSize.w + border().width());
    resultSize.h += maxSize.h;
  }

  ev.setSizeHint(resultSize);
}
예제 #3
0
파일: ComboBox.cpp 프로젝트: dacap/vaca
void ComboBox::updateMaxItemSize(const String& text)
{
  ScreenGraphics g;
  g.setFont(getFont());
  m_maxItemSize = m_maxItemSize.createUnion(g.measureString(text));
}