Exemplo n.º 1
0
void
WidgetDialog::AutoSize()
{
  const PixelRect parent_rc = GetParentClientRect();
  const PixelSize parent_size = parent_rc.GetSize();

  widget.Prepare();
  PixelSize min_size = widget.Get()->GetMinimumSize();
  min_size.cy += GetTitleHeight();
  PixelSize max_size = widget.Get()->GetMaximumSize();
  max_size.cy += GetTitleHeight();

  const PixelScalar min_height_with_buttons =
    min_size.cy + Layout::GetMaximumControlHeight();
  const PixelScalar max_height_with_buttons =
    max_size.cy + Layout::GetMaximumControlHeight();
  if (/* need full dialog height even for minimum widget height? */
      min_height_with_buttons >= parent_size.cy ||
      /* try to avoid putting buttons left on portrait screens; try to
         comply with maximum widget height only on landscape
         screens */
      (parent_size.cx > parent_size.cy &&
       max_height_with_buttons >= parent_size.cy)) {
    /* need full height, buttons must be left */
    PixelRect rc = parent_rc;
    if (max_size.cy < parent_size.cy)
      rc.bottom = rc.top + max_size.cy;

    PixelRect remaining = buttons.LeftLayout(rc);
    PixelSize remaining_size = remaining.GetSize();
    if (remaining_size.cx > max_size.cx)
      rc.right -= remaining_size.cx - max_size.cx;

    Move(rc);
    widget.Move(buttons.LeftLayout());
    return;
  }

  /* see if buttons fit at the bottom */

  PixelRect rc = parent_rc;
  if (max_size.cx < parent_size.cx)
    rc.right = rc.left + max_size.cx;

  PixelRect remaining = buttons.BottomLayout(rc);
  PixelSize remaining_size = remaining.GetSize();

  if (remaining_size.cy > max_size.cy)
    rc.bottom -= remaining_size.cy - max_size.cy;

  Move(rc);
  widget.Move(buttons.BottomLayout());
}
Exemplo n.º 2
0
TBRect TBWindow::GetPaddingRect()
{
	TBRect padding_rect = TBWidget::GetPaddingRect();
	int title_height = GetTitleHeight();
	padding_rect.y += title_height;
	padding_rect.h -= title_height;
	return padding_rect;
}
Exemplo n.º 3
0
void TBWindow::OnResized(int old_w, int old_h)
{
	// Apply gravity on children
	TBWidget::OnResized(old_w, old_h);
	// Manually move our own decoration children
	// FIX: Put a layout in the TBMover so we can add things there nicely.
	int title_height = GetTitleHeight();
	m_mover.SetRect(TBRect(0, 0, GetRect().w, title_height));
	PreferredSize ps = m_resizer.GetPreferredSize();
	m_resizer.SetRect(TBRect(GetRect().w - ps.pref_w, GetRect().h - ps.pref_h, ps.pref_w, ps.pref_h));
	TBRect mover_rect = m_mover.GetPaddingRect();
	int button_size = mover_rect.h;
	m_close_button.SetRect(TBRect(mover_rect.x + mover_rect.w - button_size, mover_rect.y, button_size, button_size));
	if (m_settings & WINDOW_SETTINGS_CLOSE_BUTTON)
		mover_rect.w -= button_size;
	m_textfield.SetRect(mover_rect);
}
Exemplo n.º 4
0
PreferredSize TBWindow::OnCalculatePreferredSize(const SizeConstraints &constraints)
{
	PreferredSize ps = OnCalculatePreferredContentSize(constraints);

	// Add window skin padding
	if (TBSkinElement *e = GetSkinBgElement())
	{
		ps.min_w += e->padding_left + e->padding_right;
		ps.pref_w += e->padding_left + e->padding_right;
		ps.min_h += e->padding_top + e->padding_bottom;
		ps.pref_h += e->padding_top + e->padding_bottom;
	}
	// Add window title bar height
	int title_height = GetTitleHeight();
	ps.min_h += title_height;
	ps.pref_h += title_height;
	return ps;
}
Exemplo n.º 5
0
/** Compute the size of a dialog window. */
void ComputeDimensions(const ClientNode *np)
{

   const ScreenType *sp;
   int width;
   int x;

   Assert(dialog);

   /* Get the min width from the size of the buttons. */
   if(!minWidth) {
      minWidth = GetStringWidth(FONT_MENU, GetCancelString()) * 3;
      width = GetStringWidth(FONT_MENU, GetOKString()) * 3;
      if(width > minWidth) {
         minWidth = width;
      }
      minWidth += 16 * 3;
   }
   dialog->width = minWidth;

   /* Take into account the size of the message. */
   for(x = 0; x < dialog->lineCount; x++) {
      width = GetStringWidth(FONT_MENU, dialog->message[x]);
      if(width > dialog->width) {
         dialog->width = width;
      }
   }
   dialog->lineHeight = GetStringHeight(FONT_MENU);
   dialog->width += 8;
   dialog->height = (dialog->lineCount + 2) * dialog->lineHeight;

   if(np) {

      dialog->x = np->x + (np->width - dialog->width) / 2;
      dialog->y = np->y + (np->height - dialog->height) / 2;

      if(dialog->x < 0) {
         dialog->x = 0;
      }
      if(dialog->y < 0) {
         dialog->y = 0;
      }
      if(dialog->x + dialog->width >= rootWidth) {
         dialog->x = rootWidth - dialog->width - (settings.borderWidth * 2);
      }
      if(dialog->y + dialog->height >= rootHeight) {
         const unsigned titleHeight = GetTitleHeight();
         dialog->y = rootHeight - dialog->height
               - (settings.borderWidth * 2 + titleHeight);
      }

   } else {

      sp = GetMouseScreen();

      dialog->x = (sp->width - dialog->width) / 2 + sp->x;
      dialog->y = (sp->height - dialog->height) / 2 + sp->y;

   }

}