123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- /*
- * Part of LaGUI demonstration programs
- * Copyright (C) 2022-2023 Wu Yiming
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- #include "la_5.h"
- extern LA MAIN;
- typedef struct My{
- int _pad;
- laSafeString* Name;
- int Age;
- int Gender;
- real Height;
- } My;
- My Stats;
- void* myget_Stats(void* unused, void* unused1){
- return &Stats;
- }
- int INV_ShowMyStats(laOperator* a, laEvent* e){
- My* stats=a->This?a->This->EndInstance:0;
- if(!stats){
- printf("Operator not invoked from property.\n");
- return LA_FINISHED;
- }
- char* name=(stats->Name&&stats->Name->Ptr)?stats->Name->Ptr:"";
- printf("Hi! My name is %s and I'm %d years old :D\n",name,stats->Age);
- logPrint("Hi! My name is %s and I'm %d years old :D\n",name,stats->Age);
- return LA_FINISHED;
- }
- void MyProperties(laUiList *uil, laPropPack *This, laPropPack *DetachedProps, laColumn *UNUSED, int context){
- laColumn* c=laFirstColumn(uil);
- laShowLabel(uil,c,"Hello world!",0,0);
- laShowItem(uil,c,0,"me.name");
- laShowItem(uil,c,0,"me.age");
- laShowItem(uil,c,0,"me.height");
- laShowItem(uil,c,0,"me.gender");
- laShowLabel(uil,c," ",0,0);
- laUiItem* collection=laShowItem(uil,c,0,"me");
- laShowItem(uil,c,&collection->PP,"show");
- laShowItem(uil,c,0,"MY_show_my_stats");
- }
- int main(int argc, char *argv[]){
- laGetReady();
- Stats.Age=25;
- Stats.Gender=0;
- Stats.Height=1.76;
- strSafeSet(&Stats.Name,"ChengduLittleA");
- laCreateOperatorType("MY_show_my_stats", "Show Stats!", "Shoy my stats!",0,0,0,INV_ShowMyStats,0,0,0);
- laPropContainer* root=laDefineRoot();
- laAddSubGroup(root,"me","Me","Me root", "my", 0,0,0,0,myget_Stats,0,0,0,0,0,0,0);
- laPropContainer* my=laAddPropertyContainer("my", "My", "Struct My",0,0,0,0,0,LA_PROP_OTHER_ALLOC);
- laAddStringProperty(my, "name", "Name", "My name",0,0,0,0,1,offsetof(My,Name),0,0,0,0,0);
- laAddIntProperty(my, "age", "Age", "My age",0,0,"years old",100,0,1,25,0,offsetof(My,Age),0,0,0,0,0,0,0,0,0,0,0);
- laAddFloatProperty(my, "height", "Height", "My height",0,0,"cm",2,0.3,0.01,1.76,0,offsetof(My,Height),0,0,0,0,0,0,0,0,0,0,0);
- laProp* ep=laAddEnumProperty(my, "gender","Gender","My gender",0,0,0,0,0,offsetof(My,Gender),0,0,0,0,0,0,0,0,0,0);
- laAddEnumItemAs(ep,"MALE","Male","Gender being male",0,L'♂');
- laAddEnumItemAs(ep,"FEMALE","female","Gender being female",1,L'♀');
- laAddOperatorProperty(my, "show", "Show Stats with *This","Show stats called from \"my\" container","MY_show_my_stats",0,0);
- laRegisterUiTemplate("my_properties","Properties", MyProperties,0,0,"Demonstration", 0,0,0);
- // Uncomment this to load preferences.
- // laEnsureUserPreferences();
- if(!MAIN.Windows.pFirst){
- laWindow* w = laDesignWindow(-1,-1,600,600);
- laLayout* l = laDesignLayout(w,"My Layout");
- laCreatePanel(l->FirstBlock,"my_properties");
- laStartWindow(w);
- }
- laMainLoop();
- }
|