Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Questions about GUI design

This thread is locked; no one can reply to it. rss feed Print
Questions about GUI design
Edgar Reynaldo
Major Reynaldo
May 2007
avatar

axilmar said:

 EventListenerId addEventListener(EventType eventType, const std::function<void(const EventPtr &)>);

Don't you need to use mem_function? I never could get the hang of that.

It looks like an interesting idea. Maybe there is some redundancy in my design then, because right now I have both widget messages and listeners.

edit this is what I have right now

void WidgetBase::RaiseEvent(WidgetMsg msg) {
   // signal your slots
   PrivateRaiseEvent(msg);
   
   // send event to listeners
   EagleEvent e = MakeEagleEvent(msg);
   EmitEvent(e);
   
   // tell our parent
   if (wparent) {
      wparent->QueueUserMessage(msg);
   }
}

axilmar
Member #1,204
April 2001

Don't you need to use mem_function? I never could get the hang of that.

Not in c++11.

Quote:

Maybe there is some redundancy in my design then

No shit!!!! :-)

I suppose now you are going to go off and change Eagle5 with this design, aren't you?

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

No, and you're not doing anything all that original anyway. What you're doing is standard SWING design from java anyway. And yes I might like to reduce my messaging system to perhaps just listeners, and that would be completely within my rights to choose to do so. Stop implying that I just copy peoples work and ideas. It's pissing me off.

axilmar
Member #1,204
April 2001

No, and you're not doing anything all that original anyway.

I didn't imply that my ideas are original. Hardly anything is original these days.

Quote:

And yes I might like to reduce my messaging system to perhaps just listeners, and that would be completely within my rights to choose to do so. Stop implying that I just copy peoples work and ideas. It's pissing me off.

So asking another person about design ideas in the context of collaboration and then running off to implement these ideas on their own isn't something to be pissed off at?

Is that good behavior Edgar? I think not.

You clearly didn't think to apply the design I propose to your library, so when you distribute it, it must give me some credit, that being the least you can do.

Unless you still want to collaborate.

LennyLen
Member #5,313
December 2004
avatar

axilmar said:

Unless you still want to collaborate.

Why would he want to? You've been behaving like complete asshole for some time now.

jmasterx
Member #11,410
October 2009

LennyLen said:

Why would he want to? You've been behaving like complete ḁsshole for some time now.

I have to also agree. While you may mean well, text can be emotionally ambiguous, so it is important to ensure that you minimize this ambiguity.

You seem to really know your stuff when it comes to programming, but people will be hesitant to collaborate if they get a feeling of hostility. Saying something like: no shiṭ, while in the way you mean it might be nonchalant, without the context of your tone and facial expression, it's generally perceived as the demeaning form "duh, you stupid idiot".

Sometimes it helps to try to read back what you have written to someone as if you were receiving it.

Hopefully, keeping this in mind will allow communication that is more neutral, and that does not in any way make others feel bad, as can happen with the emotional ambiguity of text.

bamccaig
Member #7,536
July 2006
avatar

Also you do not own ideas. You said yourself those ideas aren't original anyway. It is entirely his choice to "credit" you with helping him. Just as it's entirely your choice to be helpful or not. I'd say your general attitude robs you of any due credit though. It's clear you aren't helping to be helpful, but doing so in hopes of exploiting him for personal gain. Which is a really shitty attitude. You should just try to help to be helpful or GTFO. If he ends up developing a better library as a result of your discussion then great! Especially if he releases it open source so you can use it to. Nothing stops you from doing the same! Put your egos aside already. Jesus. You both suck or you'd have done this already. >:( 8-)

axilmar
Member #1,204
April 2001

In the previous discussion we had about GUIs, although the technical points I raised were valid, and my behavior was nice, I was mostly ignored.

so I decided to change tactic to make people actually listen to me, because it seems raising technical points it's not enough, and being nice is also not enough.

My apologies to anyone that was insulted, that wasn't my intention.

EDIT:

bamccaig said:

Also you do not own ideas. You said yourself those ideas aren't original anyway. It is entirely his choice to "credit" you with helping him. Just as it's entirely your choice to be helpful or not. I'd say your general attitude robs you of any due credit though. It's clear you aren't helping to be helpful, but doing so in hopes of exploiting him for personal gain. Which is a really attitude. You should just try to help to be helpful or GTFO. If he ends up developing a better library as a result of your discussion then great! Especially if he releases it open source so you can use it to. Nothing stops you from doing the same! Put your egos aside already. Jesus. You both suck or you'd have done this already. >:( 8-)

Just saw the above.

Well...I really don't have an attitude. I wouldn't expect people to be so emotional.

What I really want to see is collaboration. Doing an enormous project like a GUI by myself is not fun.

It's also very illogical for many people to work individually on a GUI, when they could collaborate. The spending of resources is illogical.

