void Widget::RequestResize() { m_requisition = CalculateRequisition(); if( m_custom_requisition ) { if( m_custom_requisition->x > 0.f ) { m_requisition.x = std::max( m_custom_requisition->x, m_requisition.x ); } if( m_custom_requisition->y > 0.f ) { m_requisition.y = std::max( m_custom_requisition->y, m_requisition.y ); } } HandleRequisitionChange(); Container::Ptr parent = m_parent.lock(); // Notify observers. GetSignals().Emit( OnSizeRequest ); if( parent ) { parent->RequestResize(); } else { sf::FloatRect allocation( GetAllocation().left, GetAllocation().top, std::max( GetAllocation().width, m_requisition.x ), std::max( GetAllocation().height, m_requisition.y ) ); SetAllocation( allocation ); } }
virtual Container::Ptr Decode(const Binary::Container& data) const { if (!FileDecoder->GetFormat()->Match(data)) { return Container::Ptr(); } const Container::Ptr files = ZXZip::ParseArchive(*FileDecoder, data); return files && files->CountFiles() ? files : Container::Ptr(); }
void Widget::SetParent( Widget::Ptr parent ) { Container::Ptr cont( std::dynamic_pointer_cast<Container>( parent ) ); if( !cont ) { return; } Container::Ptr oldparent = m_parent.lock(); if( oldparent ) { oldparent->Remove( shared_from_this() ); } m_parent = cont; }
void WidgetLoader::load(Container::Ptr parent, std::stringstream& stream) { auto rootNode = DataIO::parse(stream); if (rootNode->propertyValuePairs.size() != 0) loadWidget(rootNode, parent); for (auto& node : rootNode->children) { auto nameSeparator = node->name.find('.'); auto widgetType = node->name.substr(0, nameSeparator); auto& loadFunction = m_loadFunctions[toLower(widgetType)]; if (loadFunction) { std::string className; if (nameSeparator != std::string::npos) { if ((node->name.size() >= nameSeparator + 2) && (node->name[nameSeparator+1] == '"') && (node->name.back() == '"')) className = Deserializer::deserialize(ObjectConverter::Type::String, node->name.substr(nameSeparator + 1)).getString(); else className = node->name.substr(nameSeparator + 1); } tgui::Widget::Ptr widget = loadFunction(node); parent->add(widget, className); } else throw Exception{"No load function exists for widget type '" + widgetType + "'."}; } }
TGUI_API Widget::Ptr loadContainer(std::shared_ptr<DataIO::Node> node, Container::Ptr container) { assert(container != nullptr); loadWidget(node, container); for (auto& childNode : node->children) { auto nameSeparator = childNode->name.find('.'); auto widgetType = childNode->name.substr(0, nameSeparator); auto& loadFunction = WidgetLoader::getLoadFunction(toLower(widgetType)); if (loadFunction) { std::string className; if (nameSeparator != std::string::npos) { if ((childNode->name.size() >= nameSeparator + 2) && (childNode->name[nameSeparator+1] == '"') && (childNode->name.back() == '"')) className = Deserializer::deserialize(ObjectConverter::Type::String, childNode->name.substr(nameSeparator + 1)).getString(); else className = childNode->name.substr(nameSeparator + 1); } tgui::Widget::Ptr childWidget = loadFunction(childNode); container->add(childWidget, className); } else throw Exception{"No load function exists for widget type '" + widgetType + "'."}; } return container; }
void Widget::SetParent( const Widget::Ptr& parent ) { Container::Ptr cont( DynamicPointerCast<Container>( parent ) ); if( !cont ) { return; } Container::Ptr oldparent = m_parent.lock(); if( oldparent ) { oldparent->Remove( shared_from_this() ); } m_parent = cont; SetHierarchyLevel( parent->GetHierarchyLevel() + 1 ); HandleAbsolutePositionChange(); }
void Widget::RequestSize() const { m_recalc_requisition = true; Container::Ptr parent = m_parent.lock(); // Notify observers. OnSizeRequest(); if( parent ) { parent->RequestSize(); } else { sf::Vector2f requisition( GetRequisition() ); sf::FloatRect allocation( GetAllocation().Left, GetAllocation().Top, std::max( GetAllocation().Width, requisition.x ), std::max( GetAllocation().Height, requisition.y ) ); AllocateSize( allocation ); } }
void WidgetSaver::save(Container::Ptr widget, std::stringstream& stream) { auto node = std::make_shared<DataIO::Node>(); for (auto& child : widget->getWidgets()) { auto& saveFunction = WidgetSaver::getSaveFunction(toLower(child->getWidgetType())); if (saveFunction) node->children.emplace_back(saveFunction(WidgetConverter{child})); else throw Exception{"No save function exists for widget type '" + child->getWidgetType() + "'."}; } DataIO::emit(node, stream); }
TGUI_API std::shared_ptr<DataIO::Node> saveContainer(Container::Ptr container) { auto node = saveWidget(container); for (auto& child : container->getWidgets()) { auto& saveFunction = WidgetSaver::getSaveFunction(toLower(child->getWidgetType())); if (saveFunction) node->children.emplace_back(saveFunction(WidgetConverter{child})); else throw Exception{"No save function exists for widget type '" + child->getWidgetType() + "'."}; } return node; }