Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - Maksat

Pages: [1]
1
Hello!
I'm drawing radio buttons and check boxes to scrollable panel with fixed width (scrollablePanel.setHorizontalScrollbarPolicy(tgui::Scrollbar::Policy::Never)). Some of them have long texts and go beyond the borders of the panel. I think it would be useful to add the ability to automatically change the width of the text like in Label.
Here is example of what I have:

2
Help requests / 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");
        }
 

3
Hi Texus! Could you tell me how you implemented the "Middle" parameter on themes syntax? How do you scale given rect of texture and remain unchanged other parts?

4
Help requests / Adding signals to derived widgets
« on: 28 December 2019, 13:08:52 »
Hello! I made class inherited from tgui::Group, which contains some other widgets. Is it possible to add new signal like "GropWidgetPressed" so I could use it like this:
myGroupWidget.connect("GropWidgetPressed", [](){});
 

5
Help requests / Increasing scroll sensitivity
« on: 14 June 2019, 06:25:21 »
Hi! I could not find any way to increase scroll sensitivity of ScrollablePanel. It's very inconvenient to scroll to the end of the content of ScrollablePanel with low contentOffset, when it has wide content height

6
Help requests / unfocusing widgets
« on: 24 May 2019, 11:26:24 »
Hi!
auto button = tgui::Button::create();
button->setRenderer(theme.getRenderer("Button"));
button->connect("pressed", [](){std::cout<<"button pressed" << endl;});
gui->add(button);

/* --- */

sf::Event event;
while (window->isOpen())
{
        while (window->pollEvent(event))
        {
                /* --- */
                gui.handleEvent(event);
               
                if (event->type == Event::KeyPressed)
                        switch (event->key.code)
                        {
                        case Keyboard::Space:
                                cout<< "space key pressed"<<endl;
                                break;
                                /* --- */
                        }

                        /* --- */
        }
}
 

if you press the button and then the space key, you will see:
button pressed
button pressed
space key pressed

I use many buttons and i have another function bind to the space key. I have to unfocus widget every time i pressed it. Is there any option to disable auto focusing last pressed widget?

7
Help requests / ComboBox and State pattern
« on: 12 March 2019, 15:10:31 »
Hi! Here is a little example of how I implement State pattern in my program to manage windows. When I click ComboBox item, contex changes its state from Awindow to Bwindow, which will draw loading animationw while loading some resources and return back to A state. The problem is that when I press mouse button, contex changes it's state to B immediadetly and A state does not have time to accept the mouseButtonReleased event. So when contex returned back to the state A, the ComboBox will think that I'm still holding mouse button. How can I solve this problem?
 class BaseWindow;
class myRWindow : public sf::RenderWindow
{
        BaseWindow * state;
public:
        void changeState(BaseWindow *st) { state = st; }
        void handleEvent(Event *event) { state->handleEvent(event); }
        void drawCurrentState() { state->draw(); };
};

class BaseWindow
{
public:
        virtual void draw() = 0;
        virtual void handleEvent(sf::Event *) = 0;
protected:
        myRWindow *contex;
};

class WindowStateA : public BaseWindow
{
private:
        tgui::Gui gui;

        void onComboBoxItemSelected(tgui::Widget::Ptr, const sf::String&)
        {
                /* --- */
                WindowStateB *windB = WindowStateB::getInstance();
                contex->changeState(windB);
                windB->doSomethingAndReturn(this);
        };
public:
        virtual void draw();
        virtual void handleEvent(sf::Event & ev) { gui.handleEvent(ev); };

};

class WindowStateB : public BaseWindow
{
public:
        void doSomethingAndReturn(BaseWindow * wst) // and return to window
        {
                auto contWind = contex;
                auto changeState = [contWind, wst]() {contWind->changeState(wst); };
                /* --- */
                // working in another thread while showong animation. After finishing work  changeState will be called
                /* --- */
        }

        virtual void draw();
        virtual void handleEvent(sf::Event & ev);

};

8
Help requests / Set different text colors to ComboBox items
« on: 10 March 2019, 11:41:25 »
Hi everyone!
Is it possible to set a different color to specific items? I want to add item with grey color, which will mean that the item is not available.

Or how can I hide selected item from items list? Or is there any function like tgui::EditBox::setDefaultText? sorry for my bad English=)

Pages: [1]