Best practice: Linking GUI to function code. Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
tuk1
Earned some good credits
Earned some good credits
Posts: 114
Joined: Sun Oct 08, 2017 9:36 am

Best practice: Linking GUI to function code.

Post by tuk1 »

Lets say we have...

1) A really simple class which takes strings and stores them in a kind of list, ...lets call the class: list_manager.
2) A GUI consisting of a text box and list box on a panel.

What is the usual practice for connecting the two, so they can elegantly interact with each other?

Should our Panel class have a list_manager as one of it's member variables?
wxWidgets(v3.2.2.1) - Vs2022(v143) - Win10(x64) - DialogBlocks(v5.16.5_Unicode)
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Best practice: Linking GUI to function code.

Post by ONEEYEMAN »

Hi,
The best would probably be to use std::vector of std::{w}string and use GUI to manage it through the list box.

But it depends on the task at hand...

Thank you.
tuk1
Earned some good credits
Earned some good credits
Posts: 114
Joined: Sun Oct 08, 2017 9:36 am

Re: Best practice: Linking GUI to function code.

Post by tuk1 »

I'm probably not being clear, my question is more about how the GUI layer and function layer should connect.

We cant just randomly use a vector, ...in my example the list_manager class has to interact with the GUI class and vice versa.

I'm asking for the best way to link the two? ...for eg, the GUI class could have a list_manager as one of its member variable, then its easy for the GUI object to find, manage and drive the list_manager object .
wxWidgets(v3.2.2.1) - Vs2022(v143) - Win10(x64) - DialogBlocks(v5.16.5_Unicode)
coderrc
Earned some good credits
Earned some good credits
Posts: 141
Joined: Tue Nov 01, 2016 2:46 pm

Re: Best practice: Linking GUI to function code.

Post by coderrc »

it sounds like what youre looking for is MVVM
User avatar
eranon
Can't get richer than this
Can't get richer than this
Posts: 867
Joined: Sun May 13, 2012 11:42 pm
Location: France
Contact:

Re: Best practice: Linking GUI to function code.

Post by eranon »

In wxWidgets, the mechanism to easily transfer values from variables to controls and reversely is done through the concept of validator (see wxValidator and derived classes). Of course, if the kind of controls and/or values you want to support has no wxWidgets validator yet, you can create your own deriving the stock validator you want.
[Ind. dev. - wxWidgets 3.0/3.1 under "Win 7 64-bit, TDM64-GCC" + "OS X 10.9, LLVM Clang"]
User avatar
shawnhcorey
Knows some wx things
Knows some wx things
Posts: 41
Joined: Mon Nov 19, 2012 3:29 pm
Location: The Great White North

Re: Best practice: Linking GUI to function code.

Post by shawnhcorey »

The Document/View Framework was created to separate documents from views, although some might think it is overkill for a single list.
WARNING: Highly caffeinated ☕. Approach with caution 🚧.
tuk1
Earned some good credits
Earned some good credits
Posts: 114
Joined: Sun Oct 08, 2017 9:36 am

Re: Best practice: Linking GUI to function code.

Post by tuk1 »

Thanks!!!
wxWidgets(v3.2.2.1) - Vs2022(v143) - Win10(x64) - DialogBlocks(v5.16.5_Unicode)
Post Reply