本文整理汇总了C++中widget::Ptr类的典型用法代码示例。如果您正苦于以下问题:C++ Ptr类的具体用法?C++ Ptr怎么用?C++ Ptr使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Ptr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: addChild
void Widget::addChild(Widget::Ptr child) {
if (child->parent().get() != this) {
return child->setParent(shared_from_this());
}
m_children.push_back(child);
}
示例2: UpdateChild
void Alignment::UpdateChild() {
Widget::Ptr child = GetChild();
if( !child ) {
return;
}
sf::FloatRect allocation( GetAllocation() );
sf::Vector2f spare_space( allocation.width, allocation.height );
spare_space -= child->GetRequisition();
spare_space.x *= 1.f - GetScale().x;
spare_space.y *= 1.f - GetScale().y;
if( ( spare_space.x < 0 ) || ( spare_space.y < 0 ) ) {
#ifdef SFGUI_DEBUG
std::cerr << "SFGUI warning: Alignment got a smaller allocation than it requested." << std::endl;
return;
#endif
}
allocation.left = spare_space.x * GetAlignment().x;
allocation.top = spare_space.y * GetAlignment().y;
allocation.width -= spare_space.x;
allocation.height -= spare_space.y;
child->SetAllocation( allocation );
}
示例3: GetChild
sf::Vector2f Alignment::CalculateRequisition() {
Widget::Ptr child = GetChild();
if( !child ) {
return sf::Vector2f( 0.f, 0.f );
}
return child->GetRequisition();
}
示例4: removeChild
void Widget::removeChild(Widget::Ptr child) {
if (child->parent() != 0) {
return child->setParent(0);
}
auto it = std::find(m_children.begin(), m_children.end(), child);
if (it != m_children.begin()) {
m_children.erase(it);
}
}
示例5: RemoveAll
void Container::RemoveAll() {
while( !m_children.empty() ) {
Widget::Ptr widget = m_children.back();
m_children.pop_back();
widget->SetParent( Widget::Ptr() );
HandleRemove( widget );
}
RequestResize();
}
示例6: handleUnconditionalExitInstrumentation
bool Instrumenter::handleUnconditionalExitInstrumentation(RelocBlock *trace, RelocGraph *, instPoint *exit) {
// Easy
RelocBlock::WidgetList &elements = trace->elements();
// For now, we're inserting this instrumentation immediately before the last instruction
// in the list of elements.
Widget::Ptr inst = makeInstrumentation(exit);
if (!inst) return false;
inst.swap(elements.back());
elements.push_back(inst);
return true;
}
示例7: setParent
void Widget::setParent(Widget::Ptr parent) {
if (m_parent == parent)
return;
if (m_parent) {
std::cout << m_parent << std::endl;
Widget::Ptr old = m_parent;
m_parent = 0;
old->removeChild(shared_from_this());
}
if (parent) {
m_parent = parent;
parent->addChild(shared_from_this());
}
}
示例8: pack
void Container::pack(Widget::Ptr widget)
{
mChildren.push_back(widget);
if(!hasSelection() && widget->isSelectable())
select(mChildren.size() -1);
}
示例9: SetParent
void Widget::SetParent( Widget::Ptr parent ) {
auto cont = std::dynamic_pointer_cast<Container>( parent );
auto oldparent = m_parent.lock();
if( cont == oldparent ) {
return;
}
if( oldparent ) {
oldparent->Remove( shared_from_this() );
}
m_parent = cont;
auto iter = std::find( root_widgets.begin(), root_widgets.end(), this );
if( parent ) {
// If this widget has a parent, it is no longer a root widget.
if( iter != root_widgets.end() ) {
root_widgets.erase( iter );
}
SetHierarchyLevel( parent->GetHierarchyLevel() + 1 );
}
else {
// If this widget does not have a parent, it becomes a root widget.
if( iter == root_widgets.end() ) {
root_widgets.push_back( this );
}
SetHierarchyLevel( 0 );
}
HandleAbsolutePositionChange();
}
示例10: remove
bool ScrollablePanel::remove(const Widget::Ptr& widget)
{
const sf::Vector2f bottomRight = widget->getPosition() + widget->getFullSize();
const bool ret = Panel::remove(widget);
if (m_contentSize == sf::Vector2f{0, 0})
{
if ((bottomRight.x == m_mostBottomRightPosition.x) || (bottomRight.y == m_mostBottomRightPosition.y))
{
recalculateMostBottomRightPosition();
updateScrollbars();
}
}
return ret;
}
示例11: Remove
void Container::Remove( const Widget::Ptr& widget ) {
WidgetsList::iterator iter( std::find( m_children.begin(), m_children.end(), widget ) );
if( iter != m_children.end() ) {
m_children.erase( iter );
widget->SetParent( Widget::Ptr() );
HandleRemove( widget );
RequestResize();
}
}
示例12: Add
void Container::Add( const Widget::Ptr& widget ) {
if( IsChild( widget ) ) {
return;
}
m_children.push_back( widget );
HandleAdd( widget );
// Check if HandleAdd still wants the little boy.
if( IsChild( widget ) ) {
widget->SetParent( shared_from_this() );
RequestResize();
}
}
示例13: loadWidget
TGUI_API Widget::Ptr loadWidget(std::shared_ptr<DataIO::Node> node, Widget::Ptr widget)
{
assert(widget != nullptr);
if (node->propertyValuePairs["visible"])
{
bool visible = parseBoolean(node->propertyValuePairs["visible"]->value);
if (visible)
widget->show();
else
widget->hide();
}
if (node->propertyValuePairs["enabled"])
{
bool enabled = parseBoolean(node->propertyValuePairs["enabled"]->value);
if (enabled)
widget->enable();
else
widget->disable();
}
if (node->propertyValuePairs["position"])
widget->setPosition(parseLayout(node->propertyValuePairs["position"]->value));
if (node->propertyValuePairs["size"])
widget->setSize(parseLayout(node->propertyValuePairs["size"]->value));
if (node->propertyValuePairs["opacity"])
widget->setOpacity(tgui::stof(node->propertyValuePairs["opacity"]->value));
/// TODO: Font and ToolTip (and Theme?)
for (auto& childNode : node->children)
{
if (toLower(childNode->name) == "renderer")
{
for (auto& pair : childNode->propertyValuePairs)
widget->getRenderer()->setProperty(pair.first, pair.second->value);
}
}
REMOVE_CHILD("renderer");
return widget;
}
示例14: SetParent
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();
}
示例15: addWidget
void Grid::addWidget(const Widget::Ptr& widget, unsigned int row, unsigned int col,
const Borders& borders, Alignment alignment)
{
// If the widget hasn't already been added then add it now
if (std::find(getWidgets().begin(), getWidgets().end(), widget) == getWidgets().end())
add(widget);
// Create the row if it did not exist yet
if (m_gridWidgets.size() < row + 1)
{
m_gridWidgets.resize(row + 1);
m_objBorders.resize(row + 1);
m_objAlignment.resize(row + 1);
}
// Create the column if it did not exist yet
if (m_gridWidgets[row].size() < col + 1)
{
m_gridWidgets[row].resize(col + 1, nullptr);
m_objBorders[row].resize(col + 1);
m_objAlignment[row].resize(col + 1);
}
// If this is a new row then reserve some space for it
if (m_rowHeight.size() < row + 1)
m_rowHeight.resize(row + 1, 0);
// If this is the first row to have so many columns then reserve some space for it
if (m_columnWidth.size() < col + 1)
m_columnWidth.resize(col + 1, 0);
// Add the widget to the grid
m_gridWidgets[row][col] = widget;
m_objBorders[row][col] = borders;
m_objAlignment[row][col] = alignment;
// Update the widgets
updateWidgets();
// Automatically update the widgets when their size changes
m_connectedCallbacks[widget] = widget->connect("SizeChanged", &Grid::updateWidgets, this);
}