Skip to content

Commit

Permalink
[+] add Introduction
Browse files Browse the repository at this point in the history
  • Loading branch information
heng30 committed Aug 31, 2024
1 parent 5e8b4dc commit 72a73e8
Show file tree
Hide file tree
Showing 12 changed files with 191 additions and 95 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

### Reference
- [Slint Language Documentation](https://slint-ui.com/releases/1.0.0/docs/slint/)
- [slint::android](https://snapshots.slint.dev/master/docs/rust/slint/android/#building-and-deploying)
- [github/slint-ui](https://github.com/slint-ui/slint)
- [Viewer for Slint](https://github.com/slint-ui/slint/tree/master/tools/viewer)
- [LSP (Language Server Protocol) Server for Slint](https://github.com/slint-ui/slint/tree/master/tools/lsp)
Expand Down
1 change: 1 addition & 0 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

### 参考
- [Slint Language Documentation](https://slint-ui.com/releases/1.0.0/docs/slint/)
- [slint::android](https://snapshots.slint.dev/master/docs/rust/slint/android/#building-and-deploying)
- [github/slint-ui](https://github.com/slint-ui/slint)
- [Viewer for Slint](https://github.com/slint-ui/slint/tree/master/tools/viewer)
- [LSP (Language Server Protocol) Server for Slint](https://github.com/slint-ui/slint/tree/master/tools/lsp)
Expand Down
2 changes: 1 addition & 1 deletion ui/base/dialog.slint
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export component Dialog inherits Rectangle {

if !is-hide-bottom-btns: HorizontalLayout {
alignment: LayoutAlignment.end;
spacing: Theme.spacing * 8;
spacing: Theme.spacing * 4;
padding: Theme.padding * 4;

if !is-hide-cancel-btn: CancelBtn {
Expand Down
36 changes: 29 additions & 7 deletions ui/base/link.slint
Original file line number Diff line number Diff line change
@@ -1,18 +1,40 @@
import { Theme } from "../theme.slint";
import { Theme, Icons } from "../theme.slint";
import { IconBtn } from "icon-btn.slint";

export component Link inherits Text {
export component Link inherits HorizontalLayout {
in-out property <bool> is-read;
in-out property <bool> is-show-icon;

out property has-hover <=> touch.has-hover;
in-out property enabled <=> touch.enabled;

in-out property text <=> tx.text;
in-out property color <=> tx.color;
in-out property font-size <=> tx.font-size;
in-out property wrap <=> tx.wrap;
in-out property font-weight <=> tx.font-weight;
in-out property horizontal-alignment <=> tx.horizontal-alignment;
in-out property overflow <=> tx.overflow;

callback clicked <=> touch.clicked;

wrap: word-wrap;
font-size: Theme.title5-font-size;
color: root.is-read ? Theme.have-read-text-color : Theme.link-text-color;
spacing: Theme.spacing;
alignment: LayoutAlignment.start;

tx := Text {
wrap: word-wrap;
font-size: Theme.title5-font-size;
color: root.is-read ? Theme.have-read-text-color : Theme.link-text-color;

touch := TouchArea {
mouse-cursor: MouseCursor.pointer;
}
}

touch := TouchArea {
mouse-cursor: MouseCursor.pointer;
if is-show-icon: IconBtn {
icon: Icons.browser-access;
clicked => {
root.clicked();
}
}
}
37 changes: 28 additions & 9 deletions ui/base/paragraph.slint
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Divider } from "divider.slint";
export struct ParagraphEntry {
title: string,
title-link: string,
text: string,
contents: [string],
picture: image,
}

Expand All @@ -17,10 +17,11 @@ export component Paragraph inherits Rectangle {
in-out property <length> title-font-size: Theme.title1-font-size;
in-out property title-color <=> lb-title.color;

in-out property <length> text-font-size: Theme.default-font-size;
in-out property text-color <=> lb-text.color;
in-out property <length> content-font-size: Theme.default-font-size;
in-out property <color> content-color: Theme.regular-text-color;

in-out property <length> picture-size: 300px;
in-out property <bool> is-picture-before-contents;
in-out property <bool> is-show-divider;

preferred-height: vbox.preferred-height;
Expand All @@ -34,21 +35,39 @@ export component Paragraph inherits Rectangle {
text: entry.title;
font-size: root.title-font-size;
font-weight: Theme.bold-font-weight;
color: entry.title-link != "" ? Theme.link-text-color : Theme.primary-text-color;
color: Theme.primary-text-color;
is-show-icon: entry.title-link != "";

clicked => {
Util.open-url("Default", entry.title-link);
}
}
}

lb-text := Label {
text: entry.text;
font-size: root.text-font-size;
wrap: word-wrap;
if entry.picture.width > 0 && root.is-picture-before-contents: HorizontalLayout {
alignment: LayoutAlignment.center;

Image {
width: root.picture-size;
source: entry.picture;
}
}

for item[index] in entry.contents: VerticalLayout {
padding-bottom: index == entry.contents.length - 1 ? 0 : Theme.padding * 4;

TextInput {
text: item;
font-size: root.content-font-size;
color: root.content-color;
wrap: word-wrap;
read-only: true;
single-line: false;
vertical-alignment: TextVerticalAlignment.center;
}
}

if entry.picture.width > 0: HorizontalLayout {
if entry.picture.width > 0 && !root.is-picture-before-contents: HorizontalLayout {
alignment: LayoutAlignment.center;

Image {
Expand Down
14 changes: 7 additions & 7 deletions ui/base/sidebar.slint
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ export component SideBar inherits Rectangle {
in-out property <bool> is-show-search;
in-out property search-values <=> search.values;

in-out property <int> top-current-index;
in-out property <int> current-index;
in-out property <string> selected-key;

in-out property <length> category-font-size: Theme.title3-font-size;
in-out property <int> category-font-weight: Theme.normal-font-weight;
Expand All @@ -35,6 +34,8 @@ export component SideBar inherits Rectangle {
return IconsDialogSetting.icons[current-icon-index];
}

clip: true;

hbox := HorizontalLayout {
visible: root.is-show-search;

Expand Down Expand Up @@ -63,7 +64,7 @@ export component SideBar inherits Rectangle {

for entry[top-index] in root.entries: VerticalLayout {
SettingEntryV2 {
private property <bool> is-checked: root.top-current-index == top-index && entry.children.length == 0;
private property <bool> is-checked: root.selected-key != "" && root.selected-key == entry.key;

text: entry.category;
font-size: root.category-font-size;
Expand All @@ -83,7 +84,7 @@ export component SideBar inherits Rectangle {
if entry.children.length > 0 {
entry.is-open = !entry.is-open;
} else {
root.top-current-index = top-index;
root.selected-key = entry.key;
root.clicked(entry.category, "", entry.key);
}
}
Expand All @@ -100,7 +101,7 @@ export component SideBar inherits Rectangle {

child-vbox := VerticalLayout {
for item[index] in entry.children: SettingEntryV2 {
private property <bool> is-checked: root.top-current-index == top-index && root.current-index == index;
private property <bool> is-checked: root.selected-key != "" && root.selected-key == item.key;
text: item.title;
font-size: root.child-font-size;
background: self.is-checked ? Theme.checked-background : self.has-hover ? Theme.hover-background : Colors.transparent;
Expand All @@ -112,8 +113,7 @@ export component SideBar inherits Rectangle {
}

clicked => {
root.top-current-index = top-index;
root.current-index = index;
root.selected-key = item.key;
root.clicked(entry.category, item.title, item.key);
}
}
Expand Down
56 changes: 48 additions & 8 deletions ui/panel/desktop/examples/introducion.slint
Original file line number Diff line number Diff line change
@@ -1,21 +1,61 @@
import { Util, Theme,Icons, Logic } from "../../def.slint";
import { Util, Theme,Icons, Store } from "../../def.slint";
import { Paragraph, ParagraphEntry } from "../../../base/widgets.slint";

export component Introduction inherits Flickable {
viewport-height: vbox.preferred-height;
viewport-width: vbox.preferred-width;

private property <[ParagraphEntry]> entries-cn:
[
{
title: "简介",
contents: [
"这是一个基于Rust和Slint GUI框架的模板项目。包含一些常用的组件,设置面板,配置文件,简单的数据库功能和其他小功能。这个项目的主要目的是给新手开发者提供一个简单快速的Slint GUI开发环境。该项目能够编译到桌面平台(Windows, Linux, Macos)和Android移动平台。"
],
},
{
title: "如何使用项目?",
contents: [
"1. 打开Cargo.toml文件,将所有的`slint-template` 和`slint_template`字符串替换为`你的项目名`",
"2. 打开Makefile文件,将`app-name=slint-template` 修改为`app-name=你的项目名`",
"3. 如果是Windows平台,需要修改`windows/version.h`文件,设置程序名称和描述信息等",
"4. 替换`ui/images/brand.png`和`windows/icon.ico`为你的程序图标",
"5. 使用`make desktop-build-release`构建桌面平台应用程序, `make android-build-release`构建安卓平台应用程序。更多命令可参考Makefile文件",
],
},
{
title: "如何设置Android构建环境?",
title-link: "https://snapshots.slint.dev/master/docs/rust/slint/android/#building-and-deploying",
contents: [
"1. 安装编译目标:`rustup target add aarch64-linux-android`",
"2. 安装编译工具:`cargo install cargo-apk`",
"3. 设置安卓平台环境变量:`ANDROID_HOME`, `ANDROID_NDK`, `ANDROID_NDK_ROOT` 和 `JAVA_HOME`",
"4. 例子:\n export JAVA_HOME=$LIBRARY_PATH/openjdk\n export ANDROID_HOME=$HOME/Android/Sdk\n export ANDROID_NDK=$HOME/Android/Sdk/ndk/27.0.12077973\n export ANDROID_NDK_ROOT=$HOME/Android/Sdk/ndk/27.0.12077973",
],
},
];

private property <[ParagraphEntry]> entries-en: [{ title: "Brief" }];

private property <[ParagraphEntry]> entries: Store.is-cn ? entries-cn : entries-en;

vbox := VerticalLayout {
spacing: Theme.spacing * 20;
spacing: Theme.spacing * 8;
padding: Theme.padding * 5;
alignment: LayoutAlignment.center;
padding-left: root.width * 10%;
padding-right: root.width * 10%;

HorizontalLayout {
width: root.width - parent.padding * 2;

Rectangle {
height: 600px;
background: red;
alignment: LayoutAlignment.center;
Image {
width: Math.min(root.width * 0.5, 300px);
source: Icons.brand;
}
}

for entry in root.entries: Paragraph {
width: root.width * 80%;
entry: entry;
}
}
}
15 changes: 10 additions & 5 deletions ui/panel/desktop/examples/paragraph.slint
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,34 @@ export component ParagraphExample inherits Flickable {
spacing: Theme.spacing * 10;

Paragraph {
width: 100%;
is-show-divider: true;
is-picture-before-contents: true;
entry: {
title:"How to accelerate rust-analyzer efficient?",
text: "For single-threaded improvements, one area to focus on is Rowan, the library rust-analyzer uses for syntax tree construction. Benchmarks indicate that Rowan's tree construction can be slower than other libraries like syntree. Using a syntax tree library structure with a more contiguous representation could lead to faster initial workspace loading and indexing.",
picture: Icons.landing-account,
contents: [
"For single-threaded improvements, one area to focus on is Rowan, the library rust-analyzer uses for syntax tree construction.",
"Benchmarks indicate that Rowan's tree construction can be slower than other libraries like syntree. Using a syntax tree library structure with a more contiguous representation could lead to faster initial workspace loading and indexing.",
]
};
}

Paragraph {
width: 100%;
picture-size: 500px;

entry: {
title:"Rust analyzer: any tips to increase its performance?",
title-link: "https://users.rust-lang.org/t/rust-analyzer-any-tips-to-increase-its-performance/112150",
text: "For single-threaded improvements, one area to focus on is Rowan, the library rust-analyzer uses for syntax tree construction. Benchmarks indicate that Rowan's tree construction can be slower than other libraries like syntree. Using a syntax tree library structure with a more contiguous representation could lead to faster initial workspace loading and indexing.",
picture: Icons.landing-account,
contents: [
"For single-threaded improvements, one area to focus on is Rowan, the library rust-analyzer uses for syntax tree construction. Benchmarks indicate that Rowan's tree construction can be slower than other libraries like syntree. Using a syntax tree library structure with a more contiguous representation could lead to faster initial workspace loading and indexing."
],
};
}
}
}

code: "";
code: "VerticalLayout {\n spacing: Theme.spacing * 10;\n\n Paragraph {\n width: 100%;\n is-show-divider: true;\n entry: {\n title:\"How to accelerate rust-analyzer efficient?\",\n text: \"For single-threaded improvements, one area to focus on is Rowan, the library rust-analyzer uses for syntax tree construction. Benchmarks indicate that Rowan's tree construction can be slower than other libraries like syntree. Using a syntax tree library structure with a more contiguous representation could lead to faster initial workspace loading and indexing.\",\n };\n }\n\n Paragraph {\n width: 100%;\n picture-size: 500px;\n\n entry: {\n title:\"Rust analyzer: any tips to increase its performance?\",\n title-link: \"https://users.rust-lang.org/t/rust-analyzer-any-tips-to-increase-its-performance/112150\",\n text: \"For single-threaded improvements, one area to focus on is Rowan, the library rust-analyzer uses for syntax tree construction. Benchmarks indicate that Rowan's tree construction can be slower than other libraries like syntree. Using a syntax tree library structure with a more contiguous representation could lead to faster initial workspace loading and indexing.\",\n picture: Icons.landing-account,\n };\n }\n}";
}
}
}
Expand Down
Loading

0 comments on commit 72a73e8

Please sign in to comment.