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











SourceForge.net Logo

GetLayoutId

 

Demostrate how to use Layout introspection

 

 

main.cpp

 

#include <CtrlLib/CtrlLib.h>

 

using namespace Upp;

 

#define LAYOUTFILE <GetLayoutId/MyApp.lay>

#include <CtrlCore/lay.h>

 

class MyApp : public WithMyAppLayout<TopWindow> {

public:

    typedef MyApp CLASSNAME;

    

    void Load();

    void Save();

    

    MyApp();

};

 

void MyApp::Load()

{

    Value v = ParseJSON(LoadFile(ConfigFile("data.json")));

    for(Ctrl *q = GetFirstChild(); q; q = q->GetNext())

        if(dynamic_cast<EditField *>(q))

            *q <<= v[q->GetLayoutId()]; // If missing in JSON, sets Null, which is OK

}

 

void MyApp::Save()

{

    Json json;

    for(Ctrl *q = GetFirstChild(); q; q = q->GetNext())

        if(dynamic_cast<EditField *>(q)) {

            String id = q->GetLayoutId();

            if(id.GetCount())

                json(id, ~*q);

        }

    SaveFile(ConfigFile("data.json"), json);

}

 

MyApp::MyApp()

{

    CtrlLayoutOKCancel(*this, "Window title");

}

 

GUI_APP_MAIN

{

    MyApp app;

    app.Load();

    if(app.Execute() == IDOK)

        app.Save();

}

 

 

 

MyApp.lay

 

LAYOUT(MyAppLayout, 216, 140)

    ITEM(Label, dv___0, SetLabel(t_("Name")).LeftPosZ(8, 68).TopPosZ(8, 21))

    ITEM(EditString, name, LeftPosZ(80, 128).TopPosZ(8, 19))

    ITEM(Label, dv___2, SetLabel(t_("Last Name")).LeftPosZ(8, 68).TopPosZ(32, 21))

    ITEM(EditString, lastname, LeftPosZ(80, 128).TopPosZ(32, 19))

    ITEM(Label, dv___4, SetLabel(t_("City")).LeftPosZ(8, 68).TopPosZ(56, 21))

    ITEM(EditString, city, LeftPosZ(80, 128).TopPosZ(56, 19))

    ITEM(Label, dv___6, SetLabel(t_("Street")).LeftPosZ(8, 68).TopPosZ(80, 21))

    ITEM(EditString, street, LeftPosZ(80, 128).TopPosZ(80, 19))

    ITEM(Button, ok, SetLabel(t_("OK")).HCenterPosZ(64, 0).BottomPosZ(8, 24))

    ITEM(Button, cancel, SetLabel(t_("Cancel")).RightPosZ(8, 64).BottomPosZ(8, 24))

END_LAYOUT

 

 

 

 

GetLayoutId.lay

 

LAYOUT(GetLayoutIdLayout, 216, 140)

    ITEM(Label, dv___0, SetLabel(t_("Name")).LeftPosZ(8, 68).TopPosZ(8, 21))

    ITEM(EditString, name, LeftPosZ(80, 128).TopPosZ(8, 19))

    ITEM(Label, dv___2, SetLabel(t_("Last Name")).LeftPosZ(8, 68).TopPosZ(32, 21))

    ITEM(EditString, lastname, LeftPosZ(80, 128).TopPosZ(32, 19))

    ITEM(Label, dv___4, SetLabel(t_("City")).LeftPosZ(8, 68).TopPosZ(56, 21))

    ITEM(EditString, city, LeftPosZ(80, 128).TopPosZ(56, 19))

    ITEM(Label, dv___6, SetLabel(t_("Street")).LeftPosZ(8, 68).TopPosZ(80, 21))

    ITEM(EditString, street, LeftPosZ(80, 128).TopPosZ(80, 19))

    ITEM(Button, ok, SetLabel(t_("OK")).HCenterPosZ(64, 0).BottomPosZ(8, 24))

    ITEM(Button, cancel, SetLabel(t_("Cancel")).RightPosZ(8, 64).BottomPosZ(8, 24))

END_LAYOUT

 

 

 

 

 

Do you want to contribute?