*/}}
Browse Source

better property examples

YimingWu 1 year ago
parent
commit
f75585374d
2 changed files with 25 additions and 1 deletions
  1. 5 1
      example_viewer.c
  2. 20 0
      simple_properties.c

+ 5 - 1
example_viewer.c

@@ -148,7 +148,10 @@ void ui_Operator(laUiList *uil, laPropPack *This, laPropPack *DetachedProps, laC
     laShowLabel(uil,c,"\n\
     laShowLabel(uil,c,"\n\
 Operator demonstration program\n\
 Operator demonstration program\n\
 ------------------------------\n\
 ------------------------------\n\
-    Press the \"Something!\" Button to invoke a one-time operator, you can see some strings printed on stdout and LaGUI Terminal.\n\
+    1) Press the \"Something!\" Button to invoke a one-time operator, you can see some strings printed on stdout and LaGUI Terminal.\n\
+    2) Press the \"Modal!\" Button to invoke a modal operator, the operator would keep printing out pointer coordinates as you move the mouse\
+while the user interface is kept from getting input events.\n\
+    3) Use right mouse button to exit the modal operator.\n\
     Use 🞆->Terminal to show LaGUI Terminal.",0,0)->Flags|=LA_TEXT_LINE_WRAP|LA_TEXT_MONO;
     Use 🞆->Terminal to show LaGUI Terminal.",0,0)->Flags|=LA_TEXT_LINE_WRAP|LA_TEXT_MONO;
 
 
     EXAMPLE_COMMON_END
     EXAMPLE_COMMON_END
@@ -168,6 +171,7 @@ Play with this demo:\n\
     2) You can right click them for extra opeartions.\n\
     2) You can right click them for extra opeartions.\n\
     3) Create a new \"Properties\" panel from the 🞆 button, \
     3) Create a new \"Properties\" panel from the 🞆 button, \
 verify that adjustiing values in either panels would cause the other panel to refresh in sync.\n\
 verify that adjustiing values in either panels would cause the other panel to refresh in sync.\n\
+    4) Test invoking a operator from property.\n\
     ",0,0)->Flags|=LA_TEXT_LINE_WRAP|LA_TEXT_MONO;
     ",0,0)->Flags|=LA_TEXT_LINE_WRAP|LA_TEXT_MONO;
 
 
     EXAMPLE_COMMON_END
     EXAMPLE_COMMON_END

+ 20 - 0
simple_properties.c

@@ -33,6 +33,18 @@ void* myget_Stats(void* unused, void* unused1){
     return &Stats;
     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){
 void MyProperties(laUiList *uil, laPropPack *This, laPropPack *DetachedProps, laColumn *UNUSED, int context){
     laColumn* c=laFirstColumn(uil);
     laColumn* c=laFirstColumn(uil);
     laShowLabel(uil,c,"Hello world!",0,0);
     laShowLabel(uil,c,"Hello world!",0,0);
@@ -40,6 +52,11 @@ void MyProperties(laUiList *uil, laPropPack *This, laPropPack *DetachedProps, la
     laShowItem(uil,c,0,"me.age");
     laShowItem(uil,c,0,"me.age");
     laShowItem(uil,c,0,"me.height");
     laShowItem(uil,c,0,"me.height");
     laShowItem(uil,c,0,"me.gender");
     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[]){
 int main(int argc, char *argv[]){
@@ -50,6 +67,8 @@ int main(int argc, char *argv[]){
     Stats.Height=1.76;
     Stats.Height=1.76;
     strSafeSet(&Stats.Name,"ChengduLittleA");
     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();
     laPropContainer* root=laDefineRoot();
     laAddSubGroup(root,"me","Me","Me root", "my", 0,0,0,0,myget_Stats,0,0,0,0,0,0,0);
     laAddSubGroup(root,"me","Me","Me root", "my", 0,0,0,0,myget_Stats,0,0,0,0,0,0,0);
 
 
@@ -60,6 +79,7 @@ int main(int argc, char *argv[]){
     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);
     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,"MALE","Male","Gender being male",0,L'♂');
     laAddEnumItemAs(ep,"FEMALE","female","Gender being female",1,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);
     laRegisterUiTemplate("my_properties","Properties", MyProperties,0,0,"Demonstration", 0,0,0);