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












SourceForge.net Logo
Home » Community » Newbie corner » Layout files versus embedded code
Layout files versus embedded code [message #59621] Fri, 17 February 2023 14:25 Go to next message
MrAndreas is currently offline  MrAndreas
Messages: 2
Registered: February 2023
Junior Member
I just came across U++ and soon found the following example...

#include <CtrlLib/CtrlLib.h>

#define LAYOUTFILE <Days/Days.lay>
#include <CtrlCore/lay.h>

class Days : public WithDaysLayout<TopWindow> {
public:

    typedef Days CLASSNAME;
    Days();
};

Days::Days()
{
    CtrlLayout(*this, "Days");
    date1 ^= date2 ^= [=] {
        result = IsNull(date1) || IsNull(date2) ? "" :
                 Format("There is %d day(s) between %` and %`", abs(Date(~date1) - Date(~date2)), ~date1, ~date2);
    };
}

GUI_APP_MAIN
{
    Days().Run();
}

Source: U++ Overview / 1. Whetting your appetite

Based on this example it appears U++ makes use of external data files that describe the GUI similar to how Delphi and C++ Builder uses DFM files for the same purpose. If this is the case then why was this paradigm chosen when it has been proven to be a source of many errors and in general flawed? Note that Anders, the original architect of Delphi/C++ Builder, recognised and rectified these flaws when he designed C# and made the GUI definitions as plain C# code embedded in standard C# source files.


Cheers,
-Andreas
Re: Layout files versus embedded code [message #59627 is a reply to message #59621] Sun, 19 February 2023 10:12 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Nope. See this:

#define LAYOUTFILE <Days/Days.lay>
#include <CtrlCore/lay.h>


This is actually the layout definition and it is embedded directly to sources.

AFAIK, this is very similar to C# does. The one difference is that while C# dialog designer produces complex C# code with multiple warning in comments "do not edit by hand", in U++, thanks to macros, we have a bit nicer "format"

LAYOUT(DaysLayout, 320, 64)
	ITEM(Upp::EditDate, date1, LeftPosZ(52, 100).TopPosZ(8, 19))
	ITEM(Upp::Label, dv___1, SetLabel(t_("Date 1")).LeftPosZ(8, 40).TopPosZ(8, 19))
	ITEM(Upp::EditDate, date2, LeftPosZ(212, 100).TopPosZ(8, 19))
	ITEM(Upp::Label, dv___3, SetLabel(t_("Date 2")).LeftPosZ(168, 40).TopPosZ(8, 19))
	ITEM(Upp::Label, result, LeftPosZ(8, 304).TopPosZ(36, 19))
END_LAYOUT


which definitely can be and often is edited as text, but with a bit of macro trickery is actually possible input for C++ compiler.

So no, no external files, layouts are C++ code.
Re: Layout files versus embedded code [message #59639 is a reply to message #59627] Sun, 19 February 2023 17:39 Go to previous messageGo to next message
MrAndreas is currently offline  MrAndreas
Messages: 2
Registered: February 2023
Junior Member
Thank you for clarifying this.

The fact that U++ uses C++ code for layout definitions is a huge advantage over most other solutions.
Re: Layout files versus embedded code [message #59642 is a reply to message #59639] Sun, 19 February 2023 18:57 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
MrAndreas wrote on Sun, 19 February 2023 17:39
Thank you for clarifying this.

The fact that U++ uses C++ code for layout definitions is a huge advantage over most other solutions.


It gets even better - same is true for images (icons) Smile These are simply embedded as C++ code as well.

Mirek
Previous Topic: Add a new build method
Next Topic: Newbie questions
Goto Forum:
  


Current Time: Fri Apr 19 12:37:48 CEST 2024

Total time taken to generate the page: 0.05930 seconds