*/}}
ソースを参照

Two new demonstration programs

YimingWu 1 年間 前
コミット
217ffd77c6
4 ファイル変更192 行追加1 行削除
  1. 8 0
      CMakeLists.txt
  2. 39 1
      example_viewer.c
  3. 69 0
      operator.c
  4. 76 0
      simple_properties.c

+ 8 - 0
CMakeLists.txt

@@ -10,6 +10,8 @@ include_directories(
 add_definitions(-w)
 
 set(SimplestFiles ${CMAKE_SOURCE_DIR}/simplest.c)
+set(OperatorFiles ${CMAKE_SOURCE_DIR}/operator.c)
+set(SimplePropertiesFiles ${CMAKE_SOURCE_DIR}/simple_properties.c)
 set(WidgetsFiles ${CMAKE_SOURCE_DIR}/widgets.c)
 set(WidgetFlagsFiles ${CMAKE_SOURCE_DIR}/widget_flags.c)
 set(FruitsFiles ${CMAKE_SOURCE_DIR}/fruits.c)
@@ -19,6 +21,8 @@ set(CalculatorFiles ${CMAKE_SOURCE_DIR}/calculator.c)
 set(ExampleViewerFiles ${CMAKE_SOURCE_DIR}/example_viewer.c)
 
 add_executable(simplest ${SimplestFiles})
+add_executable(operator ${OperatorFiles})
+add_executable(simple_properties ${SimplePropertiesFiles})
 add_executable(widgets ${WidgetsFiles})
 add_executable(widget_flags ${WidgetFlagsFiles})
 add_executable(fruits ${FruitsFiles})
@@ -27,6 +31,8 @@ add_executable(calculator ${CalculatorFiles})
 add_executable(example_viewer ${ExampleViewerFiles})
 
 target_link_libraries(simplest ${LAGUI_SHARED_LIBS} )
+target_link_libraries(operator ${LAGUI_SHARED_LIBS} )
+target_link_libraries(simple_properties ${LAGUI_SHARED_LIBS} )
 target_link_libraries(widgets ${LAGUI_SHARED_LIBS} )
 target_link_libraries(widget_flags ${LAGUI_SHARED_LIBS} )
 target_link_libraries(fruits ${LAGUI_SHARED_LIBS} )
@@ -43,4 +49,6 @@ add_custom_command(
     COMMAND cp ${CMAKE_SOURCE_DIR}/widget_flags.c   ${CMAKE_CURRENT_BINARY_DIR}/example_source_files/widget_flags.c
     COMMAND cp ${CMAKE_SOURCE_DIR}/fruits.c         ${CMAKE_CURRENT_BINARY_DIR}/example_source_files/fruits.c
     COMMAND cp ${CMAKE_SOURCE_DIR}/modelling_main.c ${CMAKE_CURRENT_BINARY_DIR}/example_source_files/modelling_main.c
+    COMMAND cp ${CMAKE_SOURCE_DIR}/simple_properties.c ${CMAKE_CURRENT_BINARY_DIR}/example_source_files/simple_properties.c
+    COMMAND cp ${CMAKE_SOURCE_DIR}/operator.c       ${CMAKE_CURRENT_BINARY_DIR}/example_source_files/operator.c
     COMMAND cp ${CMAKE_SOURCE_DIR}/simplest.c       ${CMAKE_CURRENT_BINARY_DIR}/example_source_files/simplest.c)

+ 39 - 1
example_viewer.c

@@ -140,6 +140,38 @@ To manipulate the layout:\n\
 
     EXAMPLE_COMMON_END
 }
