​
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;
​
Getting Started
​
-
Installation provides download and install documentation.
-
Guides provides xtd guides and tutorials.
-
Examples provides some examples.
​
Examples
​
The classic first application 'Hello World'.
​
Console
hello_world_console.cpp:
​
#include <xtd/xtd>
​
using namespace xtd;
​
int main() {
console::background_color(console_color::blue);
console::foreground_color(console_color::white);
console::write_line("Hello, World!");
}
​
CMakeLists.txt:
​
cmake_minimum_required(VERSION 3.3)
project(hello_world_console)
find_package(xtd REQUIRED)
add_sources(hello_world_console.cpp)
target_type(CONSOLE_APPLICATION)
​
Build and run
​
Open "Command Prompt" or "Terminal". Navigate to the folder that contains the project and type the following:
​
xtdc run
​
Output
​
Hello, World!
​
Gui
hello_world_forms.cpp:
​
#include <xtd/xtd>
​
using namespace xtd::forms;
auto main()->int {
auto main_form = form::create("Hello world (message_box)");
auto button1 = button::create(main_form, "&Click me", {10, 10});
button1.click += [] {message_box::show("Hello, World!");};
application::run(main_form);
}
​
CMakeLists.txt:
​
cmake_minimum_required(VERSION 3.3)
project(hello_world_forms)
find_package(xtd REQUIRED)
add_sources(hello_world_forms.cpp)
target_type(GUI_APPLICATION)
​
Build and run
​
Open "Command Prompt" or "Terminal". Navigate to the folder that contains the project and type the following:
​
xtdc run
​
Output
​
Windows:
​
![hello_world_message_box_w.png](https://static.wixstatic.com/media/24b851_ab333bddf5374a63bcd1ef79e6eaecf9~mv2.png/v1/fill/w_82,h_73,al_c,q_85,usm_0.66_1.00_0.01,blur_2,enc_auto/hello_world_message_box_w.png)
![hello_world_message_box_wd.png](https://static.wixstatic.com/media/24b851_1fa22172be1943478d5f45cc473efa14~mv2.png/v1/fill/w_86,h_73,al_c,q_85,usm_0.66_1.00_0.01,blur_2,enc_auto/hello_world_message_box_wd.png)
macOS:
​
![hello_world_message_box_m.png](https://static.wixstatic.com/media/24b851_c2dba419c3154eb7a0585e12e96b4f9e~mv2.png/v1/fill/w_51,h_30,al_c,q_85,usm_0.66_1.00_0.01,blur_2,enc_auto/hello_world_message_box_m.png)
![hello_world_message_box_md.png](https://static.wixstatic.com/media/24b851_d49eb8e40ea749489873c7a41b72101b~mv2.png/v1/fill/w_50,h_29,al_c,q_85,usm_0.66_1.00_0.01,blur_2,enc_auto/hello_world_message_box_md.png)
Linux Gnome:
​
![hello_world_message_box_g.png](https://static.wixstatic.com/media/24b851_4725bb2e553946159be66502baa166b0~mv2.png/v1/fill/w_87,h_75,al_c,q_85,usm_0.66_1.00_0.01,blur_2,enc_auto/hello_world_message_box_g.png)
![hello_world_message_box_gd.png](https://static.wixstatic.com/media/24b851_c2e959b703714b21babfb139a4a0e265~mv2.png/v1/fill/w_88,h_75,al_c,q_85,usm_0.66_1.00_0.01,blur_2,enc_auto/hello_world_message_box_gd.png)
​
Unit test
hello_world_test.cpp:
​
#include <xtd/xtd>
#include <string>
using namespace std;
using namespace xtd::tunit;
namespace unit_tests {
class test_class_(hello_world_test) {
public:
void test_method_(create_string_from_literal) {
string s = "Hello, World!";
valid::are_equal(13, s.size());
assert::are_equal("Hello, World!", s);
}
void test_method_(create_string_from_chars) {
string s = {'H', 'e', 'l', 'l', 'o', ',', ' ', 'W', 'o', 'r', 'l', 'd', '!'};
valid::are_equal(13, s.size());
string_assert::starts_with("Hello,", s);
string_assert::ends_with(" World!", s);
}
};
}
int main() {
return console_unit_test().run();
}
​
CMakeLists.txt:
​
cmake_minimum_required(VERSION 3.3)
project(hello_world_test)
find_package(xtd REQUIRED)
add_sources(hello_world_test.cpp)
target_type(TEST_APPLICATION)
​
Build and run
​
Open "Command Prompt" or "Terminal". Navigate to the folder that contains the project and type the following:
​
xtdc 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)