Questions

Started by Law, 10 August 2014, 14:47:07

texus

There will still be quite some changes in the next month to the v0.7 code though.
But the big rewrite to all the widgets is almost over (just MessageBox has been temporarily disabled and TextBox still has to be rewritten). Most of these changes will be improvements to specific widgets so they shouldn't bring too much incompatibilities.

There aren't tutorials yet, but the post in the last month on the facebook page show most of the new features.
The example code that is included with the download will be the best place to learn though.

I'm just recreating the Black theme. After that I'll send you the v0.7 code.
Do you have a bitbucket account by any chance?

Law

Sorry I don't. But I don't mind copy/pasting.

Thanks a lot :)

texus

#17
You can download it here: https://www.dropbox.com/s/ay4trebp4j1ehqr/texus-tgui-devel-af81ec0bcefb.zip?dl=1
Installation is the same as v0.6. You do need to have the latest sfml version for it though, it won't work with sfml 2.1.

Have a look at the examples/login_screen folder. That example will probably teach you most things.

I noticed that there is still a small bug with how slider stretches. I'll fix that tomorrow.
In order to solve it, the Slider section in Black.conf should look like this:
Slider:
    TrackNormalImage = "Black.png" Part(203, 150, 20, 45) Middle(0, 15, 20, 15)
    TrackHoverImage  = "Black.png" Part(223, 150, 20, 45) Middle(0, 15, 20, 15)
    ThumbNormalImage = "Black.png" Part(243, 150, 30, 30)

I even just realized that in v0.6 it always stretched that bad. So its not even a bug fix, changing this code is a feature :).

Law

Scanning dependencies of target tgui
[  2%] [  5%] [  8%] [ 11%] Building CXX object src/TGUI/CMakeFiles/tgui.dir/Gui.cpp.o
Building CXX object src/TGUI/CMakeFiles/tgui.dir/EditBox.cpp.o
Building CXX object src/TGUI/CMakeFiles/tgui.dir/Container.cpp.o
Building CXX object src/TGUI/CMakeFiles/tgui.dir/Layout.cpp.o
/home/lol/texus-tgui-devel-af81ec0bcefb/src/TGUI/Layout.cpp: In constructor 'tgui::LayoutGroup::LayoutGroup(tgui::Layout1d&, const tgui::Layout1d&, tgui::LayoutGroup::Selector)':
/home/lol/texus-tgui-devel-af81ec0bcefb/src/TGUI/Layout.cpp:276:28: error: invalid initialization of non-const reference of type 'tgui::Layout1d&' from an rvalue of type '<brace-enclosed initializer list>'
         m_selector{selector}
                            ^
/home/lol/texus-tgui-devel-af81ec0bcefb/src/TGUI/Layout.cpp: In constructor 'tgui::LayoutGroup::LayoutGroup(tgui::LayoutGroup&&)':
/home/lol/texus-tgui-devel-af81ec0bcefb/src/TGUI/Layout.cpp:286:36: error: invalid initialization of non-const reference of type 'tgui::Layout1d&' from an rvalue of type '<brace-enclosed initializer list>'
         m_selector{group.m_selector}
                                    ^
