diff --git a/include/osgUI/AlignmentSettings b/include/osgUI/AlignmentSettings index cc4fdeccd..6c9d2d75e 100644 --- a/include/osgUI/AlignmentSettings +++ b/include/osgUI/AlignmentSettings @@ -25,9 +25,6 @@ namespace osgUI class OSGUI_EXPORT AlignmentSettings : public osg::Object { public: - AlignmentSettings(); - AlignmentSettings(const AlignmentSettings& as, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); - META_Object(osgUI, AlignmentSettings); enum Alignment { @@ -52,6 +49,10 @@ public: RIGHT_BOTTOM_BASE_LINE }; + AlignmentSettings(Alignment alignment=AlignmentSettings::LEFT_BOTTOM); + AlignmentSettings(const AlignmentSettings& as, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); + META_Object(osgUI, AlignmentSettings); + void setAlignment(Alignment alignment) { _alignment = alignment; } Alignment getAlignment() const { return _alignment; } diff --git a/src/osgUI/AlignmentSettings.cpp b/src/osgUI/AlignmentSettings.cpp index d9df3e0fe..2bad796c6 100644 --- a/src/osgUI/AlignmentSettings.cpp +++ b/src/osgUI/AlignmentSettings.cpp @@ -17,8 +17,8 @@ using namespace osgUI; -AlignmentSettings::AlignmentSettings(): - _alignment(AlignmentSettings::LEFT_BOTTOM) +AlignmentSettings::AlignmentSettings(AlignmentSettings::Alignment alignment): + _alignment(alignment) { } diff --git a/src/osgUI/TabWidget.cpp b/src/osgUI/TabWidget.cpp index 296b92f54..a2b571943 100644 --- a/src/osgUI/TabWidget.cpp +++ b/src/osgUI/TabWidget.cpp @@ -65,7 +65,6 @@ bool TabWidget::handleImplementation(osgGA::EventVisitor* ev, osgGA::Event* even osgUtil::LineSegmentIntersector::Intersections intersections; if (aa->computeIntersections(*ea, nodePath, intersections)) { - const osgUtil::LineSegmentIntersector::Intersection& Intersection = *intersections.begin(); for(osg::NodePath::const_iterator itr = Intersection.nodePath.begin(); itr != Intersection.nodePath.end(); @@ -179,7 +178,7 @@ void TabWidget::createGraphicsImplementation() float selected = 0.97f; float titleHeight = 10.0f; float characterWidth = titleHeight*0.7f; - float margin = titleHeight*0.1f; + float margin = titleHeight*0.2f; float xPos = _extents.xMin(); float yMin = _extents.yMax()-titleHeight; float yMax = _extents.yMax(); @@ -187,6 +186,9 @@ void TabWidget::createGraphicsImplementation() float zMax = _extents.zMax(); unsigned int tabIndex = 0; + + osg::ref_ptr textAlignment = new osgUI::AlignmentSettings(osgUI::AlignmentSettings::LEFT_CENTER); + for(Tabs::iterator itr = _tabs.begin(); itr != _tabs.end(); ++itr, ++tabIndex) @@ -196,12 +198,18 @@ void TabWidget::createGraphicsImplementation() float width = tab->getText().size() * characterWidth; osg::BoundingBox headerExtents( xPos, yMin, zMin, xPos+width, yMax, zMax); + osg::BoundingBox textExtents( xPos+margin, yMin, zMin, xPos+width-margin, yMax, zMax); - OSG_NOTICE<<"headerExtents = " - < textNode = style->createText(textExtents, textAlignment.get(), getTextSettings(), tab->getText()); + + osg::ref_ptr text = dynamic_cast(textNode.get()); + if (text.valid()) textExtents = text->getBoundingBox(); + + // adjust position of size of text. + float textWidth = (textExtents.xMax() - textExtents.xMin()); + + headerExtents.xMax() = textExtents.xMin() + textWidth + margin; - osg::ref_ptr text = style->createText(headerExtents, getAlignmentSettings(), getTextSettings(), tab->getText()); osg::ref_ptr unselected_panel = style->createPanel(headerExtents, osg::Vec4(unselected, unselected, unselected, 1.0f)); osg::ref_ptr selected_panel = style->createPanel(headerExtents, osg::Vec4(selected, selected, selected, 1.0f)); @@ -219,7 +227,7 @@ void TabWidget::createGraphicsImplementation() _selectedHeaderSwitch->addChild(selected_group.get()); _tabWidgetSwitch->addChild(tab->getWidget()); - xPos += width+margin; + xPos += textWidth+3.0*margin; }