DebugSettingsWindow(TBWidget *root) { SetText("Debug settings"); g_widgets_reader->LoadData(this, "TBLayout: axis: y, distribution: available, position: left\n" " TBLayout: id: 'container', axis: y, size: available\n" " TBTextField: text: 'Event output:'\n" " TBEditField: id: 'output', gravity: all, multiline: 1, wrap: 0\n" " lp: pref-height: 100dp"); AddCheckbox(TBDebugInfo::LAYOUT_BOUNDS, "Layout bounds"); AddCheckbox(TBDebugInfo::LAYOUT_CLIPPING, "Layout clipping"); AddCheckbox(TBDebugInfo::LAYOUT_PS_DEBUGGING, "Layout size calculation"); AddCheckbox(TBDebugInfo::RENDER_BATCHES, "Render batches"); AddCheckbox(TBDebugInfo::RENDER_SKIN_BITMAP_FRAGMENTS, "Render skin bitmap fragments"); AddCheckbox(TBDebugInfo::RENDER_FONT_BITMAP_FRAGMENTS, "Render font bitmap fragments"); output = GetWidgetByIDAndType<TBEditField>(TBIDC("output")); TBRect bounds(0, 0, root->GetRect().w, root->GetRect().h); SetRect(GetResizeToFitContentRect().CenterIn(bounds).MoveIn(bounds).Clip(bounds)); root->AddChild(this); TBWidgetListener::AddGlobalListener(this); }
void DemoWindow::LoadResource(TBNode &node) { g_widgets_reader->LoadNodeTree(this, &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) { 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) { 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 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 // adding the window to the root), but then we had nothing to focus. // Alternatively, we could add the window after setting it up properly. EnsureFocus(); }
void TBWindow::ResizeToFitContent(RESIZE_FIT fit) { SetRect(GetResizeToFitContentRect(fit)); }