-
Notifications
You must be signed in to change notification settings - Fork 0
Tutorial
TREE is the library. The library itself has a little bit of initialization that needs to be completed before it can be fully functional. Always call TREE_Init(); before using the library, and always call TREE_Free(); when done using the library.
Setup:
TREE_Result result;
result = TREE_Init();
if (result)
{
printf("Failed to initialize TREE: %s\n", TREE_Result_ToString(result));
return 1;
}
Teardown:
TREE_Free();
A Theme is required to define how Controls are drawn, including characters and colors. When a Theme is initialized, it loads the hard coded default values. These can be modified to fit your needs.
Setup:
...
// create the Theme
TREE_Theme theme;
result = TREE_Theme_Init(&theme);
if (result)
{
printf("Failed to initialize theme: %s\n", TREE_Result_ToString(result));
return 1;
}
Teardown:
TREE_Theme_Free(&theme);
...
Applications are not required, but are very useful for creating a quick application with some window-styled functionality. Applications allow for a number of controls, which are intractable elements that provide different sorts of functionality.
Setup:
...
// create the Application
TREE_Application app;
result = TREE_Application_Init(&app, &surface, 32, ApplicationEventHandler);
if (result)
{
printf("Failed to initialize application: %s\n", TREE_Result_ToString(result));
return 1;
}
Teardown:
TREE_Application_Free(&app);
...
Controls are individual components that can be added to an Application, such as a Button, Label, Dropdown, TextInput, List, etc. Most can be focused, meaning that they can be navigated to and interacted with. Typically, those Controls allow for events to be run based on those interactions, such as OnSubmit, OnChange, etc. These event functions, however, are all optional, and can be NULL.
Labels are a very simple control that shows text, and nothing else. They, however, can be aligned in different ways. By default, labels are word wrapped, and aligned to the top left.
Setup:
...
// create label data
TREE_Control_LabelData labelData;
result = TREE_Control_LabelData_Init(&labelData, "Checkboxes:");
if (result)
{
printf("Failed to initialize label data: %s\n", TREE_Result_ToString(result));
return 1;
}
// create label
TREE_Control label;
result = TREE_Control_Label_Init(&label, NULL, &labelData);
if (result)
{
printf("Failed to initialize label: %s\n", TREE_Result_ToString(result));
return 1;
}
Teardown:
TREE_Control_LabelData_Free(&labelData);
TREE_Control_Free(&label);
...
Buttons are a Control that is able to be clicked and run an event. They contain a label which is center middle aligned. The value argument of the OnSubmit function will always be NULL for Buttons.
Setup:
void Button_OnSubmit(void* sender, void const* value)
{
// run your code here...
}
...
// create button data
TREE_Control_ButtonData buttonData;
result = TREE_Control_ButtonData_Init(&buttonData, "Button", Button_OnSubmit, &theme);
if (result)
{
printf("Failed to initialize button data: %s\n", TREE_Result_ToString(result));
return 1;
}
// create button
TREE_Control button;
result = TREE_Control_Button_Init(&button, NULL, &buttonData);
if(result)
{
printf("Failed to initialize button: %s\n", TREE_Result_ToString(result));
return 1;
}
Teardown:
TREE_Control_ButtonData_Free(&buttonData);
TREE_Control_Free(&button);
...
I will add the rest of the contents for the Tutorial as soon as I am able!