Skip to content

Tutorial Project Structure

ddbnl edited this page Aug 27, 2022 · 3 revisions

First we will learn how to prepare an EzTerm project; it consists of three parts:

  • UI config files (files with the '.ez' extension)
  • UI Rust module(s)
  • Your actual app (also Rust modules)

Below we will briefly discuss each part. Then, in the next section, we will set up an actual EzTerm project with a minimal example.

UI config files

UI config files have the '.ez' extension. They define what your UI will look like using layouts and widgets. You can have as many .ez files as you like, so you can split up your UI along multiple files. The language syntax will be explained in the coming Ez Language section.

When you compile your project, the .ez files are automatically merged into your binary, so you do not have to ship them alongside your executable. In order to merge the .ez files into your binary, cargo needs to know where they are. You declare this in an environment variable called "EZ_FOLDER" before you compile. Let's say you put the .ez files in your project root in a folder called 'ui':

/project_root
  /cargo.toml
  /src
  /ui
    /my_ui.ez

Then you would declare the environment variable like this:

  • On Linux:
export EZ_FOLDER="/path/to/project/ui"
  • On Windows:
$env:EZ_FOLDER="C:\path\to\project\ui"

Note that the path should be a full path, not a relative one. Once we have one or more .ez files and we set the environment variable, we can move on to the Rust code.

UI Rust module(s)

We have our .ez files describing what our UI should look like. Now we need a rust module that will initialize the UI and start it. It makes sense for this to be main.rs, but it does not have to be. Here is what the the module should contain at an absolute minimum:

use ez_term::*;

fn main() {

    let (root_widget, mut state_tree, mut scheduler) = load_ui();
    run(root_widget, state_tree, scheduler);
}

Initializing- and starting the UI are separate steps, because you might want to make some changes to the UI from code before it starts (we'll cover this in de Scheduler chapter).

To summarize, we now have a folder with our .ez files and a module to initialize- and start our UI:

/project_root
  /cargo.toml
  /src
    /main.rs
  /ui
    /my_ui.ez

Your app

Finally your project will obviously contain the Rust modules of your actual app (that you are building the UI for). The UI will run in the main thread and will call (parts of) your App to run in a background thread through callbacks (for example, when a button is pushed), or through a scheduled task (e.g. run every 10 seconds without user input). We'll discuss how to run your app, and how your app can manipulate the UI, later in the Scheduler section. With your actual app included, the full project structure could look like this:

/project_root
  /cargo.toml
  /src
    /main.rs
    /my_app.rs
  /ui
    /my_ui.ez

Continue

The general tutorial continues with: Minimal example.

Tutorial Tutorial-Project-Structure
  Minimal example
EzLang
  EzLang basics
  EzLang Templates
  Ezlang Layout modes
   EzLang Box mode layouts
   EzLang Stack mode layouts
   EzLang Table mode layouts
   EzLang Float mode layouts
   EzLang Tab mode layouts
   EzLang Screen mode layouts
   EzLang Layout Scrolling
   EzLang Layout Views
  EzLang Widget overview
   EzLang Label
   EzLang Text Input
   EzLang Button
   EzLang Checkbox
   EzLang Radio button
   EzLang Dropdown
   EzLang Slider
   EzLang Canvas
  EzLang Property Binding
  EzLang Sizing
   EzLang Size hints
   EzLang Auto scaling
   EzLang Maths Sizing
   EzLang Manual Sizing
  EzLang Positioning
   EzLang Layout Mode Positioning
   EzLang Position Hints
   EzLang Position Maths
   EzLang Manual Position
   EzLang Adjusting Position
  EzLang Keyboard Selection
Scheduler
  Widget States and the State Tree
  The Scheduler Object
  Managing callbacks
   Callback Structure
   Callback Configs
   Callback: On keyboard enter
   Callback: On Left Mouse Click
   Callback: On Press
   Callback: On Select
   Callback: On Deselect
   Callback: On Right Mouse Click
   Callback: On Hover
   Callback: On Drag
   Callback: On Scroll Up
   Callback: On Scroll Down
   Callback: On Value Change
   Callback: Custom Key Binds
   Callback: Global Key Binds
   Callback: Property Binds
  Tasks
   Scheduled Single Exectution Tasks
   Scheduled Recurring Tasks
   Threaded Tasks
  Custom Properties
  Modals
  Programmatic Widgets
  Updating widgets
  Managing selection
Default global (key)binds
Performance
ExamplesLayout: Box Mode Nested
Layout: Box Mode Size Hints
Layout: Stack Mode
Layout: Table Mode Dynamic
Layout: Table Mode Static
Layout: Float Mode Manual
Layout: Float Mode Position hints
Layout: Screen Mode
Layout: Tab Mode
Layout: Scrolling
Layout: Views
Widget: Label
Widget: Text input
Widget: Button
Widget: Checkbox
Widget: Radio Button
Widget: Dropdown
Widget: Slider
Widget: Progress Bar
Widget: Canvas
Scheduler: Schedule Once
Scheduler: Schedule Once Callback
Scheduler: Schedule Recurring
Scheduler: Schedule Recurring Callback
Scheduler: Threaded Task State Tree
Scheduler: Threaded Task Custom Property
Scheduler: Create Widgets
Scheduler: Modal Popup
Reference Widgets
  Common Properties
  Label
  Text Input
  Button
  Checkbox
  Radio button
  Dropdown
  Slider
  Canvas
Scheduler
  Schedule once
  Schedule Recurring
  Schedule Threaded
  Cancel Task
  Cancel Recurring Task
  Create Widget
  Remove Widget
  Select Widget
  Deselect Widget
  Update Widget
  Force Redraw
  Open Modal
  Dismiss Modal
  Bind Global Key
  Remove Global Key
  Clear Global Keys
  Bind Property
  Create Custom Properties
  Get Property
  Get Property Mut
  Overwrite Callback Config
  Update Callback Config
  Exit
Clone this wiki locally