make[2]: *** [src/TGUI/CMakeFiles/tgui.dir/Layout.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [src/TGUI/CMakeFiles/tgui.dir/all] Error 2
make: *** [all] Error 2


Didn't you make me install the latest SFML ?

texus

Yes, but I was just mentioning it in case you also develop on another computer.

What compiler version do you have? (type "g++ --version" in the terminal)

Law

g++ (Ubuntu 4.8.2-19ubuntu1) 4.8.2

Here it is.

texus

I think we may have a serious problem here, this may not be easy to fix.
But before I can try to fix it I have to reproduce it. I have 4.9.1 installed on all my linuxes so I'm going to check on windows with 4.7.1.

In worst case I will have to completely rewrite the layout system (which I'm planning to do someday anyway since it has become a mess), but then it will take another week before you can use this version.

Law

Okay, anyway I was only asking you that for a minor thing, I can wait. Don't feel urged to fix that right now. I have lots of other things to do anyway.

Law

Also I was wondering.

    NormalImage_L  = "Black.png" (  0,  25,  50, 50)
    NormalImage_M  = "Black.png" ( 50,  25, 100, 50)
    NormalImage_R  = "Black.png" (150,  25,  50, 50)
    HoverImage_L   = "Black.png" (  0,  75,  50, 50)
    HoverImage_M   = "Black.png" ( 50,  75, 100, 50)
    HoverImage_R   = "Black.png" (150,  75,  50, 50)
    DownImage_L    = "Black.png" (  0, 125,  50, 50)
    DownImage_M    = "Black.png" ( 50, 125, 100, 50)
    DownImage_R    = "Black.png" (150, 125,  50, 50)


What do L, M and R stand for?

texus

#24
Left, Middle and Right.

The Left and Right parts would keep their ratio, while the Middle part gets stretched.
E.g. the EditBox image in the black theme is only 120 pixels width, but it still looks good when giving it a width of 1000 pixels.

But this has been replaced in v0.7 where you can even use 9-slice scaling. You would specify the entire button image there, and then set the middle rect to (50, 0, 100, 50) to split the image (with a width of 200 and a height of 50) into 3 parts (these rects are always left,top,width,height).

texus

I'm not sure if I hit a bug in gcc, or just some special case in the c++ standard.
I'm going to assume its a bug since it compiled with gcc 4.9.

The braces on lines 274 and 284 in src/TGUI/Layout.cpp should be replaced by brackets.
So "m_first{...}" should be "m_first(...)".
It should compile after that change.

I also found 2 other places that didn't compile, but you since you already passed the first one, and I assume that gcc 4.8 will have an emplace function, they just have to be fixed to make it work on gcc 4.7.

Law

Okay thanks!

I was also wondering how many different events tgui knows, beyond tgui::button::LeftMouseClicked. For example, what is the appropriate event when the user clicks outside of the widget he was using ?

Also how can we write in italics or bold in comboboxes, listboxes, etc?

texus

#27
QuoteAlso how can we write in italics or bold in comboboxes, listboxes, etc?
That is something that you can't do. It could be added in the future but it will take some planning about how it would be implemented.

QuoteI was also wondering how many different events tgui knows, beyond tgui::button::LeftMouseClicked.
Normally this is found in the documentation of that widget and its base classes. But since the documentation isn't really complete yet, here is the full list. Button inherits from ClickableWidget which inherits from Widget, so it also has the events from its base classes.
(The documentation of v0.6 should contain the ones from the other widgets, I think only PositionChanged and SizeChanged are new in v0.7)

Widget:
  PositionChanged       ///< Position of the widget has changed
  SizeChanged           ///< Size of the widget has changed
  Focused               ///< Widget gained focus.
  Unfocused             ///< Widget lost focus.
  MouseEntered         ///< Mouse cursor entered in the Widget area.
  MouseLeft            ///< Mouse cursor left the Widget area.

ClickableWidget:
  LeftMousePressed     ///< The left mouse button was pressed
  LeftMouseReleased     ///< The left mouse button was released
  LeftMouseClicked     ///< The left mouse button was clicked

Button:
  SpaceKeyPressed     ///< Space key was pressed
  ReturnKeyPressed     ///< Return key was pressed

Quotewhat is the appropriate event when the user clicks outside of the widget he was using
That will hopefully generate an Unfocused event :)

Focusing widgets is something very tricky in my code and even I can't always predict the exact behavior. The event should be fired when clicking outside the edit box that you were typing. But I don't think it will work with e.g. a slider.

The SpaceKeyPressed and ReturnKeyPressed callbacks only work when the button is focused, but the black style has no focused image by default. So it may not be possible to focus a button and then press space to trigger a callback while using the black theme.

Edit: I just verified it. Clicking outside the edit box will correctly generate the unfocused callback. Button will generate this callback immediately after the focused callback, since it cannot be focused without a focus image. Edit box is the exception since it has to be focused to type text in it, which is the reason that it can be focused even when there is no focus image.

Law

Okay thanks again.

I'm currently trying callbacks and it is my understanding that you only use the duo bindCallback + setCallbackId when you only have 1 callback to put on the widget. You can't put two different callbacks (like, LeftMouseReleased and )LeftMousePressed) this way, correct ? (Because that doesn't work for me)

Also, just for your future versions, you might want the comboboxes' content to disappear on LeftMouseReleased rather than LeftMousePressed. Also it could be nice to highlight the item you are currently hovering. :)

texus

QuoteYou can't put two different callbacks (like, LeftMouseReleased and )LeftMousePressed) this way, correct
All callbacks will have the same callbackId, you cannot use more than one id.
The id is just needed to differentiate between the widgets, you also have callback.trigger which contains whether it was a LeftMouseReleased or LeftMousePressed. But in most cases you don't even need the id since you just call a specific function when something happens to that widget. And the function isn't called from anywhere else.

QuoteAlso, just for your future versions, you might want the comboboxes' content to disappear on LeftMouseReleased rather than LeftMousePressed. Also it could be nice to highlight the item you are currently hovering. :)
Thanks for the feedback.
Altough this might be harder than it looks. The list is actually a ListBox that gets created. Highlighting items should thus just be implemented in ListBox and it will automatically work with the combo box. So that is doable.
But the list box is closed when the combo box gets a ItemSelected callback from the list box. This brings 2 problems: the list doesn't close when clicking on the already selected item, and it always happens on mouse press. Using the click callback instead of the ItemSelect won't work because you may click on the scrollbar. So I'm still looking for a way to get around this limitation.