*/}}
Yiming Wu 2 rokov pred
rodič
commit
193ba815e7
5 zmenil súbory, kde vykonal 226 pridanie a 35 odobranie
  1. 18 30
      CMakeLists.txt
  2. 42 4
      example_viewer.c
  3. 0 1
      simplest.c
  4. 111 0
      widget_flags.c
  5. 55 0
      widgets.c

+ 18 - 30
CMakeLists.txt

@@ -9,50 +9,38 @@ include_directories(
 
 add_definitions(-w)
 
-set(SimplestFiles 
-    ${CMAKE_SOURCE_DIR}/simplest.c
-)
-set(FruitsFiles 
-    ${CMAKE_SOURCE_DIR}/fruits.c
-)
-set(ModellingFiles 
-    ${CMAKE_SOURCE_DIR}/modelling_main.c
-)
-set(CalculatorFiles 
-    ${CMAKE_SOURCE_DIR}/calculator.c
-)
+set(SimplestFiles ${CMAKE_SOURCE_DIR}/simplest.c)
+set(WidgetsFiles ${CMAKE_SOURCE_DIR}/widgets.c)
+set(WidgetFlagsFiles ${CMAKE_SOURCE_DIR}/widget_flags.c)
+set(FruitsFiles ${CMAKE_SOURCE_DIR}/fruits.c)
+set(ModellingFiles ${CMAKE_SOURCE_DIR}/modelling_main.c)
+set(CalculatorFiles ${CMAKE_SOURCE_DIR}/calculator.c)
 
-set(ExampleViewerFiles 
-    ${CMAKE_SOURCE_DIR}/example_viewer.c
-)
+set(ExampleViewerFiles ${CMAKE_SOURCE_DIR}/example_viewer.c)
 
 add_executable(simplest ${SimplestFiles})
+add_executable(widgets ${WidgetsFiles})
+add_executable(widget_flags ${WidgetFlagsFiles})
 add_executable(fruits ${FruitsFiles})
 add_executable(modelling_main ${ModellingFiles})
 add_executable(calculator ${CalculatorFiles})
 add_executable(example_viewer ${ExampleViewerFiles})
 
-target_link_libraries(simplest
-    ${LAGUI_SHARED_LIBS}
-)
-target_link_libraries(fruits
-    ${LAGUI_SHARED_LIBS}
-)
-target_link_libraries(modelling_main
-    ${LAGUI_SHARED_LIBS}
-)
-target_link_libraries(calculator
-    ${LAGUI_SHARED_LIBS}
-)
+target_link_libraries(simplest ${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} )
+target_link_libraries(modelling_main ${LAGUI_SHARED_LIBS} )
+target_link_libraries(calculator ${LAGUI_SHARED_LIBS} )
 
-target_link_libraries(example_viewer
-    ${LAGUI_SHARED_LIBS}
-)
+target_link_libraries(example_viewer ${LAGUI_SHARED_LIBS} )
 
 add_custom_command(
     TARGET example_viewer POST_BUILD
     COMMAND mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/example_source_files
     COMMAND cp ${CMAKE_SOURCE_DIR}/calculator.c     ${CMAKE_CURRENT_BINARY_DIR}/example_source_files/calculator.c
+    COMMAND cp ${CMAKE_SOURCE_DIR}/widgets.c        ${CMAKE_CURRENT_BINARY_DIR}/example_source_files/widgets.c
+    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}/simplest.c       ${CMAKE_CURRENT_BINARY_DIR}/example_source_files/simplest.c)

+ 42 - 4
example_viewer.c

@@ -91,8 +91,6 @@ Play with this demo:\n\
     
     EXAMPLE_COMMON_END
 }
-
-
 void ui_Simplest(laUiList *uil, laPropPack *This, laPropPack *DetachedProps, laColumn *UNUSED, int context){
     EXAMPLE_COMMON_BEGIN
 
@@ -117,13 +115,47 @@ How do I begin?\n\
 To manipulate the layout:\n\
 -------------------------\n\
     1) You can dock panels by pressing the 🗖 button, then drop the panel to approperiate region.\n\