If I didn't want to collaborate, I wouldn't discuss designs, I'd have completed my library by now.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

I thought the whole point of collaboration was for both parties to benefit. :/

I do like your idea though. I think it would work well.

As far as me using it in my library goes, not likely. My QueueUserMessage system works just fine for now, and I see no point to refactor that too just yet. I need to just sit down and work on my layout managers and then start porting widgets. What should the default layout of a container be? An expander? Ie., it takes up the full space of the panel it is on?

jmasterx
Member #11,410
October 2009

JPanel uses a FlowLayout... to do as your suggesting, perhaps BorderLayout where north,south,east,west have nothing?

axilmar
Member #1,204
April 2001

What should the default layout of a container be?

I don't think a container should have a default layout. When building a hierarchy of containers, it is seldom that a default layout can be useful. In most instantiations of a container, a different layout is instantiated.

Thomas Fjellstrom
Member #476
June 2000
avatar

I usually set up layouts with a dedicated layout widget. A top level or group widget would just be an open free form area, and if you want a layout, you use a hbox, vbox, table, splitter or another type of layout widget.

Another options is a non widget layout object that you attach to containers. But I find its easy enough to just make them child widgets.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

axilmar
Member #1,204
April 2001

Making layouts be widgets makes the reuse of layout algorithms more difficult than they can be.

For example, a window frame does not have a specific layout. Forcing it to have a specific layout makes changing layouts of the frame more difficult thab it can be: you either have to subclass the window frame to change its layout or add a container to it with the desired layout, which means one more widget consuming resources unneccesserily (the window frame could have the layout the container has).

Plus ot hardcoding the layout on a widget makes the whole thing a lot more flexible, for example the orientation of a scroll bar could change by simply altering the layout of its root widget, whereas with hardcoded layout the scrollbar needs a different base class for each orientation.

Thomas Fjellstrom
Member #476
June 2000
avatar

Yeah, but how often that happens, especially in games, I don't think it really matters in most cases.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

axilmar
Member #1,204
April 2001

Yeah, but how often that happens, especially in games, I don't think it really matters in most cases.

Many many times. In the current game I work, I had to implement the layout system in that way, because the same problem kept coming up over and over.

Thomas Fjellstrom
Member #476
June 2000
avatar

Maybe you're doing it wrong ;) jk.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

axilmar
Member #1,204
April 2001

Not really. It has increased the code reuse and simplified the code.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

axilmar said:

Plus ot hardcoding the layout on a widget makes the whole thing a lot more flexible, for example the orientation of a scroll bar could change by simply altering the layout of its root widget, whereas with hardcoded layout the scrollbar needs a different base class for each orientation.

I don't think you could switch from a h to a v scroll bar just with a layout change. You also need to change the bitmaps orientation or change the image so the buttons would work. What I would do is have an hscrollbar and a vscrollbar (instantiate both) and then only have one visible at a time.

Quote:

Making layouts be widgets makes the reuse of layout algorithms more difficult than they can be.

I really don't think so. I have widgets be layouts so they can be nested inside each other, because a layout holds widgets, not layouts and widgets separately. One layout can hold another directly as if it were a widget. All the widgets are registered separately to the gui. The layout object is strictly in charge of positioning (and/or resizing) widgets.

edit
Ie. you don't need panels, because layouts provide their functionality (but you can still have one if you need one). Saves resources by not having multiple buffers.

axilmar
Member #1,204
April 2001

I don't think you could switch from a h to a v scroll bar just with a layout change. You also need to change the bitmaps orientation or change the image so the buttons would work. What I would do is have an hscrollbar and a vscrollbar (instantiate both) and then only have one visible at a time.

In the game I work, the scroll bar class I have created has an orientation property. If I set the orientation to horizontal, I also change the layout to horizontal, if I set the orientation to vertical, I change the layout to vertical.

Then subclasses of the scroll bar that implement the actual components can choose the actual graphics from the 'orientationChanged' event.

Quote:

I have widgets be layouts so they can be nested inside each other, because a layout holds widgets, not layouts and widgets separately.

By having separate layouts, you can do that too. In my GUI library for the current game I work at, each widget has a pointer to a layout object, and layout objects can be shared with widgets. I have a set of functions that create horizontal boxes, vertical boxes, grid boxes, etc, and all these share the same layout instances. I also have layout instances that need parameters, and for these each widget has its own layout instance.

The advantages of separating layouts from widgets are:

  • less widget instances. If a container has a hardcoded layout, then in order to change that layout you may add another widget to it with the appropriate layout.


  • less subclassing. If a container has a hardcoded layout, then in order to change that layout you may subclass it.


  • less resources. If layout instances can be shared across objects, then that means fewer application resources.

For example, suppose you have a button with a horizontal orientation, which puts a text and an image side by side.

