Creating a New GUI Application From Scratch

Last modified by Microchip on 2025/07/14 12:57

Introduction

This user guide provides information on how to create a new Microchip Graphics Suite (MGS) Graphical User Interface (GUI) application from scratch.

Directory Structure

The SDK's directory structure is as follows:

File/DirectorySub-FolderDescription
CMakeLists.txt CMake configuration file
apps Contains the MGS Quickstart and demo applications
gfx Contains the MGS graphics library 
system Contains the platform-specific library and interface code
/gfxCross-platform versions of certain MGS library middleware
/linuxInterface code for Linux®-based platforms

Adding a New Application

To add a new MGS application to the SDK, the application folder must be created in the apps/ directory. For example, to create a new application named "mynewapp":

cd <mgs_xp>
mkdir -p apps/mynewapp

Back to Top


In the application folder, add the app and gfx subfolders.

mkdir -p apps/mynewapp/gfx
mkdir -p apps/mynewapp/app

These subdirectories will contain the following:

apps/ subfolderDescription
gfxWill contain the MGS Composer-generated code
appWill contain the application code, like the screen and widget event callbacks and other application-specific code

Back to Top


Next, create a main.c file for the new application. The quick way to do this is to copy the existing main.c from the MGS Quickstart application to the new application folder.

cp apps/quickstart/main.c apps/mynewapp/

Back to Top


Then, add the CMake configuration file for the new application. You can create a new CMakeLists.txt file or copy and modify the one from the MGS Quickstart application example.

cp apps/quickstart/CMakeLists.txt apps/mynewapp/

Back to Top


Modify the CMakeLists.txt file and change mgs_quickstart to the new application name, mynewapp.

vi apps/mynewapp/CMakeLists.txt

CMakeLists.txt changes

Back to Top


Next, update the root CMakeLists.txt file to include the new application to the build.

vi CMakeLists.txt

CMakeLists.txt changes 2

Back to Top

Creating a New MGS Composer Project

The next step is to create a new MGS Composer project.

First, launch MGS Composer using the steps in the user guide

Back to Top


Use the New Project Wizard to create a New Project.

MGS Composer New Project Wizard

Back to Top


Set the project configuration.

MGS Composer New Project Configuration
A. Template: Clean Design if starting from a blank screen, or select Quickstart to start with a simple GUI design.

B. Display Resolution: Select a preset resolution or manually set the display width and height.

C. Color Mode: Use RGB565 for 16-bit colors, or RGBA8888 for 32-bit colors with alpha. 

D. Memory Profile: Select MPU for embedded Linux devices. This will configure the memory pools and scratch buffer for MPUs.

E. Create: Click to create the new design.

Back to Top

Quickstart Design

The following image shows a Quickstart design, which contains an image, a button, and a label.

Default Quickstart Screen

Clean Design

A clean design will have a screen and a background panel identical to the one shown in the accompanying image.

New Blank Screen

Configuring the MGS Composer Project Settings

The MGS Composer project settings will need to be configured further for a cross-platform configuration. In MGS Composer, go to Project > Settings.

Back to Top

Code Generator Settings

The code generator needs to be set so MGS Composer will generate the screen design code to the right location in the project.

Code Generator Settings

Click Code Generator


Uncheck Generate Harmony Interface. This will disable all Harmony-specific generated code.


Set Generate Path to the absolute path of the gfx folder in the new application directory, <mgs_xp>/apps/mynewapp/gfx.


Set Generate Name to legato.

Renderer Settings

The renderer needs to be configured so that the scratch buffer size is optimized. Ideally, the scratch buffer size must be greater than or equal to the frame buffer size in bytes, which is width × height × bytes per pixel.

For this example project, the frame buffer size is 800 × 480 × 2 bytes per pixel = 768 kB. So the scratch buffer size (kB) is set to 768.

Renderer Settings

Back to Top

Start Designing the UI

You can start designing the UI by dragging and dropping the widgets from the toolbar.

In the example below, a button widget is added and resized to the screen.

New Button Widget

For more information on how to use MGS Composer, refer to the "Microchip Graphics Suite (MGS) Harmony Composer User Guide".

MGS Composer on Linux can also import designs from Figma®. See "Working with UI Designs in Figma" for details.

Back to Top

Save and Generate the Design

Save the MGS project to the new application folder. For this example, the design project file is named using the convention, design_<resolution>.zip.

MGS Composer project zip file

Back to Top


Next, generate the design by clicking the Generate button in MGS Composer.

New Button Widget

This will generate the design source files to the <mgs_xp>/apps/<new application>/gfx/legato directory. 

Back to Top

Building and Running the Application

Build the application for desktop Linux and run the cmake commands to reconfigure the makefiles.

cd <mgs_xp>/build/host
cmake ../../
make all -j

Back to Top


The new application build output will be in the <mgs_xp>/build/host/apps/mynewapp/ directory. Launch the application directly.

./apps/mynewapp/mynewapp

Back to Top


The new application will launch in its own window. 

Running the project, button unpressed

Clicking on the gray button will toggle it.

Running the project, button pressed

To build the new application for the embedded Linux device, refer to "Building Microchip Graphics Suite (MGS) for Embedded Linux".

Back to Top