-    2) To tear down the panel, drag the panel title to the center of each region and release.\n\
+    2) To tear off a docked the panel, drag the panel title to the center of each region and release.\n\
     3) You could maximize a region by clicking ⯆ on the top left of each region and select approperiate operations.\n\
     4) You can also use 🗗 button on the top to create a new window/layout, then dock some new panels there to customize your workspace.\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
+
+    laShowLabel(uil,c,"\
+This demo shows commom widgets inside LaGUI.\n\
+\n\
+What you need to know about widgets in LaGUI:\n\
+---------------------------------------------\n\
+    1) Except labels, you need a data source (a defined property in LaGUI) to show any other kind of widget.\n\
+    2) To show a button, you need to define an operator, and an operator is basically what you trigger an action with.\n\
+    3) A widget can have multiple style/looks controlled by mainly `ui->Flags`. Some ui types accept extra instructions as a string, like you \
+could specify \"text=something;\" to a button.\n\
+    4) You could arrange widgets in a columns or rows, also with groups and tabs. Currently, group/subprop widgets can not be used inside a row.\n\
+    5) Canvas widgets are drawn on their own offscreen buffers. They can also be customized to have your own drawing and event handling callbacks, \
+they can be set to display a certain property as well.\n\
+        ",0,0)->Flags|=LA_TEXT_LINE_WRAP|LA_TEXT_MONO;
+    
+    EXAMPLE_COMMON_END
+}
+void ui_WidgetFlags(laUiList *uil, laPropPack *This, laPropPack *DetachedProps, laColumn *UNUSED, int context){
+    EXAMPLE_COMMON_BEGIN
+
+    laShowLabel(uil,c,"\
+This demo shows most-used UI flags and their effects on widgets.\n\
+\n\
+When using widget creator like `laShowItem`, set ui->Flags to the combination of UI flags to adjust the look and interaction of the widget. \
+Not all UI flags are supported by every kind of widgets, but the most common ones can always be used, and widgets will just ignore unsupported \
+UI flags and won't generate any errors.\n\
+\n\
+Launch the program to see the effect of each UI flags.\
+        ",0,0)->Flags|=LA_TEXT_LINE_WRAP|LA_TEXT_MONO;
+    
+    EXAMPLE_COMMON_END
+}
 void ui_Calculator(laUiList *uil, laPropPack *This, laPropPack *DetachedProps, laColumn *UNUSED, int context){
     EXAMPLE_COMMON_BEGIN
 
@@ -181,7 +213,7 @@ int inv_OpenDemoSource(laOperator* a, laEvent* e){
 }
 
 
-laPropContainer *pcGeneric,*pcFruits,*pcSimplest,*pcModelling,*pcCalculator;
+laPropContainer *pcGeneric,*pcFruits,*pcSimplest,*pcModelling,*pcCalculator,*pcWidgets,*pcWidgetFlags;
 
 void* get_ExampleViewer(void* unused){
     return EV;
@@ -191,6 +223,8 @@ laPropContainer* get_ExamplesGetType(void* unused, ExampleItem* ei){
     if(ei->Define==ui_Simplest) return pcSimplest;
     if(ei->Define==ui_Modelling) return pcModelling;
     if(ei->Define==ui_Calculator) return pcCalculator;
+    if(ei->Define==ui_Widgets) return pcWidgets;
+    if(ei->Define==ui_WidgetFlags) return pcWidgetFlags;
     return pcGeneric;
 }
 void set_CurrentExample(ExampleViewer* v, ExampleItem* ei){
@@ -222,11 +256,15 @@ static void InitExamples(){
     
     EXAMPLE_ADD_PC("simplest",pcSimplest,ui_Simplest);
     EXAMPLE_ADD_PC("fruits",pcFruits,ui_Fruits);
+    EXAMPLE_ADD_PC("widgets",pcWidgets,ui_Widgets);
+    EXAMPLE_ADD_PC("widget_flags",pcWidgetFlags,ui_WidgetFlags);
     EXAMPLE_ADD_PC("calculator",pcCalculator,ui_Calculator);
     EXAMPLE_ADD_PC("modelling_main",pcModelling,ui_Modelling);
 
     EV=memAcquire(sizeof(ExampleViewer));
     AddExample("Simplest","simplest",ui_Simplest);
+    AddExample("Widgets","widgets",ui_Widgets);
+    AddExample("Widget Flags","widget_flags",ui_WidgetFlags);
     AddExample("Fruits","fruits",ui_Fruits);
     AddExample("Calculator","calculator",ui_Calculator);
     AddExample("Modelling","modelling_main",ui_Modelling);

+ 0 - 1
simplest.c

@@ -1,6 +1,5 @@
 #include "la_5.h"
 
-
 void MyPanel(laUiList *uil, laPropPack *This, laPropPack *DetachedProps, laColumn *UNUSED, int context){
     laColumn* c=laFirstColumn(uil);
     laShowLabel(uil,c,"Hello world!",0,0);

+ 111 - 0
widget_flags.c

@@ -0,0 +1,111 @@
+#include "la_5.h"
+
+#define SHOW_FLAG(what)\
+    laShowSeparator(uil,c); laShowLabel(uil,cl, #what ,0,0)->Flags|=LA_TEXT_MONO;
+#define BR b=laBeginRow(uil,cr,0,0);
+#define ER laEndRow(uil,b);
+
+void Widgets(laUiList *uil, laPropPack *This, laPropPack *DetachedProps, laColumn *UNUSED, int context){
+    laColumn* c=laFirstColumn(uil);
+    laColumn* cl,*cr;laSplitColumn(uil,c,0.3);cl=laLeftColumn(c,0);cr=laRightColumn(c,0);
+    laUiItem* b;
+
+    laShowColumnAdjuster(uil,c);
+    laShowLabel(uil,cl,"UI Flags",0,0); laShowLabel(uil,cr,"Description",0,0);
+
+    SHOW_FLAG(LA_UI_FLAGS_EXPAND);
+        laShowLabel(uil,cr,"Enum properties are shown with a menu.",0,0);
+        BR laShowItem(uil,cr,0,"la.user_preferences.panel_multisample"); ER
+        laShowLabel(uil,cr,"You can expand the enum selections by using this flag.",0,0);
+        BR laShowItem(uil,cr,0,"la.user_preferences.panel_multisample")->Flags|=LA_UI_FLAGS_EXPAND; ER
+    SHOW_FLAG(LA_UI_FLAGS_TRANSPOSE);
+        laShowLabel(uil,cr,"And you can also make the expansion vertical.",0,0);
+        laShowLabel(uil,cr,"This also applies to array values.",0,0);
+        BR laShowItem(uil,cr,0,"la.user_preferences.panel_multisample")->Flags|=LA_UI_FLAGS_TRANSPOSE|LA_UI_FLAGS_EXPAND; ER
+    SHOW_FLAG(LA_UI_FLAGS_ICON);
+        laShowLabel(uil,cr,"Buttons/Selectors typically show an icon and a name.",0,0);
+        BR laShowItem(uil,cr,0,"LA_pure_yes_no"); ER
+        laShowLabel(uil,cr,"You could choose to only show icons.",0,0);
+        BR laShowItem(uil,cr,0,"LA_pure_yes_no")->Flags|=LA_UI_FLAGS_ICON; ER
+    SHOW_FLAG(LA_UI_FLAGS_NO_DECAL);
+        laShowLabel(uil,cr,"This stops the UI from drawing background box.",0,0);
+        laShowLabel(uil,cr,"The UI will still accept user inputs.",0,0);
+        BR laShowItem(uil,cr,0,"la.user_preferences.interface_size"); laShowItem(uil,cr,0,"la.user_preferences.interface_size")->Flags|=LA_UI_FLAGS_NO_DECAL; ER
+        BR laShowItem(uil,cr,0,"la.user_preferences.panel_multisample"); laShowItem(uil,cr,0,"la.user_preferences.panel_multisample")->Flags|=LA_UI_FLAGS_NO_DECAL; ER
+    SHOW_FLAG(LA_UI_FLAGS_NO_EVENT);
+        laShowLabel(uil,cr,"This stops the UI from accepting user inputs.",0,0);
+        BR laShowItem(uil,cr,0,"la.user_preferences.interface_size")->Flags|=LA_UI_FLAGS_NO_EVENT; ER
+        BR laShowItem(uil,cr,0,"la.user_preferences.panel_multisample")->Flags|=LA_UI_FLAGS_NO_EVENT; ER
+    SHOW_FLAG(LA_UI_FLAGS_NO_CONFIRM);
+        laShowLabel(uil,cr,"This stops widgets from generating a confirm event when executed or values changed.",0,0)->Flags|=LA_TEXT_LINE_WRAP;
+    SHOW_FLAG(LA_TEXT_ALIGN_LEFT);
+        laShowLabel(uil,cr,"A lot of widgets supports text aligning flags, not just labels.",0,0);
+        laShowLabel(uil,cr,"Align left",0,0)->Flags|=LA_TEXT_ALIGN_LEFT;
+    SHOW_FLAG(LA_TEXT_ALIGN_CENTER);
+        laShowLabel(uil,cr,"Align center",0,0)->Flags|=LA_TEXT_ALIGN_CENTER;
+    SHOW_FLAG(LA_TEXT_ALIGN_RIGHT);
+        laShowLabel(uil,cr,"Align right",0,0)->Flags|=LA_TEXT_ALIGN_RIGHT;
+    SHOW_FLAG(LA_TEXT_ALIGN_AUTO);
+        laShowLabel(uil,cr,"Align auto",0,0)->Flags|=LA_TEXT_ALIGN_AUTO;
+    SHOW_FLAG(LA_TEXT_USE_NEWLINE);
+        laShowLabel(uil,cr,"Will use '\\n' in string properties and switch to a new line.",0,0);
+    SHOW_FLAG(LA_TEXT_LINE_WRAP);
+        laShowLabel(uil,cr,"Will use '\\n' in labels\n as well as wrapping the line.",0,0)->Flags|=LA_TEXT_LINE_WRAP;
+    SHOW_FLAG(LA_TEXT_REVERT_Y);
+        laShowLabel(uil,cr,"Text would be drawn up-size-down, convenient in different coordinate systems.",0,0)->Flags|=LA_TEXT_LINE_WRAP;
+        laShowLabel(uil,cr," ",0,0);
+        laShowLabel(uil,cr,"Just like this",0,0)->Flags|=LA_TEXT_REVERT_Y;
+    SHOW_FLAG(LA_TEXT_MONO);
+        laShowLabel(uil,cr,"Text would be in monospace font.",0,0);
+    SHOW_FLAG(LA_UI_FLAGS_PREFER_BOTTOM);
+        laShowLabel(uil,cr,"UI list would prefer to stay at the bottom.",0,0);
+        laShowLabel(uil,cr,"Resize the terminal window and see the effect.",0,0);
+        BR laShowItemFull(uil,cr,0,"LA_panel_activator",0,"panel_id=LAUI_terminal;text=Show Terminal",0,0); ER
+    SHOW_FLAG(LA_UI_FLAGS_NO_GAP);
+        laShowLabel(uil,cr,"Draw UI as if there's no gap between itself and its adjacent UI items.",0,0);
+        BR laShowItem(uil,cr,0,"LA_pure_yes_no"); ER
+        BR laShowItem(uil,cr,0,"LA_pure_yes_no")->Flags|=LA_UI_FLAGS_NO_GAP; laShowLabel(uil,cr,"  <-- Like this one",0,0); ER
+    SHOW_FLAG(LA_UI_FLAGS_UNDERNEATH);
+        laShowLabel(uil,cr,"Show this UI item as if it's underneath the next one.",0,0);
+        laShowLabel(uil,cr,"Under",0,0)->Flags|=LA_UI_FLAGS_UNDERNEATH;
+        laShowLabel(uil,cr,"--------- Over",0,0);
+    SHOW_FLAG(LA_UI_FLAGS_NO_HEIGHT);
+        laShowLabel(uil,cr,"Same as above, but also removes margins etc.",0,0);
+    SHOW_FLAG(LA_UI_FLAGS_NO_OVERLAY);
+        laShowLabel(uil,cr,"Hide UI overlays on top of a canvas widget",0,0);
+    SHOW_FLAG(LA_TEXT_OVERFLOW_ARROW);
+        laShowLabel(uil,cr,"Show an arrow in long string box",0,0);
+        BR laShowItem(uil,cr,0,"la.example_string")->Flags|=LA_TEXT_ONE_LINE|LA_TEXT_OVERFLOW_ARROW; ER
+    SHOW_FLAG(LA_UI_FLAGS_DISABLED);
+        laShowLabel(uil,cr,"Like this, also used on other widgets",0,0)->Flags|=LA_UI_FLAGS_DISABLED;
+    SHOW_FLAG(LA_UI_FLAGS_HIGHLIGHT);
+        laShowLabel(uil,cr,"Like this, also used on other widgets",0,0)->Flags|=LA_UI_FLAGS_HIGHLIGHT;
+    SHOW_FLAG(LA_UI_FLAGS_NODE_CONTAINER);
+        laShowLabel(uil,cr,"Set this UI as the node container",0,0);
+    SHOW_FLAG(LA_UI_COLLECTION_NO_HIGHLIGHT);
+        laShowLabel(uil,cr,"If this is a collection UI, then this stops it from showing the background of active element.",0,0)->Flags|=LA_TEXT_LINE_WRAP;
+    SHOW_FLAG(LA_TEXT_ONE_LINE);
+        laShowLabel(uil,cr,"Show string property values in one line, even if there's a '\\n'.",0,0)->Flags|=LA_TEXT_LINE_WRAP;
+    SHOW_FLAG(LA_UI_FLAGS_INT_ICON);
+        laShowLabel(uil,cr,"Show an int property as if its value is a unicode codepoint and display its corresponding glyph.'.",0,0)->Flags|=LA_TEXT_LINE_WRAP;
+    SHOW_FLAG(LA_UI_FLAGS_PLAIN);
+        laShowLabel(uil,cr,"LA_UI_FLAGS_NO_DECAL|LA_UI_FLAGS_NO_EVENT",0,0)->Flags|=LA_TEXT_MONO;
+    SHOW_FLAG(LA_UI_SOCKET_LABEL_N);
+        laShowLabel(uil,cr,"Set node socket label to north. Default not shown.",0,0);
+    SHOW_FLAG(LA_UI_SOCKET_LABEL_S);
+    SHOW_FLAG(LA_UI_SOCKET_LABEL_W);
+    SHOW_FLAG(LA_UI_SOCKET_LABEL_E);
+}
+
+int main(int argc, char *argv[]){
+    laGetReady();
+
+    laRegisterUiTemplate("my_widget_flags","Widget Flags", Widgets,0,0,"Demonstration");
+
+    laWindow* w = laDesignWindow(-1,-1,1000,600);
+    laLayout* l = laDesignLayout(w,"My Layout");
+    laCreatePanel(l->FirstBlock,"my_widget_flags");
+
+    laStartWindow(w);
+    laMainLoop();
+}

+ 55 - 0
widgets.c

@@ -0,0 +1,55 @@
+#include "la_5.h"
+
+void Widgets(laUiList *uil, laPropPack *This, laPropPack *DetachedProps, laColumn *UNUSED, int context){
+    laColumn* c=laFirstColumn(uil);
+    laColumn* cl,*cr;laSplitColumn(uil,c,0.5);cl=laLeftColumn(c,0);cr=laRightColumn(c,0);
+
+    laShowLabel(uil,c,"This is a label",0,0);
+    laShowLabel(uil,c,"This label is aligned to the center",0,0)->Flags|=LA_TEXT_ALIGN_CENTER;
+    laShowLabel(uil,c,"This label is aligned to the right",0,0)->Flags|=LA_TEXT_ALIGN_RIGHT;
+    laShowSeparator(uil,c);
+
+    laUiItem* b=laBeginRow(uil,c,0,0);
+    laShowLabel(uil,c,"This is a button:",0,0);
+    laShowItem(uil,c,0,"LA_pure_yes_no");
+    laEndRow(uil,b);
+    laShowSeparator(uil,c);
+
+    laUiItem* g=laMakeGroup(uil,cl,"Group",0); laUiList* gu=g->Page; laColumn* gc=laFirstColumn(gu);
+    laShowLabel(gu,gc,"Label inside a group",0,0);
+
+    g=laMakeTab(uil,cr,0);
+    gu=laAddTabPage(g,"Page1"); gc=laFirstColumn(gu);
+    laShowLabel(gu,gc,"Label 1 in tab",0,0);
+    laShowLabel(gu,gc,"Label 2 in tab",0,0);
+    gu=laAddTabPage(g,"Page2"); gc=laFirstColumn(gu);
+    laShowLabel(gu,gc,"Label 3 in tab",0,0);
+
+    laShowSeparator(uil,c);
+
+    laShowLabel(uil,c,"Below are some built-in example properties,\ntry changing the values in them:",0,0)->Flags|=LA_TEXT_LINE_WRAP;
+    laShowLabel(uil,cl,"Value slider:",0,0)->Flags|=LA_TEXT_ALIGN_RIGHT;  laShowItem(uil,cr,0,"la.example_int");
+    laShowLabel(uil,cl,"String editor:",0,0)->Flags|=LA_TEXT_ALIGN_RIGHT; laShowItem(uil,cr,0,"la.example_string")->Flags|=LA_TEXT_ONE_LINE;
+    laShowLabel(uil,cl,"Color picker:",0,0)->Flags|=LA_TEXT_ALIGN_RIGHT;  laShowItem(uil,cr,0,"la.themes.color");
+    laShowLabel(uil,cl,"Multi-line string:",0,0)->Flags|=LA_TEXT_ALIGN_RIGHT;
+    laShowItemFull(uil,cr,0,"la.example_string",LA_WIDGET_STRING_MULTI,0,0,0)->Extra->HeightCoeff=5;
+    laShowSeparator(uil,c);
+
+    laShowLabel(uil,cl,"This is a 3D viewer",0,0);
+    laShowCanvas(uil,cl,0,"tns.world","la_3DView",6);
+    laShowLabel(uil,cr,"And this is 2D",0,0);
+    laCanvasExtra*ce=laShowCanvas(uil,cr,0,"tns.texture_list",0,6)->Extra; ce->ZoomX=10; ce->ZoomY=10;
+}
+
+int main(int argc, char *argv[]){
+    laGetReady();
+
+    laRegisterUiTemplate("my_widgets","Widgets", Widgets,0,0,"Demonstration");
+
+    laWindow* w = laDesignWindow(-1,-1,400,800);
+    laLayout* l = laDesignLayout(w,"My Layout");
+    laCreatePanel(l->FirstBlock,"my_widgets");
+
+    laStartWindow(w);
+    laMainLoop();
+}