Skip to content

Latest commit

 

History

History
173 lines (131 loc) · 4.78 KB

nappgui-gui-sdk-c.md

File metadata and controls

173 lines (131 loc) · 4.78 KB

NAppGUI - Cross-Platform C SDK

A toolkit for building portable desktop applications for Windows, macOS and Linux using C programming language.

Overview

Setting Up the Development Environment

Required System Libraries

For Debian/Debian-variant Linux systems, install the following dependencies:

sudo apt install libgtk-3-dev libcurl4-openssl-dev libwebkit2gtk-4.1-dev mesa-common-dev libgl1-mesa-dev

Installing NAppGUI SDK

  1. Download the source code:

    cd ~/
    git clone --depth 1 https://github.com/frang75/nappgui_src.git
    cd nappgui_src
  2. Build and install as a static library:

    cmake -S . -B build -DNAPPGUI_DEMO=NO -DCMAKE_BUILD_TYPE=Release
    cmake --build build -j 4
    sudo cmake --install build --config Release --prefix /usr/local/nappgui
  3. Clean up the source files:

    rm -rf ~/nappgui_src

Creating Your First Application

  1. Create a new project directory:

    mkdir nappgui_test
    cd nappgui_test
  2. Create CMakeLists.txt with the following contents:

    cmake_minimum_required(VERSION 3.0)
    project(NAppHello)
    find_package(nappgui REQUIRED)
    include("${NAPPGUI_ROOT_PATH}/prj/NAppProject.cmake")
    include("${NAPPGUI_ROOT_PATH}/prj/NAppCompilers.cmake")
    nap_config_compiler()
    nap_project_desktop_app(NAppHello hello)
  3. Create main.c with the example code for a simple GUI application (see below).

  4. Build your application:

    cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
    cmake --build build
  5. Run the application:

    cd build/Release/bin
    ./NAppHello

Image

Example Application Code

Here's a simple "Hello World" application that demonstrates basic NAppGUI functionality:

#include <nappgui.h>

typedef struct _app_t App;

struct _app_t
{
    Window *window;
    TextView *text;
    uint32_t clicks;
};

static void i_OnButton(App *app, Event *e)
{
    textview_printf(app->text, "Button click (%d)\n", app->clicks);
    app->clicks += 1;
    unref(e);
}

static Panel *i_panel(App *app)
{
    Panel *panel = panel_create();
    Layout *layout = layout_create(1, 3);
    Label *label = label_create();
    Button *button = button_push();
    TextView *text = textview_create();

    app->text = text;
    label_text(label, "Hello!, I'm a label");
    button_text(button, "Click Me!");
    button_OnClick(button, listener(app, i_OnButton, App));

    layout_label(layout, label, 0, 0);
    layout_button(layout, button, 0, 1);
    layout_textview(layout, text, 0, 2);
    layout_hsize(layout, 0, 250);
    layout_vsize(layout, 2, 100);
    layout_margin(layout, 5);
    layout_vmargin(layout, 0, 5);
    layout_vmargin(layout, 1, 5);

    panel_layout(panel, layout);
    return panel;
}

static void i_OnClose(App *app, Event *e)
{
    osapp_finish();
    unref(app);
    unref(e);
}

static App *i_create(void)
{
    App *app = heap_new0(App);
    Panel *panel = i_panel(app);
    app->window = window_create(ekWINDOW_STD);
    window_panel(app->window, panel);
    window_title(app->window, "Hello, World!");
    window_origin(app->window, v2df(500, 200));
    window_OnClose(app->window, listener(app, i_OnClose, App));
    window_show(app->window);
    return app;
}

static void i_destroy(App **app)
{
    window_destroy(&(*app)->window);
    heap_delete(app, App);
}

#include <osapp/osmain.h>
osmain(i_create, i_destroy, "", App)

This example creates a window with a label, button, and text view. The button click counter demonstrates basic event handling and GUI updates.

Create every reference GUI example application that the SDK provides:

cd ~/
git clone --depth 1 https://github.com/frang75/nappgui_src.git
cd nappgui_src
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build -j 4