void ReadItems(TBWidgetsReader *reader, TBNode *node, TBGenericStringItemSource *target_source) { // If there is a items node, loop through all its children and add // items to the target item source. if (TBNode *items = node->GetNode("items")) { for (TBNode *n = items->GetFirstChild(); n; n = n->GetNext()) { if (strcmp(n->GetName(), "item") != 0) continue; const char *item_str = n->GetValueString("text", ""); TBID item_id; if (TBNode *n_id = n->GetNode("id")) reader->SetIDFromNode(item_id, n_id); TBGenericStringItem *item = new TBGenericStringItem(item_str, item_id); if (!item || !target_source->AddItem(item)) { // Out of memory delete item; break; } } } }
TBConsole::TBConsole(BATB& b) : batb( b ) { using namespace tb; // read file as node tree, letting us parse custom nodes for this widget. // see tb_widgets_reader.[hc]pp TBNode node; if ( node.ReadFile( "static://batb/run/console.tb.txt" ) ) { // let TB populate this TBWindow from file g_widgets_reader->LoadNodeTree( this, &node ); // read properties for 'this' (g_widgets_reader only adds children of 'this') // (see void TBWidget::OnInflate(const INFLATE_INFO &info) in tb_widgets_reader.cpp) SetSkinBg( node.GetValueString( "skin", "TBWindow" ) ); //SetOpacity( node.GetValueFloat("opacity", GetOpacity()) ); // we can now retrieve child widgets of 'this' from ID with // - MyWidget* widget = GetWidgetByIDAndType<MyWidget>( TBIDC("my-id-name") ); // - tb::TBWidget* widget = GetWidgetById( TBIDC( "my-id-name" ) ); if ( (tb_input_ = GetWidgetByIDAndType<TBEditField>( TBIDC( "input" ) ) ) == nullptr ) { batb.log << "TBConsole: " << "no TBEditField 'input' defined :(" << std::endl; } if ( (tb_output_ = GetWidgetByIDAndType<TBEditField>( TBIDC( "output" ) ) ) == nullptr ) { batb.log << "TBConsole: " << "no TBEditField 'output' defined :(" << std::endl; } { // only input should receive focus tb_output_->SetIsFocusable( false ); // TODO: change skin of scrollbar. use TBEditField::GetScrollRoot() ? } //tb_input_->SetPlaceholderText( "enter command" ); } else { batb.log << "TBConsole: " << "could not read tbconsole.tb.txt" << std::endl; //throw std::runtime_error( "TBConsole: error reading file" ); } // settings: //SetSettings( tb::WINDOW_SETTINGS_RESIZABLE ); SetSettings( tb::WINDOW_SETTINGS_NONE ); SetText( "TBConsole" ); }
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(); }
bool TBBFRenderer::FindGlyphs() { if (!m_img) return false; const char *glyph_str = m_node.GetValueString("info>glyph_str", nullptr); if (!glyph_str) return false; int glyph_str_len = strlen(glyph_str); int i = 0; int x = 0; while (UCS4 uc = utf8::decode_next(glyph_str, &i, glyph_str_len)) { if (GLYPH *glyph = FindNext(uc, x)) { m_glyph_table.Add(uc, glyph); // OOM! x = glyph->x + glyph->w + 1; } else break; } return true; }