Skip to content

Commit

Permalink
Fixed so Demo windows adapt better to high DPI skin.
Browse files Browse the repository at this point in the history
-Position and sizes should of course be read as dimensions (dp by default).
-MoveIn and clip windows after getting preferred size.
  • Loading branch information
fruxo committed May 1, 2014
1 parent 80a88ee commit b5fab75
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions Demo/demo01/Demo01.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,22 +80,32 @@ void DemoWindow::LoadResource(TBNode &node)
// Get title from the WindowInfo section (or use "" if not specified)
SetText(node.GetValueString("WindowInfo>title", ""));

const TBRect parent_rect(0, 0, GetParent()->GetRect().w, GetParent()->GetRect().h);
const TBDimensionConverter *dc = g_tb_skin->GetDimensionConverter();
TBRect window_rect = GetResizeToFitContentRect();

// Use specified size or adapt to the preferred content size.
TBNode *tmp = node.GetNode("WindowInfo>size");
if (tmp && tmp->GetValue().GetArrayLength() == 2)
SetSize(tmp->GetValue().GetArray()->GetValue(0)->GetInt(),
tmp->GetValue().GetArray()->GetValue(1)->GetInt());
else
ResizeToFitContent();
{
window_rect.w = dc->GetPxFromString(tmp->GetValue().GetArray()->GetValue(0)->GetString(), window_rect.w);
window_rect.h = dc->GetPxFromString(tmp->GetValue().GetArray()->GetValue(1)->GetString(), window_rect.h);
}

// Use the specified position or center in parent.
tmp = node.GetNode("WindowInfo>position");
if (tmp && tmp->GetValue().GetArrayLength() == 2)
SetPosition(TBPoint(tmp->GetValue().GetArray()->GetValue(0)->GetInt(),
tmp->GetValue().GetArray()->GetValue(1)->GetInt()));
{
window_rect.x = dc->GetPxFromString(tmp->GetValue().GetArray()->GetValue(0)->GetString(), window_rect.x);
window_rect.y = dc->GetPxFromString(tmp->GetValue().GetArray()->GetValue(1)->GetString(), window_rect.y);
}
else
SetPosition(TBPoint((GetParent()->GetRect().w - GetRect().w) / 2,
(GetParent()->GetRect().h - GetRect().h) / 2));
window_rect = window_rect.CenterIn(parent_rect);

// Make sure the window is inside the parent, and not larger.
window_rect = window_rect.MoveIn(parent_rect).Clip(parent_rect);

SetRect(window_rect);

// Ensure we have focus - now that we've filled the window with possible focusable
// widgets. EnsureFocus was automatically called when the window was activated (by
Expand Down

0 comments on commit b5fab75

Please sign in to comment.