xtd_c - Reference Guide 0.2.0
xtd_c - Reference Guide Documentation

C11 framework to create console, forms (GUI like WinForms) and unit test applications on Windows, macOS, Linux, iOS and android.

logo.png

Features

Free and open-source (MIT License); a collection of native C++ classes libraries, to complete std; API close to the .net API with a modern C++ approach and full integration with the std standard; xtd is designed to manage GUI controls and dialogs in pure native mode or with CSS styles. written in efficient, modern C++17 / C++20 with RAII programming idiom; and highly portable and available on many different platforms (Windows, macOS, Linux, iOS and android);

xtd libraries architecture

block_diagram_onion.png

xtd_c is composed of several libraries.

xtd_c.core

xtd_c.core.png

The xtd_c.core library is modern C++17/20 libraries of classes, interfaces, and value types that provide access to system functionality. It is the foundation on which c++ applications, components, and controls are built.

xtd_c.drawing

xtd_c.drawing.png

The xtd_c.drawing library contains types that support basic GDI+ graphics functionality. Child namespaces support advanced two-dimensional and vector graphics functionality, advanced imaging functionality, and print-related and typographical services. A child namespace also contains types that extend design-time user-interface logic and drawing.

xtd_c.forms

xtd_c.forms.png

The xtd_c.forms library contains classes for creating Windows-based applications that take full advantage of the rich user interface features available in the Microsoft Windows, Apple macOS and linux base operating system.

xtd_c.tunit

xtd_c.tunit.png

The xtd_c.tunit library is a unit-testing framework for modern C++17/20 inspired by Microsoft.VisualStudio.TestTools.Cpp.

Getting Started

Installation provides download, install and uninstall documentation. Guide provides xtd guides and tutorials. Examples provides some examples.

Examples

The classic first application 'Hello World'.

Console

hello_world_console.c:

CMakeLists.txt:

cmake_minimum_required(VERSION 3.3)
project(hello_world_console)
find_package(xtd_c REQUIRED)
add_sources(hello_world_console.c)
target_type(C_CONSOLE_APPLICATION)

Build and run

Open "Command Prompt" or "Terminal". Navigate to the folder that contains the project and type the following:

xtd_c run

Output

Hello, World!

Forms

hello_world_forms.c:

#include <xtd_c/xtd_c.h>
void on_button1_click(xtd_object* sender, xtd_event_args e) {
xtd_forms_message_box_show(NULL, "Hello, World!", "", xtd_forms_message_box_buttons_ok, xtd_forms_message_box_icon_none, xtd_forms_message_box_default_button_1, (xtd_forms_message_box_options)0, false);
}
int main(void) {
xtd_forms_control* form1 = xtd_forms_form_create();
xtd_forms_control_set_text(form1, "Hello world (message_box)");
xtd_forms_control* button1 = xtd_forms_button_create();
xtd_forms_control_set_location(button1, (xtd_drawing_point){.x = 10, .y = 10});
xtd_forms_control_set_text(button1, "&Click me");
xtd_forms_control_set_click_event(button1, &on_button1_click, NULL);
return EXIT_SUCCESS;
}

CMakeLists.txt:

cmake_minimum_required(VERSION 3.3)
project(hello_world_forms)
find_package(xtd_c REQUIRED)
add_sources(hello_world_forms.c)
target_type(C_GUI_APPLICATION)

Build and run

Open "Command Prompt" or "Terminal". Navigate to the folder that contains the project and type the following:

xtd_c run

Output

Windows:

hello_world_message_box_w.png


hello_world_message_box_wd.png

macOS:

hello_world_message_box_m.png


hello_world_message_box_md.png

Linux Gnome:

hello_world_message_box_g.png


hello_world_message_box_gd.png

Unit tests

hello_world_test.c:

#include <xtd_c/xtd_c.h>
#include <string.h>
void XTD_TUNIT_TEST(hello_world_test, create_string_from_literal) {
const char* s = "Hello, World!";
XTD_TUNIT_ASSERT_ARE_EQUAL("Hello, World!", s);
}
void XTD_TUNIT_TEST(hello_world_test, create_string_from_chars) {
const char s[14] = {'H', 'e', 'l', 'l', 'o', ',', ' ', 'W', 'o', 'r', 'l', 'd', '!', '\0'};
XTD_TUNIT_VALID_ARE_EQUAL(13, s.size());
XTD_TUNIT_STRING_ASSERT_STARTS_WIDTH("Hello,", s);
XTD_TUNIT_STRING_ASSERT_ENDS_WIDTH(" World!", s);
}
int main(void) {
return xtd_console_unit_test_run();
}

CMakeLists.txt:

cmake_minimum_required(VERSION 3.3)
project(hello_world_test)
find_package(xtd_c REQUIRED)
add_sources(hello_world_test.c)
target_type(C_TEST_APPLICATION)

Build and run

Open "Command Prompt" or "Terminal". Navigate to the folder that contains the project and type the following:

xtd_c run

Output

Start 2 tests from 1 test case
Run tests:
SUCCEED hello_world_test.create_string_from_literal (0 ms total)
SUCCEED hello_world_test.create_string_from_chars (0 ms total)
Test results:
SUCCEED 2 tests.
End 2 tests from 1 test case ran. (0 ms total)

See also

website wiki sources project Reference Guide