Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site











SourceForge.net Logo

Layouts

 

Using multiple layouts for various purposes

 

 

Layouts.h

 

#ifndef _Layouts_Layouts_h_

#define _Layouts_Layouts_h_

 

#include <CtrlLib/CtrlLib.h>

 

using namespace Upp;

 

#define LAYOUTFILE <Layouts/layoutfile1.lay> // Layouts will be visible in all files that #include Layouts.h

#include <CtrlCore/lay.h>

 

// FirstTabDlg will be visible in all files that #include Layouts.h

struct FirstTabDlg : WithFirstTabLayout<ParentCtrl> { // ParentCtrl is a good base class for tabs

    typedef FirstTabDlg CLASSNAME;

    FirstTabDlg();

};

 

#endif

 

 

 

main.cpp

 

#include "Layouts.h"

 

#define LAYOUTFILE <Layouts/layoutfile2.lay> // Layouts will be local to main.cpp

#include <CtrlCore/lay.h>

 

FirstTabDlg::FirstTabDlg() // Constructor needs to be in .cpp

{

    CtrlLayout(*this); // Places widgets into positions

}

 

struct SecondTabDlg : WithSecondTabLayout<ParentCtrl> { // Local to main.cpp

    typedef SecondTabDlg CLASSNAME;

    SecondTabDlg();

};

 

SecondTabDlg::SecondTabDlg()

{

    CtrlLayout(*this);

}

 

struct MainDlg : WithMainLayout<TopWindow> { // Local to main.cpp

    typedef MainDlg CLASSNAME;

    

    FirstTabDlg  tab1;

    SecondTabDlg tab2;

    

    void DoDialog();

    

    MainDlg();

};

 

void MainDlg::DoDialog()

{

    WithDialogLayout<TopWindow> dlg; // Variant without class, good for simple modal dialogs

    CtrlLayoutOK(dlg, "Dialog"); // OK means dialog has normal 'ok' button that needs setting up

    dlg.info = String().Cat() << "Today is: " << GetSysDate();

    if(dlg.Execute() != IDOK)

        return;

}

 

MainDlg::MainDlg()

{

    CtrlLayout(*this, "Layouts");

    tabs.Add(tab1.SizePos(), "Tab1"); // SizePos() means dialog fills the whole are of tab

    tabs.Add(tab2.SizePos(), "Tab2");

 

    tab1.dialog <<= THISBACK(DoDialog); // When pushing 'dialog' button, DoDialog is invoked

}

 

GUI_APP_MAIN

{

    MainDlg().Run();

}

 

 

 

layoutfile1.lay

 

LAYOUT(FirstTabLayout, 400, 200)

    ITEM(Label, dv___0, SetLabel(t_("This is first layout")).LeftPosZ(12, 124).TopPosZ(8, 21))

    ITEM(Button, dialog, SetLabel(t_("Push to invoke dialog")).LeftPosZ(12, 128).TopPosZ(40, 24))

END_LAYOUT

 

LAYOUT(SecondTabLayout, 400, 200)

    ITEM(Label, dv___0, SetLabel(t_("This is second layout")).LeftPosZ(12, 124).TopPosZ(8, 21))

END_LAYOUT

 

 

 

 

layoutfile2.lay

 

LAYOUT(DialogLayout, 196, 96)

    ITEM(Label, dv___0, SetLabel(t_("This is some dialog")).LeftPosZ(8, 116).TopPosZ(8, 21))

    ITEM(Label, info, SetLabel(t_("INFO...")).LeftPosZ(8, 116).TopPosZ(32, 21))

    ITEM(Button, ok, SetLabel(t_("OK")).LeftPosZ(120, 68).TopPosZ(64, 24))

END_LAYOUT

 

LAYOUT(MainLayout, 488, 276)

    ITEM(TabCtrl, tabs, LeftPosZ(4, 480).TopPosZ(4, 268))

END_LAYOUT

 

 

 

 

 

Do you want to contribute?