*/}}

simple_properties.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * Part of LaGUI demonstration programs
  3. * Copyright (C) 2022-2023 Wu Yiming
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include "la_5.h"
  19. extern LA MAIN;
  20. typedef struct My{
  21. int _pad;
  22. laSafeString* Name;
  23. int Age;
  24. int Gender;
  25. real Height;
  26. } My;
  27. My Stats;
  28. void* myget_Stats(void* unused, void* unused1){
  29. return &Stats;
  30. }
  31. int INV_ShowMyStats(laOperator* a, laEvent* e){
  32. My* stats=a->This?a->This->EndInstance:0;
  33. if(!stats){
  34. printf("Operator not invoked from property.\n");
  35. return LA_FINISHED;
  36. }
  37. char* name=(stats->Name&&stats->Name->Ptr)?stats->Name->Ptr:"";
  38. printf("Hi! My name is %s and I'm %d years old :D\n",name,stats->Age);
  39. logPrint("Hi! My name is %s and I'm %d years old :D\n",name,stats->Age);
  40. return LA_FINISHED;
  41. }
  42. void MyProperties(laUiList *uil, laPropPack *This, laPropPack *DetachedProps, laColumn *UNUSED, int context){
  43. laColumn* c=laFirstColumn(uil);
  44. laShowLabel(uil,c,"Hello world!",0,0);
  45. laShowItem(uil,c,0,"me.name");
  46. laShowItem(uil,c,0,"me.age");
  47. laShowItem(uil,c,0,"me.height");
  48. laShowItem(uil,c,0,"me.gender");
  49. laShowLabel(uil,c," ",0,0);
  50. laUiItem* collection=laShowItem(uil,c,0,"me");
  51. laShowItem(uil,c,&collection->PP,"show");
  52. laShowItem(uil,c,0,"MY_show_my_stats");
  53. }
  54. int main(int argc, char *argv[]){
  55. laGetReady();
  56. Stats.Age=25;
  57. Stats.Gender=0;
  58. Stats.Height=1.76;
  59. strSafeSet(&Stats.Name,"ChengduLittleA");
  60. laCreateOperatorType("MY_show_my_stats", "Show Stats!", "Shoy my stats!",0,0,0,INV_ShowMyStats,0,0,0);
  61. laPropContainer* root=laDefineRoot();
  62. laAddSubGroup(root,"me","Me","Me root", "my", 0,0,0,0,myget_Stats,0,0,0,0,0,0,0);
  63. laPropContainer* my=laAddPropertyContainer("my", "My", "Struct My",0,0,0,0,0,LA_PROP_OTHER_ALLOC);
  64. laAddStringProperty(my, "name", "Name", "My name",0,0,0,0,1,offsetof(My,Name),0,0,0,0,0);
  65. 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);
  66. 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);
  67. 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);
  68. laAddEnumItemAs(ep,"MALE","Male","Gender being male",0,L'♂');
  69. laAddEnumItemAs(ep,"FEMALE","female","Gender being female",1,L'♀');
  70. laAddOperatorProperty(my, "show", "Show Stats with *This","Show stats called from \"my\" container","MY_show_my_stats",0,0);
  71. laRegisterUiTemplate("my_properties","Properties", MyProperties,0,0,"Demonstration", 0,0,0);
  72. // Uncomment this to load preferences.
  73. // laEnsureUserPreferences();
  74. if(!MAIN.Windows.pFirst){
  75. laWindow* w = laDesignWindow(-1,-1,600,600);
  76. laLayout* l = laDesignLayout(w,"My Layout");
  77. laCreatePanel(l->FirstBlock,"my_properties");
  78. laStartWindow(w);
  79. }
  80. laMainLoop();
  81. }