Binding MaximumTextWidth

  • 1 Replies
  • 30 Views
Binding MaximumTextWidth
« on: 19 May 2020, 10:38:46 »
Hello,
How can I bind Labels MaximumTextWidth on widgets width? I'm making custom slider with it's name and value shown above.
Here is what I have for now:
class MyTguiSlider : public Panel
        {
        public:
                typedef std::shared_ptr<MyTguiSlider> Ptr;
                typedef std::shared_ptr<const MyTguiSlider> ConstPtr;

                MyTguiSlider(const sf::String& name, const Layout width = { "100%"});
                ~MyTguiSlider() {};

                static MyTguiSlider::Ptr create(const sf::String& name, const Layout width = { "100%" });

        protected:
        private:
                Label::Ptr m_nameLabel;
                Label::Ptr m_valueLabel;
                Slider::Ptr m_slider;
        };

tgui::MyTguiSlider::MyTguiSlider(const sf::String& name, const Layout width)
        {              
                m_valueLabel = Label::create("100.00");
                m_slider = Slider::create();
                m_nameLabel = Label::create(name);             
                getRenderer()->setBackgroundColor({ 100, 100, 60 });

                m_slider->setSize("95%", 10);
                m_slider->setPosition("&.w/2 - w/2", "nameLabel.bottom + h");
                add(m_slider, "slider");               
               
                m_valueLabel->setHorizontalAlignment(Label::HorizontalAlignment::Right);
                m_valueLabel->setPosition("slider.right - width", "slider.top - height");
                add(m_valueLabel, "valueLabel");               

                m_nameLabel->setMaximumTextWidth(m_slider->getSize().x - m_valueLabel->getSize().x - 10);
                m_nameLabel->setPosition("slider.left", 0);
                add(m_nameLabel, "nameLabel");
               

                setSize(width, "slider.bottom + 10");
        }
 

Re: Binding MaximumTextWidth
« Reply #1 on: 19 May 2020, 12:12:45 »
I seem to figure it out ;D. I just have to update maximum text width every time widget changes its size.