-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
297 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use crate::slint_generatedAppWindow::{AppWindow, Logic, PopupActionSetting}; | ||
use slint::ComponentHandle; | ||
|
||
pub fn init(ui: &AppWindow) { | ||
let ui_handle = ui.as_weak(); | ||
ui.global::<PopupActionSetting>() | ||
.on_action(move |action, _user_data| { | ||
let ui = ui_handle.unwrap(); | ||
|
||
#[allow(clippy::single_match)] | ||
match action.as_str() { | ||
"remove-all-cache" => { | ||
println!("handel remove all cache"); | ||
ui.global::<Logic>().invoke_remove_all_cache(); | ||
} | ||
_ => (), | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
import { ComponentPosition } from "def.slint"; | ||
import { Theme } from "../theme.slint"; | ||
import { Util } from "../util.slint"; | ||
import { Label } from "label.slint"; | ||
import { SettingEntryV2 } from "setting-entry.slint"; | ||
import { Divider } from "divider.slint"; | ||
|
||
// Example: | ||
// Rectangle { | ||
// background: red; | ||
// width: 300px; | ||
// height: 300px; | ||
// ta := TouchArea { | ||
// pointer-event(event) => { | ||
// if (event.kind == PointerEventKind.down && event.button == PointerEventButton.right) { | ||
// PopupActionSetting.show(parent.absolute-position.x + self.mouse-x, parent.absolute-position.y + self.mouse-y, [ | ||
// { icon: Icons.delete, text: "Delete", action: "delete-item" }, | ||
// { icon: Icons.add-fill, text: "Add", action: "add-item" }, | ||
// { icon: Icons.recover-from-trash, text: "Remove trash", action: "remove-all-cache" } | ||
// ]); | ||
// } | ||
// } | ||
// } | ||
// } | ||
|
||
export struct PopupActionEntry { | ||
icon: image, | ||
text: string, | ||
action: string, | ||
user-data: string, | ||
} | ||
|
||
export global PopupActionSetting { | ||
in-out property <bool> is-show; | ||
in-out property <[PopupActionEntry]> actions; | ||
in-out property <length> pressed-absolute-x; | ||
in-out property <length> pressed-absolute-y; | ||
|
||
public function show(absolute-x: length, absolute-y: length, actions: [PopupActionEntry]) { | ||
self.pressed-absolute-x = absolute-x; | ||
self.pressed-absolute-y = absolute-y; | ||
self.actions = actions; | ||
self.is-show = true; | ||
} | ||
|
||
public function hide() { | ||
is-show = false; | ||
} | ||
|
||
callback action(string, string); | ||
} | ||
|
||
export component PopupAction inherits Rectangle { | ||
in-out property <length> window-width; | ||
in-out property <length> window-height; | ||
in-out property <length> spacing: Theme.spacing * 2; | ||
|
||
in-out property <color> icon-colorize: Theme.icon-color; | ||
in-out property <length> icon-size: Theme.icon-size; | ||
in-out property <length> font-size: Theme.title3-font-size; | ||
|
||
pure function calc-x() -> length { | ||
return Math.clamp(PopupActionSetting.pressed-absolute-x + Theme.padding * 2, 0px, root.window-width - rect.width); | ||
} | ||
|
||
pure function calc-y() -> length { | ||
return Math.clamp(PopupActionSetting.pressed-absolute-y + Theme.padding * 2, 0px, root.window-height - rect.height); | ||
} | ||
|
||
fs := FocusScope { } | ||
|
||
TouchArea { | ||
clicked => { | ||
fs.focus(); | ||
PopupActionSetting.hide(); | ||
} | ||
} | ||
|
||
rect := Rectangle { | ||
x: calc-x(); | ||
y: calc-y(); | ||
|
||
width: vbox.preferred-width + Theme.spacing * 2; | ||
height: vbox.preferred-height + Theme.padding * 2; | ||
background: Theme.base-background; | ||
border-color: Theme.base-border-color; | ||
border-width: 1px; | ||
border-radius: Theme.border-radius; | ||
|
||
vbox := VerticalLayout { | ||
alignment: LayoutAlignment.center; | ||
spacing: root.spacing; | ||
width: self.preferred-width; | ||
height: self.preferred-height; | ||
|
||
for entry[index] in PopupActionSetting.actions: VerticalLayout { | ||
SettingEntryV2 { | ||
icon: entry.icon; | ||
text: entry.text; | ||
font-size: root.font-size; | ||
icon-colorize: root.icon-colorize; | ||
icon-size: root.icon-size; | ||
background: self.has-hover ? Theme.secondary-background : Colors.transparent; | ||
|
||
clicked => { | ||
PopupActionSetting.hide(); | ||
PopupActionSetting.action(entry.action, entry.user-data); | ||
} | ||
} | ||
|
||
if index != PopupActionSetting.actions.length - 1: HorizontalLayout { | ||
padding-left: Theme.padding * 2; | ||
padding-right: Theme.padding * 2; | ||
Divider { } | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { Theme, Icons } from "../../theme.slint"; | ||
import { Util } from "../../util.slint"; | ||
import { ProcessStep, CircleProgress, RecordIndicator, ProgressBar, ComponentPosition, Pagination, SkeletonType, Skeleton, PinCodes, Badge, Banner, CheckBtn, Select, ComponentPosition, Slider, CollapseEntry, Collapse, Search, PopupActionEntry, PopupActionSetting, IconBtn, Label } from "../../base/widgets.slint"; | ||
import { SettingIconsBar } from "../setting/desktop.slint"; | ||
|
||
export component Home inherits Rectangle { | ||
VerticalLayout { | ||
padding: Theme.padding * 2; | ||
spacing: Theme.spacing * 5; | ||
vertical-stretch: 1; | ||
alignment: LayoutAlignment.center; | ||
|
||
VerticalLayout { | ||
alignment: center; | ||
spacing: Theme.spacing * 10; | ||
|
||
HorizontalLayout { | ||
alignment: center; | ||
CircleProgress { | ||
ring-width: 15px; | ||
progress: Util.progress-value(5s); | ||
} | ||
} | ||
|
||
HorizontalLayout { | ||
alignment: center; | ||
height: 500px; | ||
|
||
Search { | ||
width: 500px; | ||
values: ["Hello", "World", "Nice", "Good"]; | ||
enabled-popup: true; | ||
|
||
search(text) => { | ||
debug(text); | ||
} | ||
|
||
edited(text) => { | ||
debug(text); | ||
} | ||
} | ||
} | ||
} | ||
|
||
HorizontalLayout { | ||
alignment: center; | ||
|
||
ProcessStep { | ||
steps: ["First Step", "Second Step", "Third Step", "Finished"]; | ||
current-step: Util.progress-value-int(self.steps.length, self.steps.length * 1s); | ||
} | ||
} | ||
|
||
HorizontalLayout { | ||
alignment: LayoutAlignment.center; | ||
|
||
Rectangle { | ||
background: red; | ||
width: 300px; | ||
height: 300px; | ||
|
||
ta := TouchArea { | ||
pointer-event(event) => { | ||
if (event.kind == PointerEventKind.down && event.button == PointerEventButton.right) { | ||
PopupActionSetting.show(parent.absolute-position.x + self.mouse-x, parent.absolute-position.y + self.mouse-y, [ | ||
{ icon: Icons.delete, text: "Delete", action: "delete-item" }, | ||
{ icon: Icons.add-fill, text: "Add", action: "add-item" }, | ||
{ icon: Icons.recover-from-trash, text: "Remove trash", action: "remove-all-cache" } | ||
]); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
HorizontalLayout { | ||
alignment: LayoutAlignment.center; | ||
|
||
SettingIconsBar { | ||
background: Theme.secondary-background; | ||
h-padding: Theme.spacing * 2; | ||
h-spacing: Theme.padding * 5; | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.