*/}}

simple_properties.c 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. void MyProperties(laUiList *uil, laPropPack *This, laPropPack *DetachedProps, laColumn *UNUSED, int context){
  32. laColumn* c=laFirstColumn(uil);
  33. laShowLabel(uil,c,"Hello world!",0,0);
  34. laShowItem(uil,c,0,"me.name");
  35. laShowItem(uil,c,0,"me.age");
  36. laShowItem(uil,c,0,"me.height");
  37. laShowItem(uil,c,0,"me.gender");
  38. }
  39. int main(int argc, char *argv[]){
  40. laGetReady();
  41. Stats.Age=25;
  42. Stats.Gender=0;
  43. Stats.Height=1.76;
  44. strSafeSet(&Stats.Name,"ChengduLittleA");
  45. laPropContainer* root=laDefineRoot();
  46. laAddSubGroup(root,"me","Me","Me root", "my", 0,0,0,0,myget_Stats,0,0,0,0,0,0,0);
  47. laPropContainer* my=laAddPropertyContainer("my", "My", "Struct My",0,0,0,0,0,LA_PROP_OTHER_ALLOC);
  48. laAddStringProperty(my, "name", "Name", "My name",0,0,0,0,1,offsetof(My,Name),0,0,0,0,0);
  49. 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);
  50. 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);
  51. 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);
  52. laAddEnumItemAs(ep,"MALE","Male","Gender being male",0,L'♂');
  53. laAddEnumItemAs(ep,"FEMALE","female","Gender being female",1,L'♀');
  54. laRegisterUiTemplate("my_properties","Properties", MyProperties,0,0,"Demonstration", 0,0,0);
  55. // Uncomment this to load preferences.
  56. // laEnsureUserPreferences();
  57. if(!MAIN.Windows.pFirst){
  58. laWindow* w = laDesignWindow(-1,-1,600,600);
  59. laLayout* l = laDesignLayout(w,"My Layout");
  60. laCreatePanel(l->FirstBlock,"my_properties");
  61. laStartWindow(w);
  62. }
  63. laMainLoop();
  64. }