slint-ui / slint

Slint is a declarative GUI toolkit to build native user interfaces for Rust, C++, or JavaScript apps.
https://slint.dev
Other
16.86k stars 560 forks source link

Introduce a project configuration file #267

Open tronical opened 3 years ago

tronical commented 3 years ago

We identified that having a project file that's understood by the tooling around Slint would have several benefits to support larger scale projects by centralising settings in a well-defined location.

This issue proposes to introduce slint.project.json as a configuration file

File Format

The file format shall be JSON with the extension of supporting comments.

Location

The file shall be read by the Slint compiler, the preview tool as well as by the LSP implementation. When loading a .slint file in order to compile the entry component as instructed, the tools shall look in the directory of the .slint file and in the directory hierarchy upwards for a slint.project.json file. In the case of the slint::slint! macro in the Rust integration, the starting point for the lookup shall be the CARGO_MANIFEST_DIR.

Purpose

Initially the file shall allow configuring the following settings:

This could also be extended in the future to allow defining an entry point, so that tools like the preview tool could be pointed to a slint.project.json file.

Priority

Some of these settings are also configurable through different means, such as the style with the SLINT_STYLE environment variable. The order of priority shall be from lowest to highest priority:

  1. Environment variables
  2. slint.project.json value
  3. API / Command line option

Schema

A schema shall be provided, which allows for the validation of the project settings file and code completion in IDEs

The proposed initial schema is:

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://slint.dev/slint.project.schema.json",
  "title": "Slint Project Settings",
  "description": "Various configurable settings when using Slint with .slint files",
  "type": "object",
  "properties": {
    "style": {
        "description": "The style to use when loading and rendering the UI",
        "type": "string"
    },
    "includes": {
        "description": "A list of include search paths, relative to the slint.project.json file",
        "type": "array",
        "items": {
            "type": "string",
        }
    },
    "fonts":  {
        "description": "A list of file paths to font files, relative to the slint.project.json file",
        "type": "array",
        "items": {
            "type": "string",
        }
    },
    "version": {
        "description": "The Slint version number the project files are intended to be compatible with",
        "type": "string",
    }
  }
}
ogoffart commented 1 year ago

Other things that the project file could contains: