Skip to content

Commit

Permalink
[+] add drawer
Browse files Browse the repository at this point in the history
  • Loading branch information
heng30 committed Jun 21, 2024
1 parent 576726f commit e00ef86
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 19 deletions.
6 changes: 3 additions & 3 deletions ui/appwindow.slint
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ 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";
// import { Drawer, DrawerPosition, TextBtn } from "./base/widgets.slint";

export component AppWindow inherits Window {
default-font-size: Theme.default-font-size;
Expand Down Expand Up @@ -70,10 +70,10 @@ export component AppWindow inherits Window {
}
}

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

export { Util, Logic, Store, Theme }
113 changes: 113 additions & 0 deletions ui/base/drawer.slint
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import { Theme } from "../theme.slint";
import { Blanket } from "./blanket.slint";

// Example:
// Rectangle {
// drawer := Drawer {
// is-show: true;
// position: DrawerPosition.Right;
// drawer-size: 300px;
// Rectangle {
// background: blue;
// }
// }
// HorizontalLayout {
// y: 0;
// height: 50px;
// spacing: 30px;
// TextBtn {
// text: "Show";
// background: pink;
// clicked => {
// drawer.show();
// }
// }
// TextBtn {
// text: "Hide";
// background: pink;
// clicked => {
// drawer.hide();
// }
// }
// }
// }

export enum DrawerPosition {
Top,
Right,
Bottom,
Left,
}

export component Drawer inherits Rectangle {
in-out property <bool> is-show;
in property <length> drawer-size: 200px;
in property <DrawerPosition> position: DrawerPosition.Bottom;

public function show() {
root.is-show = true;
}

public function hide() {
root.is-show = false;
}

pure function drawer-x() -> length {
if (root.position == DrawerPosition.Left) {
if (root.is-show) {
return 0px;
} else {
return -root.width;
}
} else if (root.position == DrawerPosition.Right) {
if (root.is-show) {
return 0px;
} else {
return root.width;
}
}
return 0px;
}

pure function drawer-y() -> length {
if (root.position == DrawerPosition.Top) {
if (root.is-show) {
return 0px;
} else {
return -root.height;
}
} else if (root.position == DrawerPosition.Bottom) {
if (root.is-show) {
return 0px;
} else {
return root.height;
}
}
return 0px;
}

x: drawer-x();
y: drawer-y();

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

if root.is-show: Blanket {
clicked => {
root.is-show = false;
}
}

VerticalLayout {
x: root.position == DrawerPosition.Right ? root.width - self.width : 0px;
y: root.position == DrawerPosition.Bottom ? root.height - self.height : 0px;
width: root.position == DrawerPosition.Right || root.position == DrawerPosition.Left ? drawer-size : root.width;
height: root.position == DrawerPosition.Top || root.position == DrawerPosition.Bottom ? drawer-size : root.height;

TouchArea {
@children
}
}
}
15 changes: 0 additions & 15 deletions ui/base/slider.slint

This file was deleted.

5 changes: 4 additions & 1 deletion ui/base/widgets.slint
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { Loading } from "./loading.slint";
import { ListTile } from "./list-tile.slint";
import { News } from "./news.slint";
import { SlideCard } from "./slide-card.slint";
import { Drawer, DrawerPosition } from "./drawer.slint";

export {
Toast,
Expand Down Expand Up @@ -67,5 +68,7 @@ export {
Loading,
ListTile,
News,
SlideCard
SlideCard,
Drawer,
DrawerPosition
}

0 comments on commit e00ef86

Please sign in to comment.