Home » Community » Newbie corner » Layout files versus embedded code
Layout files versus embedded code [message #59621] |
Fri, 17 February 2023 14:25  |
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   |
 |
mirek
Messages: 14255 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.
|
|
|
|
|
Goto Forum:
Current Time: Fri Apr 25 12:20:04 CEST 2025
Total time taken to generate the page: 0.00570 seconds
|