Skip to content

Commit

Permalink
[+] add ListTile and SlideCard
Browse files Browse the repository at this point in the history
  • Loading branch information
heng30 committed Jun 21, 2024
1 parent 5e53d72 commit 576726f
Show file tree
Hide file tree
Showing 7 changed files with 250 additions and 43 deletions.
7 changes: 7 additions & 0 deletions ui/appwindow.slint
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { Util } from "./util.slint";
import { Panel } from "./panel/panel.slint";
import { Toast, IconsDialog, IconsDialogSetting, OkCancelDialogV2, Blanket, LanguageDialog, InputBar, OkCancelDialogSetting, LandingPage } from "./base/widgets.slint";

import { SlideCard } from "./base/widgets.slint";

export component AppWindow inherits Window {
default-font-size: Theme.default-font-size;
default-font-family: Theme.default-font-family;
Expand Down Expand Up @@ -67,6 +69,11 @@ export component AppWindow inherits Window {
Store.is-show-landing-page = false;
}
}

Rectangle {
// visible: false;
// background: red;
}
}

export { Util, Logic, Store, Theme }
5 changes: 3 additions & 2 deletions ui/base/icon-btn.slint
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export component IconBtn inherits Rectangle {
in-out property icon <=> img.source;
in-out property colorize <=> img.colorize;
in-out property icon-width <=> img.width;
in-out property icon-size <=> img.width;
in-out property icon-rotation-angle <=> img.rotation-angle;
in-out property mouse-cursor <=> touch.mouse-cursor;
in-out property enabled-toucharea<=> touch.enabled;
Expand Down Expand Up @@ -35,8 +36,8 @@ export component IconBtn inherits Rectangle {

// only is a icon showing this hover color
if (text == "" && show-icon-hover-background): Rectangle {
x: img.x - Theme.spacing * 2 - (Theme.icon-size - img.width) / 2;
width: Theme.icon-size + Theme.spacing * 4;
x: img.x - Theme.spacing * 2 - (Math.max(Theme.icon-size, root.icon-width) - img.width) / 2;
width: Math.max(Theme.icon-size, root.icon-width) + Theme.spacing * 4;
height: self.width;
border-radius: self.width / 2;
background: touch.has-hover ? Palette.background : Colors.transparent;
Expand Down
90 changes: 50 additions & 40 deletions ui/base/list-tile.slint
Original file line number Diff line number Diff line change
@@ -1,48 +1,52 @@
import { Theme, Icons } from "../theme.slint";
import { CenterLayout } from "./center-layout.slint";
import { IconBtn } from "./icon-btn.slint";
import { Label } from "./label.slint";
import { Logic } from "../logic.slint";

export component ListTile inherits Rectangle {
height: vbox.preferred-height;

callback left-clicked();
callback right-clicked();
callback tap <=> tap-area.clicked;
callback middle-clicked();

in property <bool> is-show-left-icon: false;
in property <bool> is-show-left-icon;
in property <length> left-icon-size: Theme.icon-size;
in property <color> left-colorize: Colors.transparent;
in property <image> left-icon: Icons.empty-image;
in property <color> left-colorize;
in property <image> left-icon;
in property <color> left-icon-background;
in property <color> left-icon-hover-background;

in property <bool> is-show-right-icon: false;
in property <color> middle-background;
in property <color> middle-hover-background;

in property <bool> is-show-right-icon;
in property <length> right-icon-size: Theme.icon-size;
in property <color> right-colorize: Colors.transparent;
in property <image> right-icon: Icons.empty-image;
in property <color> right-colorize;
in property <image> right-icon;

in property <length> title-font-size: Theme.title3-font-size;
in property <string> title-text;
in property <length> title-font-size: Theme.title3-font-size;

in property <length> subtitle-font-size: Theme.default-font-size;
in property <string> subtitle-text;
in property <length> subtitle-font-size: Theme.default-font-size;

in property tap-mouse-cursor <=> tap-area.mouse-cursor;

private property <LayoutAlignment> horizontal-alignment: is-show-right-icon ? LayoutAlignment.space-between : LayoutAlignment.start;
in property middle-mouse-cursor <=> middle-area.mouse-cursor;

tap-area := TouchArea { }
private property <LayoutAlignment> horizontal-alignment: is-show-right-icon ? LayoutAlignment.space-between : is-show-left-icon ? LayoutAlignment.start : LayoutAlignment.stretch;

hbox := HorizontalLayout {
padding: Theme.padding;
spacing: Theme.spacing * 2;
alignment: root.horizontal-alignment;

HorizontalLayout {
horizontal-stretch: 1;
alignment: LayoutAlignment.start;
spacing: Theme.spacing * 2;

if is-show-left-icon: Rectangle {
width: root.left-icon-size + Theme.padding * 4;
border-radius: Theme.border-radius;
background: img-area.has-hover ? root.left-icon-hover-background : root.left-icon-background;

img := Image {
height: root.left-icon-size;
Expand All @@ -51,46 +55,52 @@ export component ListTile inherits Rectangle {
colorize: root.left-colorize;
}

TouchArea {
img-area := TouchArea {
mouse-cursor: MouseCursor.pointer;
clicked => {
root.left-clicked();
}
}
}

vbox := VerticalLayout {
alignment: LayoutAlignment.start;
spacing: Theme.spacing * 2;
padding: Theme.padding * 2;
horizontal-stretch: 1;

if root.title-text != "": Label {
font-size: root.title-font-size;
text: root.title-text;
wrap: word-wrap;
font-weight: 0.5;
Rectangle {
clip: true;
border-radius: Theme.border-radius;
background: middle-area.has-hover ? root.middle-hover-background : root.middle-background;

middle-area := TouchArea {
clicked => {
root.middle-clicked();
}
}

if root.subtitle-text != "": Label {
font-size: root.subtitle-font-size;
text: root.subtitle-text;
wrap: word-wrap;
vbox := VerticalLayout {
alignment: LayoutAlignment.start;
spacing: Theme.spacing * 2;
padding: Theme.padding * 2;

if root.title-text != "": Label {
font-size: root.title-font-size;
text: root.title-text;
wrap: word-wrap;
font-weight: 0.5;
}

if root.subtitle-text != "": Label {
font-size: root.subtitle-font-size;
text: root.subtitle-text;
wrap: word-wrap;
}
}
}
}

if is-show-right-icon: Rectangle {
width: root.right-icon-size + Theme.padding * 4;
Image {
height: root.right-icon-size;
width: self.height;
source: root.right-icon;
colorize: root.right-colorize;
}

TouchArea {
mouse-cursor: MouseCursor.pointer;
IconBtn {
icon-size: root.right-icon-size;
icon: root.right-icon;
clicked => {
root.right-clicked();
}
Expand Down
58 changes: 58 additions & 0 deletions ui/base/news.slint
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { Theme, Icons } from "../theme.slint";
import { Link } from "../link.slint";

export component News inherits Rectangle {
height: vbox.preferred-height;

callback link-clicked();

in property <string> link-text;
in property <string> pub-date;
in property <string> summary;
in property <string> author;
in property <bool> is-read;

background: Theme.base-background;
border-radius: Theme.border-radius;
drop-shadow-blur: Theme.padding * 2;
drop-shadow-color: Theme.base-background-drop-shadow;

vbox := VerticalLayout {
padding: Theme.padding * 2;
spacing: Theme.spacing * 2;
alignment: start;

link := Link {
is-read: root.is-read;
text: root.link-text;

clicked => {
root.link-clicked();
}
}

Text {
font-size: Theme.default-font-size - 1px;
color: root.is-read ? Theme.have-read-text-color : Theme.regular-text-color;
text: root.summary;
wrap: word-wrap;
}

HorizontalLayout {
alignment: end;
spacing: Theme.padding * 4;

if root.author != "": Text {
font-size: Theme.default-font-size - 4px;
color: Theme.placeholder-text-color;
text: root.author;
}

if pub-date != "": Text {
font-size: Theme.default-font-size - 4px;
color: Theme.placeholder-text-color;
text: root.pub-date;
}
}
}
}
112 changes: 112 additions & 0 deletions ui/base/slide-card.slint
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import { Theme } from "../theme.slint";
import { IconBtn } from "./icon-btn.slint";
import { Label } from "./label.slint";


// Example:
// SlideCard {
// background: blue;
// icons-background: white;
// icons: [
// {
// icon: Icons.delete,
// text: "Delete",
// },
// {
// icon: Icons.edit,
// text: "Edit",
// },
// ];

// Rectangle {
// height: 80px;
// background: pink;
// }
// }

export component SlideCard inherits Rectangle {
height: vbox.preferred-height;

callback icon-clicked(int);

in property <[{icon: image, text: string}]> icons;
in property <color> icons-background;
in property <bool> hide-icons-after-clicked: true;

private property <length> max-move-pixels-up-bound: self.width * 0.04;
private property <length> max-move-pixels-low-bound: self.width * 0.02;
private property <bool> is-show-icons: false;
private property <bool> is-hide-icons: true;

public function show-icons() {
root.x = -icons-scope.width;
root.is-show-icons = true;
root.is-hide-icons = false;
}

public function hide-icons() {
root.x = 0;
root.is-hide-icons = true;
root.is-show-icons = false;
}

animate x {
duration: Theme.default-animate-duration;
easing: ease-in-out;
}

TouchArea {
moved => {
if (!root.is-show-icons) {
if (self.pressed-x - self.mouse-x > parent.max-move-pixels-up-bound) {
show-icons();
}
}
if (!root.is-hide-icons) {
if (self.mouse-x - self.pressed-x > parent.max-move-pixels-up-bound) {
hide-icons();
}
}
}
}

vbox := VerticalLayout {
@children
}

icons-scope := Rectangle {
x: root.width;
background: root.icons-background;
width: Math.max(root.width * 0.15, Theme.icon-size * 2) * icons.length;
HorizontalLayout {
spacing: Theme.spacing;
for item[index] in root.icons: Rectangle {
VerticalLayout {
spacing: Theme.spacing;
alignment: LayoutAlignment.center;

IconBtn {
icon: item.icon;
}

if item.text != "": HorizontalLayout {
alignment: LayoutAlignment.center;
Label {
text: item.text;
}
}
}

TouchArea {
mouse-cursor: MouseCursor.pointer;
clicked => {
if (hide-icons-after-clicked) {
root.hide-icons();
}
root.icon-clicked(index);
}
}
}
}
}
}
15 changes: 15 additions & 0 deletions ui/base/slider.slint
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Theme } from "../theme.slint";

export component Slider inherits Text {
in-out property <bool> is-read;

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;

touch := TouchArea {
mouse-cursor: MouseCursor.pointer;
}
}
6 changes: 5 additions & 1 deletion ui/base/widgets.slint
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import { LandingPage } from "./landing-page.slint";
import { Tip } from "./tip.slint";
import { Loading } from "./loading.slint";
import { ListTile } from "./list-tile.slint";
import { News } from "./news.slint";
import { SlideCard } from "./slide-card.slint";

export {
Toast,
Expand Down Expand Up @@ -63,5 +65,7 @@ export {
LandingPage,
Tip,
Loading,
ListTile
ListTile,
News,
SlideCard
}

0 comments on commit 576726f

Please sign in to comment.