Suppose the button's layout is hardcoded because it inherits from class HBox.

In order to reuse the button code with a vertical layout that puts the image above the text, you have the following options:

1) create a new instance of VBox, put it inside the button, then add the image and the text in the vbox.

2) subclass the button to modify its layout algorithm internally. Then you break the contract that the button inherits from HBox.

If the layout is not hardcoded in the button, then all you have to do is change its layout.

Furthermore, if layouts are separated from widgets, writing new layout classes is easier: in the new layout class you don't have to deal with all the details of widgets. If layouts are hardcoded in widgets, creating a new layout means creating a new widget instance, providing constructors (if needed) for the base class that have to deal with widget properties that are unrelated to the actual layout, etc.

Additionally, debugging code in which layouts are separated from widgets is easier: if you have a problem with layouts, then you simply look at the layout code. You don't have to deal with all the rest of the widget code.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

axilmar said:

In the game I work, the scroll bar class I have created has an orientation property. If I set the orientation to horizontal, I also change the layout to horizontal, if I set the orientation to vertical, I change the layout to vertical.

In my library, a widget can have any layout it wants, as well as use its own to position its children if it wishes. Each widget is 'owned' by one or zero layouts and managed by a single widget handler.

I don't know why you would ever make a widget inherit from a layout class.

I have widgets be layouts

Correction - I have layouts be widgets so they can be nested. Said that backwards.

axilmar said:

If a container has a hardcoded layout

In my engine the user creates a layout, makes all its sublayouts and connects them, and then that layout is registered with the widget handler layout component which simply expands the object to the full size of the container. You can use whatever layouts you want with it.

I could also make the widget handler own a pointer to a layout in which case I would just have the widget handler resize the layout whenever it was resized.

In any case, for most intents and purposes, my layouts are separate from widgets. They inherit from WidgetBase merely to allow layouts to hold layouts as widget pointers.

bamccaig
Member #7,536
July 2006
avatar

If I may, one of the things that I find really helpful with design is putting implementation details aside and coming up with a stateless API. Which is to say, your base classes have no defined state (i.e., data). What methods must they have to get the job done, and what pieces of data and code (more interfaces, which is essentially also "data") need to be fed into them for them to accomplish their intended purpose?

Inheritance is a tricky tool to wield, but it will help a lot if you figure out the purely virtual interfaces for your objects. Your implementation classes (base classes and derived classes) won't inherit any state or code from your interface classes. The only thing the interface classes do is provide a defined way of interacting with an object whose state is completely abstract.

It is best if you can use your objects through these interfaces instead of directly through base or derived classes with known implementation details. Just a thought... I know that coming up with "interfaces" before implementations results in much better designs for me.

axilmar
Member #1,204
April 2001

My design is a lot simpler than your design Edgar. And my base layout class is stateless.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

And in my case I have the advantage that a layout has all the background features of a widget, such as its outer and inner area as well as its background, margins and 9 patch area. You can give your layouts a border just as if they were a separate panel as well as a background, which are all drawn automatically when WidgetBase::Display is called which is auto called by the gui.

I think the main difference here is that I have something mostly working and all you have right now are design ideas. Last time I looked at algui all you had was component and container, and all they did was hold components.

axilmar
Member #1,204
April 2001

And in my case I have the advantage that a layout has all the background features of a widget, such as its outer and inner area as well as its background, margins and 9 patch area. You can give your layouts a border just as if they were a separate panel as well as a background, which are all drawn automatically when WidgetBase::Display is called which is auto called by the gui.

Not an advantage, more like bloatware.

I can achieve the exact same functionality by combining a tiles bitmap and a frame layout.

Quote:

I think the main difference here is that I have something mostly working and all you have right now are design ideas. Last time I looked at algui all you had was component and container, and all they did was hold components.

All that I am describing are actually implemented in the gui of a big commercial mmo that I work on.They are on the market, tried and tested.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

axilmar said:

All that I am describing are actually implemented in the gui of a big commercial mmo that I work on.They are on the market, tried and tested.

Which is proprietary, and very unuseful to anyone like us. Do they ever plan on making it open source? Probably not, it's their moneymaker.

Obviously you have your own ideas and you don't care for anyone elses. Fine. That's why we have 10 different guis. I don't see myself abandoning what is already mostly working for something totally unwritten to work on a project with someone who refuses to see merit in any design other than his own. You want to be a project leader? Go ahead. But don't expect me to donate any of my time to your project.

And you have your design now, so why don't you go code it then. If it is so much simpler and easier to do it your way then you should be done in no time at all. :-/

edit
And those are features common to almost every widget. A widget should be able to have a border or margins and a 9 patch background that resizes automatically as they do. And you can leave any or all of it blank and it will not be drawn. It's a feature, not bloat. :P



Go to: