Surrealism-All / SurrealismUI

A third-party UI library using Slint, I think it will give you an extraordinary experience
https://surrealism-all.github.io/SurrealismUI.github.io/
MIT License
216 stars 20 forks source link
gui rust slint slint-ui ui-components widget-library widgets

SurrealismUI

SurrealismUI is a third-party component library built entirely using Slint

Install

use cargo-generate

1. Install cargo-generate

you can use the following command to install cargo-generate

cargo install cargo-generate

2. generate your own project

input your project name to replace {project_name}

cargo generate --git https://github.com/Surrealism-All/surrealism-ui-template.git --name {project_name}
🔧   Destination: E:\Rust\test-surrealism ...
🔧   project-name: test-surrealism ...
🔧   Generating template ...
🔧   Moving generated files into: `E:\Rust\test-surrealism`...
🔧   Initializing a fresh Git repository
✨   Done! New project created E:\Rust\test-surrealism

3. run project

cargo run

Github

  1. GoTo :https://github.com/Surrealism-All/SurrealismUI/releases
  2. Find the latest release and download
  3. unzip and add into your project

QuickStart

Config SurrealismUI as Library (optional)

  1. Open VsCode and choose Settings , then search Slint:Library Paths
  2. Choose edit in settings.json
  3. Find slint.libraryPaths and add "SurrealismUI":"parent_file_path\\surrealism-ui\\index.slint"
  "slint.libraryPaths": {
    "SurrealismUI":"E:\\test_try\\test-surrealism\\ui\\modules\\surrealism-ui\\index.slint"
  },

Import and Use

import { SMenu,SCard,SHeader,SIcon,SButton  } from "../index.slint";
import {UseIcons } from "../use/index.slint";
import { STip } from "../src/tip/index.slint";
import { STag } from "../src/tag/index.slint";
import { SAlert } from "../src/alert/index.slint";

export component App inherits Window {
    height: 600px;
    width: 800px;
    private property <int> router-index : 0;
    HorizontalLayout {
      left-wrapper:=Rectangle {
        z: 111;
        height: 100%;
        width: menu.width;
        clip: false;
        menu:=SMenu {
          change(index,data) => {
            debug(index);
          }
        }
      }
      right-wrapper:=Rectangle {
        z: 100;
        width: parent.width - menu.width;
        background: #2b2b32;
        if router-index==0:index-page:= Rectangle {
            height: 100%;
            width: 100%;
            VerticalLayout {
              HorizontalLayout {
                padding: 8px;
                alignment: center;
                Rectangle {
                  height:header.height ;
                  width: parent.width - 16px;
                  header:=SHeader {
                    value: [{label:"SurrealismUI",value:"1"},{label:"menu:Index",value:"2"}];
                  }
                }
              }
              HorizontalLayout {
                padding: 24px;
                alignment: space-around;
                STag {
                  theme: Warning;
                  text: "SurrealismUI V0.3.3";
                }
                STag {
                  theme: Success;
                  text: "MIT License";
                }
                STag {
                  theme: Error;
                  text: "For Slint!";
                }
                STag {
                  theme: Error;
                  text: "author:syf20020816@outlook.com";
                }
              }
              HorizontalLayout {
                alignment: center;
                SCard {
                  card-width: 460px;
                  card-height: 320px;
                  SIcon {
                    height: parent.height;
                    width: parent.width;
                    source: @image-url("../README/imgs/logo.png");
                  }
                }
              }
              HorizontalLayout {
                padding: 24px;
                alignment: space-around;
                SButton {
                  text: "Try SurrealismUI";
                  clicked => {
                    alert.success("Try SurrealismUI!!! Let's GO!");
                  }
                }

                SButton {
                  show-icon: true;
                  icon: UseIcons.icons.Smiling-face;
                  theme: Primary;
                  text: "Star on Github!";
                }
                STip {
                  text: "GO TO SurrealismUI WIKI?\n Click here!";
                  height: wiki-btn.height;
                  width: wiki-btn.width;
                  position: Bottom;
                  wiki-btn:=SButton {
                    theme: Success;
                    text: "Read Wiki!~~~";
                    clicked => {
                      parent.clicked();
                    }
                  }
                }
              }

            }
        }
      }
    }
    alert:=SAlert {
      result-type: Success;
      text: "";
    }
}

What SurrealismUI Do?

              default
————————————————————————————————————
|  logic control layer (Rust|C++)  |
————————————————————————————————————
                ⇕
————————————————————————————————————
|    UI layer (write components)   |
————————————————————————————————————

           SurrealismUI
