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
Experienced Solver
Experienced Solver
Posts: 62
Joined: Sun Oct 08, 2017 9:36 am

Best practice: Linking GUI to function code.

Post by tuk1 » Thu Dec 14, 2017 9:30 pm

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.0.4) - Vs2017(v141) - Win7(x64) - DialogBlocks(v5.15.3_Unicode)

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 3465
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Best practice: Linking GUI to function code.

Post by ONEEYEMAN » Thu Dec 14, 2017 9:42 pm

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
Experienced Solver
Experienced Solver
Posts: 62
Joined: Sun Oct 08, 2017 9:36 am

Re: Best practice: Linking GUI to function code.

Post by tuk1 » Thu Dec 14, 2017 10:09 pm

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.0.4) - Vs2017(v141) - Win7(x64) - DialogBlocks(v5.15.3_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 » Fri Dec 15, 2017 1:16 pm

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 » Fri Dec 15, 2017 7:50 pm

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: 34
Joined: Mon Nov 19, 2012 3:29 pm
Location: The Great White North

Re: Best practice: Linking GUI to function code.

Post by shawnhcorey » Sat Dec 16, 2017 1:52 pm

The Document/View Framework was created to separate documents from views, although some might think it is overkill for a single list.

tuk1
Experienced Solver
Experienced Solver
Posts: 62
Joined: Sun Oct 08, 2017 9:36 am

Re: Best practice: Linking GUI to function code.

Post by tuk1 » Sat Dec 16, 2017 8:50 pm

Thanks!!!
wxWidgets(v3.0.4) - Vs2017(v141) - Win7(x64) - DialogBlocks(v5.15.3_Unicode)

Post Reply