+void ui_Operator(laUiList *uil, laPropPack *This, laPropPack *DetachedProps, laColumn *UNUSED, int context){
+    EXAMPLE_COMMON_BEGIN
+
+    laColumn* c=laFirstColumn(uil);
+
+    laShowLabel(uil,c,"\n\
+Operator demonstration program\n\
+------------------------------\n\
+    Press the \"Something!\" Button to invoke a one-time operator, you can see some strings printed on stdout and LaGUI Terminal.\n\
+    Use 🞆->Terminal to show LaGUI Terminal.",0,0)->Flags|=LA_TEXT_LINE_WRAP|LA_TEXT_MONO;
+
+    EXAMPLE_COMMON_END
+}
+void ui_SimpleProperties(laUiList *uil, laPropPack *This, laPropPack *DetachedProps, laColumn *UNUSED, int context){
+    EXAMPLE_COMMON_BEGIN
+
+    laColumn* c=laFirstColumn(uil);
+
+    laShowLabel(uil,c,"\n\
+Properties demonstration program\n\
+--------------------------------\n\
+    The simplest program to demonstrate how to register properties for them to show on the interface.\n\n\
+Play with this demo:\n\
+--------------------\n\
+    1) You can manipulate the value widgets.\n\
+    2) You can right click them for extra opeartions.\n\
+    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\
+    ",0,0)->Flags|=LA_TEXT_LINE_WRAP|LA_TEXT_MONO;
+
+    EXAMPLE_COMMON_END
+}
 void ui_Widgets(laUiList *uil, laPropPack *This, laPropPack *DetachedProps, laColumn *UNUSED, int context){
     EXAMPLE_COMMON_BEGIN
 
@@ -231,7 +263,7 @@ int inv_OpenDemoSource(laOperator* a, laEvent* e){
 }
 
 
-laPropContainer *pcGeneric,*pcFruits,*pcSimplest,*pcModelling,*pcCalculator,*pcWidgets,*pcWidgetFlags;
+laPropContainer *pcGeneric,*pcFruits,*pcSimplest,*pcOperator,*pcSimpleProperties,*pcModelling,*pcCalculator,*pcWidgets,*pcWidgetFlags;
 
 void* get_ExampleViewer(void* unused){
     return EV;
@@ -239,6 +271,8 @@ void* get_ExampleViewer(void* unused){
 laPropContainer* get_ExamplesGetType(ExampleItem* ei){
     if(ei->Define==ui_Fruits) return pcFruits;
     if(ei->Define==ui_Simplest) return pcSimplest;
+    if(ei->Define==ui_Operator) return pcOperator;
+    if(ei->Define==ui_SimpleProperties) return pcSimpleProperties;
     if(ei->Define==ui_Modelling) return pcModelling;
     if(ei->Define==ui_Calculator) return pcCalculator;
     if(ei->Define==ui_Widgets) return pcWidgets;
@@ -273,6 +307,8 @@ static void InitExamples(){
     laAddStringProperty(pc,"code","Code","Code of the example",LA_WIDGET_STRING_MULTI,0,0,0,1,offsetof(ExampleItem,Code),0,0,0,0,LA_READ_ONLY);
     
     EXAMPLE_ADD_PC("simplest",pcSimplest,ui_Simplest);
+    EXAMPLE_ADD_PC("operator",pcOperator,ui_Operator);
+    EXAMPLE_ADD_PC("simple_properties",pcSimpleProperties,ui_SimpleProperties);
     EXAMPLE_ADD_PC("fruits",pcFruits,ui_Fruits);
     EXAMPLE_ADD_PC("widgets",pcWidgets,ui_Widgets);
     EXAMPLE_ADD_PC("widget_flags",pcWidgetFlags,ui_WidgetFlags);
@@ -281,6 +317,8 @@ static void InitExamples(){
 
     EV=memAcquire(sizeof(ExampleViewer));
     AddExample("Simplest","simplest",ui_Simplest);
+    AddExample("Operator","operator",ui_Operator);
+    AddExample("Simple Properties","simple_properties",ui_SimpleProperties);
     AddExample("Widgets","widgets",ui_Widgets);
     AddExample("Widget Flags","widget_flags",ui_WidgetFlags);
     AddExample("Fruits","fruits",ui_Fruits);

+ 69 - 0
operator.c

@@ -0,0 +1,69 @@
+/*
+* 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;
+
+int INV_MyOperator(laOperator* a, laEvent* e){
+    printf("Something happened in stdout!\n");
+    logPrint("Something happened in LaGUI terminal!\n");
+    return LA_FINISHED;
+}
+
+int INV_MyModalOperator(laOperator* a, laEvent* e){
+    printf("Modal opeator!\n");
+    logPrint("Modal opeator!\n");
+    return LA_RUNNING;
+}
+int MOD_MyModalOperator(laOperator* a, laEvent* e){
+    printf("%d,%d\n",e->x,e->y);
+    logPrint("%d,%d\n",e->x,e->y);
+    if(e->Type==LA_R_MOUSE_DOWN){
+        printf("Modal opeator finished!\n");
+        logPrint("Modal opeator finished!\n");
+        return LA_FINISHED;
+    }
+    return LA_RUNNING;
+}
+
+void MyPanel(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,"MY_invoke_test");
+    laShowItem(uil,c,0,"MY_modal_test");
+}
+
+int main(int argc, char *argv[]){
+    laGetReady();
+
+    laCreateOperatorType("MY_invoke_test", "Something!", "Print some strings.",0,0,0,INV_MyOperator,0,L'🗨',0);
+    laCreateOperatorType("MY_modal_test", "Modal!", "Print mouse positions.",0,0,0,INV_MyModalOperator,MOD_MyModalOperator,L'🏃',0);
+
+    laRegisterUiTemplate("my_panel","My Panel", MyPanel,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_panel");
+        laStartWindow(w);
+    }
+    laMainLoop();
+}

+ 76 - 0
simple_properties.c

@@ -0,0 +1,76 @@
+/*
+* 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;
+}
+
+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");
+}
+
+int main(int argc, char *argv[]){
+    laGetReady();
+
+    Stats.Age=25;
+    Stats.Gender=0;
+    Stats.Height=1.76;
+    strSafeSet(&Stats.Name,"ChengduLittleA");
+
+    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'♀');
+
+    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();
+}