————————————————————————————————————
|  logic control layer (Rust|C++)  |
————————————————————————————————————
                ⇕
————————————————————————————————————
|      UI Styles Wrapper layer     |   <-- What SurrealismUI do , see ①
————————————————————————————————————
|   UI layer (write components)    |
————————————————————————————————————

①:define a lot replaceable theme styles and binding styles use theme property , can be customized in slint file or logic control layer , means: all system components are wrapped (Customizing themes in third-party component libraries is very affordable as it acts on the UI layer. slint is like an integration of HTML and CSS, so I use this way)(By binding global singleton variables to styles, any component that uses variables can change styles simultaneously)

                System support (like iced)
————————————————————————————————————      ————————————————
|           logic control          | -->  | Theme::Light |
————————————————————————————————————      ————————————————
|             UI layer             |              ↓
————————————————————————————————————        |————————————|
                         ↑               ↓            ↓
                import    ← Light_Theme Styles   Dark_Theme Styles

## Diff
Slint differs from other GUI frameworks in that the UI layer is completed through. slint, which I believe is good and brings many advantages (compatibility with different platforms, instant preview, maintainability, parallel development, etc.). But this also leads to SLIT being unable to easily customize the theme of the component. Theme customization and switching are dynamic to static processes, which require a lot of logical processing, and this is also same as (HTML+CSS+js | ts)

Themes

Built in 7 theme colors in SurrealismUI

themes-color

Theme weakest weaker normal deeper deepest font opacity
Light #F6F6F6 #E0E0E0 #FFFFFF #F6F6F6 #F5F5F5 #212121 #E0E0E088
Primary #88D0EC #6CB8F7 #3AA1F5 #1891F3 #0B86F1 #e5ffff #3AA1F588
Success #8FCEC4 #61BF84 #38A762 #21964A #118A3D #e5fffb #38A76288
Info #F6F6F6 #eaeaea #E0E0E0 #D2D2D2 #BDBDBD #484848 #E0E0E088
Warning #ffd5bd #FCBD99 #F9A677 #F9955C #F8894A #fff4ec #F9A67788
Error #e9a7a7 #f48989 #ed5e5e #ed4e4e #ed3b3b #ffe5e4 #ed4e4e88
Dark #707070 #616161 #3a3a3a #242424 #000000 #e4e4e4 #42424288

Wiki

https://github.com/Surrealism-All/SurrealismUI/wiki

Components

Updates

中文

V0.3.0 版本是一个重大变更的版本,几乎所有的组件都经历了一次重构,优化了所有组件的结构,对整体项目目录进行了调整,处理了在之前版本中的不合理问题(组件名字,组件属性,方法,回调,内置方法,内置属性,内置 Global 等)。本次大更新更探索了类似于 VNode 的可能性(但目前并没有完美的方案)。将所有组件属性进行提取并使用结构体进行管理,这使得对组件样式的控制更加彻底,并使得使用 rust,c++,js 动态控制组件更加容易,动态生成组件这一需求也得到了解决。

在本次大型更新后,SurrealismUI 中属性的写法与原生属性更加接近,这不仅减少了学习成本,更有利于使用者的理解。在后续 0.3.x 的版本中将会持续优化(每个版本的更新周期约 2 周)。此外 0.3.0 版本后可能不再涉及如此大范围的更新,该项目的稳定性将会持续提升。

感谢各位的阅读,如果您有任何问题,请发送邮件到syf20020816@outlook.com或在 SurrealismUI 仓库的讨论或 issue 中提出


English

V0.3.0 is a major change version. Almost all components have undergone a rebuiding, optimizing the structure of all components, adjusting the overall project directory, and dealing with unreasonable problems in the previous version (component name, component properties, functions, callbacks, built-in functions, built-in properties, built-in Global, ...). This big update explores the possibility of something similar to VNode (but there is no perfect solution at present). All component attributes are extracted and managed by using struct, which makes the control of component style more thorough, and makes it easier to use Rust, C + +, JS to dynamically control components, and the requirement of dynamically generating components is also solved.

After this major update, the writing of attributes in SurrealismUI is closer to the native attributes, which not only reduces the learning cost, but also is more conducive to the user's understanding. Optimization will continue in subsequent 0.3.x releases (approximately 2 weeks per release). In addition, the 0.3.0 version may no longer involve such a wide range of updates, and the stability of the project will continue to improve.

Thank you for reading, and if you have any questions, please send an email to syf20020816@outlook.com or raise them in a discussion or issue at the SurrealismUI repository