Skip to content

Commit

Permalink
[+] add Paragraph
Browse files Browse the repository at this point in the history
  • Loading branch information
heng30 committed Aug 31, 2024
1 parent 0875b56 commit 5e8b4dc
Show file tree
Hide file tree
Showing 35 changed files with 822 additions and 514 deletions.
42 changes: 39 additions & 3 deletions src/logic/examples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,51 @@ use slint::{ComponentHandle, Model, ModelRc, VecModel};
pub fn init(ui: &AppWindow) {
ui.global::<Logic>()
.on_generate_search_values(move |entries| {
let values = entries.iter().map(|entry| entry.title).collect::<Vec<_>>();
let values = entries
.iter()
.map(|entry| {
if entry.children.row_count() > 0 {
entry
.children
.iter()
.map(|item| item.title)
.collect::<Vec<_>>()
} else {
vec![entry.category]
}
})
.flatten()
.collect::<Vec<_>>();
ModelRc::new(VecModel::from_slice(&values[..]))
});

ui.global::<Logic>()
.on_get_component_index_from_search_values(move |entries, text| {
.on_get_sidebar_key_from_search_values(move |entries, text| {
if text.is_empty() {
return Default::default();
}

let entries = entries
.iter()
.filter(|item| item.title.to_lowercase().contains(text.to_lowercase().as_str()))
.map(|entry| {
if entry.children.row_count() > 0 {
entry
.children
.iter()
.map(|item| (item.title, item.key))
.collect::<Vec<_>>()
} else {
vec![(entry.category, entry.key)]
}
})
.flatten()
.filter_map(|item| {
if item.0.to_lowercase().contains(text.to_lowercase().as_str()) {
Some(item.1)
} else {
None
}
})
.collect::<Vec<_>>();

if entries.is_empty() {
Expand Down
2 changes: 1 addition & 1 deletion ui/base/badge.slint
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export component Badge inherits Rectangle {
in-out property <length> hpadding: Theme.padding * 4;
in-out property <length> vpadding: Theme.padding;

background: Theme.third-brand-color;
background: Theme.thirdly-brand-color;
border-width: 2px;
border-radius: self.height / 2;
border-color: Theme.base-color;
Expand Down
6 changes: 3 additions & 3 deletions ui/base/btn.slint
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ export component CancelBtn inherits IconBtn {
bg-color: Theme.info-color.brighter(50%);
bg-pressed-color: self.bg-color.darker(30%);
colorize: self.bg-pressed-color.darker(100%);
icon-valignment: LayoutAlignment.end;
icon-valignment: ImageVerticalAlignment.bottom;
text: Logic.tr("Cancel");
}

export component ConfirmBtn inherits IconBtn {
use-auto-size: true;
icon: Icons.success;
border-radius: Theme.border-radius;
bg-color: Theme.third-brand-color.darker(20%);
bg-color: Theme.thirdly-brand-color.darker(20%);
bg-pressed-color: self.bg-color.darker(30%);
colorize: Theme.light-text-color;
icon-valignment: LayoutAlignment.end;
icon-valignment: ImageVerticalAlignment.bottom;
text: Logic.tr("Confirm");
}

Expand Down
2 changes: 1 addition & 1 deletion ui/base/check-btn.slint
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export component CheckBtn inherits Rectangle {
height: self.width;
border-width: 2px;
border-radius: Theme.border-radius;
border-color: root.enabled ? (root.checked ? Theme.third-brand-color : Theme.secondary-text-color) : Theme.disabled-color;
border-color: root.enabled ? (root.checked ? Theme.thirdly-brand-color : Theme.secondary-text-color) : Theme.disabled-color;

if root.checked: Image {
width: 60%;
Expand Down
2 changes: 1 addition & 1 deletion ui/base/circle-progress.slint
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export component CircleProgress inherits Rectangle {
in-out property <length> radius: 80px;
in-out property <length> ring-width: 16px;

in-out property <color> finished-progress-color: Theme.third-brand-color;
in-out property <color> finished-progress-color: Theme.thirdly-brand-color;
in-out property <color> unfinished-progress-color: Theme.secondary-background;

in-out property <color> finished-text-background: Theme.success-color;
Expand Down
15 changes: 15 additions & 0 deletions ui/base/def.slint
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,20 @@ export struct TreeEntry {
key: string,
parent-node: string,
current-node: string,
icon: image,
}

export struct SideBarChildEntry {
key: string,
title: string,
icon: image,
}

export struct SideBarEntry {
key: string,
is-open: bool,
category: string,
icon: image,
children: [SideBarChildEntry],
}

24 changes: 10 additions & 14 deletions ui/base/icon-btn.slint
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export component IconBtn inherits Rectangle {
in-out property <length> auto-size-hpadding: Theme.padding * 4;

in-out property <length> spacing: Theme.spacing;
in-out property <LayoutAlignment> icon-valignment: LayoutAlignment.center;
in-out property <ImageVerticalAlignment> icon-valignment: ImageVerticalAlignment.center;

in-out property <string> text;
in-out property <length> font-size: Theme.title4-font-size;
Expand Down Expand Up @@ -76,20 +76,16 @@ export component IconBtn inherits Rectangle {
text: root.text;
}

VerticalLayout {
alignment: root.icon-valignment;
img := Image {
vertical-alignment: root.icon-valignment;
width: Theme.icon-size;
colorize: Theme.icon-color;
rotation-angle: 0;

img := Image {
vertical-alignment: center;
width: Theme.icon-size;
colorize: Theme.icon-color;
rotation-angle: 0;

animate rotation-angle {
duration: Theme.default-animate-duration;
easing: ease-in-out;
iteration-count: root.rotation-type == RotationType.Auto ? -1 : root.icon-rotation-iteration-count;
}
animate rotation-angle {
duration: Theme.default-animate-duration;
easing: ease-in-out;
iteration-count: root.rotation-type == RotationType.Auto ? -1 : root.icon-rotation-iteration-count;
}
}

Expand Down
2 changes: 1 addition & 1 deletion ui/base/line-input.slint
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export component LineInput inherits Rectangle {
forward-focus: text-input;
border-radius: Theme.border-radius;
border-width: text-input.has-focus ? 2px : 1px;
border-color: text-input.has-focus ? Theme.third-brand-color : Theme.base-border-color;
border-color: text-input.has-focus ? Theme.thirdly-brand-color : Theme.base-border-color;

public function paste() {
text-input.paste();
Expand Down
4 changes: 3 additions & 1 deletion ui/base/link.slint
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import { Theme } from "../theme.slint";
export component Link inherits Text {
in-out property <bool> is-read;

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

callback clicked <=> touch.clicked;

wrap: word-wrap;
font-size: Theme.title5-font-size;
Expand Down
2 changes: 1 addition & 1 deletion ui/base/log-in.slint
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export component LogIn inherits Rectangle {
height: self.text-height + Theme.padding * 2;
text: Logic.tr("Log in");
font-size: Theme.title3-font-size;
bg-color: Theme.third-brand-color;
bg-color: Theme.thirdly-brand-color;
text-color: Theme.light-text-color;

clicked => {
Expand Down
7 changes: 3 additions & 4 deletions ui/base/pagination.slint
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export component Pagination inherits Rectangle {
spacing: Theme.spacing * 4;
for index in total-pages: TextBtnWithoutIcon {
is-circle: true;
background: root.real-current-page == index ? Theme.third-brand-color : Colors.transparent;
background: root.real-current-page == index ? Theme.thirdly-brand-color : Colors.transparent;

text: start-page + index + 1;
font-size: root.font-size;
Expand Down Expand Up @@ -117,7 +117,7 @@ export component Pagination inherits Rectangle {
spacing: Theme.spacing * 4;
for index in real-show-pages-half: TextBtnWithoutIcon {
is-circle: true;
background: root.real-current-page == start-page + index ? Theme.third-brand-color : Colors.transparent;
background: root.real-current-page == start-page + index ? Theme.thirdly-brand-color : Colors.transparent;

text: start-page + index + 1;
font-size: root.font-size;
Expand Down Expand Up @@ -154,8 +154,7 @@ export component Pagination inherits Rectangle {
is-circle: true;
text: inner-real-current-page + 1;
font-size: root.font-size;
background: root.real-current-page == inner-real-current-page ? Theme.third-brand-color : Colors.transparent;
text-color: root.real-current-page == inner-real-current-page ? Theme.light-text-color : root.text-color;
background: root.real-current-page == inner-real-current-page ? Theme.thirdly-brand-color : Colors.transparent; text-color: root.real-current-page == inner-real-current-page ? Theme.light-text-color : root.text-color;

clicked => {
root.real-current-page = inner-real-current-page;
Expand Down
65 changes: 65 additions & 0 deletions ui/base/paragraph.slint
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { Theme } from "../theme.slint";
import { Util } from "../util.slint";
import { Label } from "label.slint";
import { Link } from "link.slint";
import { Divider } from "divider.slint";

export struct ParagraphEntry {
title: string,
title-link: string,
text: string,
picture: image,
}

export component Paragraph inherits Rectangle {
in-out property <ParagraphEntry> entry;

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> picture-size: 300px;
in-out property <bool> is-show-divider;

preferred-height: vbox.preferred-height;

vbox := VerticalLayout {
HorizontalLayout {
padding-bottom: Theme.padding * 4;

lb-title := Link {
enabled: entry.title-link != "";
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;

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: HorizontalLayout {
alignment: LayoutAlignment.center;

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

if root.is-show-divider: HorizontalLayout {
padding-top: Theme.padding * 4;
Divider { }
}
}
}
2 changes: 1 addition & 1 deletion ui/base/pin-codes.slint
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export component PinCodes inherits Rectangle {
border-radius: Theme.border-radius;
background: Theme.secondary-background;
border-width: 2px;
border-color: tinput.has-focus ? Theme.third-brand-color : Theme.base-border-color;
border-color: tinput.has-focus ? Theme.thirdly-brand-color : Theme.base-border-color;

tinput := TextInput {
input-type: root.input-type;
Expand Down
2 changes: 1 addition & 1 deletion ui/base/process-step.slint
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export component ProcessStep inherits Rectangle {
in-out property <color> finished-color: Theme.success-color;
in-out property <color> finished-number-color: Theme.base-color;

in-out property <color> process-color: Theme.third-brand-color;
in-out property <color> process-color: Theme.thirdly-brand-color;
in-out property <color> process-number-color: Theme.light-text-color;
in-out property <length> process-line-width: orientation == Orientation.horizontal ? 100px : Theme.default-font-size / 4;
in-out property <length> process-line-height: orientation == Orientation.horizontal ? Theme.default-font-size / 4 : 100px;
Expand Down
2 changes: 1 addition & 1 deletion ui/base/progress-bar.slint
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export component ProgressBar inherits Rectangle {
in-out property <bool> is-moving-text;
in-out property <Orientation> orientation: Orientation.horizontal;

in-out property <color> finished-progress-color: Theme.third-brand-color;
in-out property <color> finished-progress-color: Theme.thirdly-brand-color;
in-out property <color> unfinished-progress-color: Theme.secondary-background;

in-out property <string> finished-text: Logic.tr("Finished");
Expand Down
2 changes: 1 addition & 1 deletion ui/base/radio-btn.slint
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export component RadioBtn inherits Rectangle {
height: self.width;
border-width: 2px;
border-radius: self.width / 2;
border-color: root.enabled ? (root.checked ? Theme.third-brand-color : Theme.secondary-text-color) : Theme.disabled-color;
border-color: root.enabled ? (root.checked ? Theme.thirdly-brand-color : Theme.secondary-text-color) : Theme.disabled-color;

if root.checked: Rectangle {
width: 60%;
Expand Down
1 change: 1 addition & 0 deletions ui/base/search.slint
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export component Search inherits Rectangle {
font-size: root.font-size;

clicked => {
root.is-show-popup = false;
root.search(self.text);
}

Expand Down
2 changes: 1 addition & 1 deletion ui/base/select.slint
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export component Select inherits Rectangle {
overflow: elide;
text: value;
font-size: root.font-size;
color: is-selected ? Theme.third-brand-color : Theme.primary-text-color;
color: is-selected ? Theme.thirdly-brand-color : Theme.primary-text-color;
}

if is-selected: VerticalLayout {
Expand Down
20 changes: 12 additions & 8 deletions ui/base/setting-entry.slint
Original file line number Diff line number Diff line change
Expand Up @@ -47,26 +47,30 @@ export component SettingEntry inherits Rectangle {
export component SettingEntryV2 inherits Rectangle {
in-out property text <=> label.text;
in-out property font-size <=> label.font-size;
in-out property text-color <=> label.color;
in-out property font-weight <=> label.font-weight;

in-out property icon <=> img.source;
in-out property icon-colorize <=> img.colorize;
in-out property icon-size <=> img.width;
out property has-hover <=> ta.has-hover;

in-out property <bool> is-show-indicator;
in-out property <length> h-padding: Theme.padding * 2;
in-out property <length> v-padding: Theme.padding * 2;
in-out property <length> hpadding: Theme.padding * 2;
in-out property <length> vpadding: Theme.padding * 2;

in-out property <bool> is-show-right-icon;
in-out property <image> right-icon: Icons.star;
in-out property <color> right-icon-colorize;
in-out property <color> right-icon-colorize: label.color;
in-out property <length> right-icon-size;

callback clicked();

hbox := HorizontalLayout {
padding-left: h-padding;
padding-right: h-padding;
padding-top: v-padding;
padding-bottom: v-padding;
padding-left: hpadding;
padding-right: hpadding;
padding-top: vpadding;
padding-bottom: vpadding;

alignment: LayoutAlignment.space-between;

Expand Down Expand Up @@ -101,7 +105,7 @@ export component SettingEntryV2 inherits Rectangle {

if is-show-right-icon: Image {
vertical-alignment: center;
width: root.icon-size;
width: root.right-icon-size;
colorize: root.right-icon-colorize;
source: root.right-icon;
}
Expand Down
Loading

0 comments on commit 5e8b4dc

Please sign in to comment.