Skip to content

Commit

Permalink
[*] improve ui
Browse files Browse the repository at this point in the history
  • Loading branch information
heng30 committed Sep 13, 2024
1 parent 6ab2caa commit cd4d599
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/logic/toast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ pub fn init(ui: &AppWindow) {
2
};

ui.global::<ToastSetting>().set_is_timeout(false);
ui.global::<ToastSetting>().invoke_set(msg, status);

timer.start(
TimerMode::SingleShot,
std::time::Duration::from_secs(interval),
move || {
ui.global::<ToastSetting>()
.invoke_set("".into(), ToastStatus::None);
ui.global::<ToastSetting>().set_is_timeout(true);
},
);
});
Expand Down
2 changes: 1 addition & 1 deletion ui/android-window.slint
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export component AppWindow inherits Window {
width: Math.min(root.width * 0.9, self.vbox-preferred-width * 2);
}

if ToastSetting.text != "" && ToastSetting.status != ToastStatus.None: Toast {
if !ToastSetting.is-timeout || ToastSetting.is-hover: Toast {
x: root.width / 2 - self.width / 2;
y: 50px;
inner-max-width: root.width * 80%;
Expand Down
7 changes: 5 additions & 2 deletions ui/base/check-btn.slint
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export component CheckBtn inherits Rectangle {
in-out property <bool> checked;
in-out property <color> text-color: Theme.primary-text-color;

in-out property h-spacing <=> hbox.spacing;

width: hbox.preferred-width;
height: hbox.preferred-height;

Expand All @@ -21,7 +23,7 @@ export component CheckBtn inherits Rectangle {
}

hbox := HorizontalLayout {
spacing: Theme.spacing * 4;
spacing: Theme.spacing * 2;
alignment: start;

VerticalLayout {
Expand All @@ -32,11 +34,12 @@ export component CheckBtn inherits Rectangle {
border-width: 2px;
border-radius: Theme.border-radius;
border-color: root.enabled ? (root.checked ? Theme.thirdly-brand-color : Theme.secondary-text-color) : Theme.disabled-color;
background: root.checked ? (root.enabled ? Theme.thirdly-brand-color : Colors.transparent) : Colors.transparent;

if root.checked: Image {
width: 60%;
height: self.width;
colorize: parent.border-color;
colorize: root.enabled ? Theme.light-text-color : parent.border-color;
source: Icons.checked;
}
}
Expand Down
1 change: 0 additions & 1 deletion ui/base/def.slint
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export enum ToastStatus {
Info,
Warning,
Danger,
None,
}

export enum ComponentPosition {
Expand Down
8 changes: 5 additions & 3 deletions ui/base/radio-btn.slint
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export component RadioBtn inherits Rectangle {
in-out property <bool> checked;
in-out property <color> text-color: Theme.primary-text-color;

in-out property h-spacing <=> hbox.spacing;

width: hbox.preferred-width;
height: hbox.preferred-height;

Expand All @@ -17,11 +19,11 @@ export component RadioBtn inherits Rectangle {
width: inner.width + Theme.spacing * 4;
height: self.width;
border-radius: self.width / 2;
background: ta.has-hover ? Theme.hover-background : Colors.transparent;
background: (ta.has-hover && !root.checked) ? Theme.hover-background : Colors.transparent;
}

hbox := HorizontalLayout {
spacing: Theme.spacing * 4;
spacing: Theme.spacing * 2;
alignment: start;

VerticalLayout {
Expand Down Expand Up @@ -53,7 +55,7 @@ export component RadioBtn inherits Rectangle {
fs := FocusScope { }

ta := TouchArea {
mouse-cursor: MouseCursor.pointer;
mouse-cursor: root.checked ? MouseCursor.default : MouseCursor.pointer;
clicked => {
fs.focus();

Expand Down
15 changes: 13 additions & 2 deletions ui/base/toast.slint
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { ToastStatus } from "def.slint";
export global ToastSetting {
in-out property <string> text;
in-out property <ToastStatus> status;
in-out property <bool> is-hover;
in-out property <bool> is-timeout: true;

public function set(text: string, status: ToastStatus) {
self.text = text;
Expand All @@ -15,7 +17,7 @@ export global ToastSetting {
}

export component Toast inherits Rectangle {
in-out property<length> inner-max-width: 300px;
in-out property <length> inner-max-width: 300px;

callback clicked <=> touch.clicked;

Expand Down Expand Up @@ -48,5 +50,14 @@ export component Toast inherits Rectangle {
}
}

touch := TouchArea { }
touch := TouchArea {
mouse-cursor: self.has-hover ? MouseCursor.pointer : MouseCursor.default;
changed has-hover => {
if (self.has-hover) {
ToastSetting.is-hover = true;
} else {
ToastSetting.is-hover = false;
}
}
}
}
2 changes: 1 addition & 1 deletion ui/desktop-window.slint
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export component AppWindow inherits Window {
width: Math.min(root.width * 0.9, self.vbox-preferred-width * 2);
}

if ToastSetting.text != "" && ToastSetting.status != ToastStatus.None: Toast {
if !ToastSetting.is-timeout || ToastSetting.is-hover: Toast {
x: root.width / 2 - self.width / 2;
y: 50px;
inner-max-width: root.width * 80%;
Expand Down
12 changes: 12 additions & 0 deletions ui/panel/desktop/examples/button.slint
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ export component ButtonExample inherits Flickable {
text: Logic.tr("Disable");
enabled: false;
}

CheckBtn {
text: Logic.tr("Disable");
checked: true;
enabled: false;
}
}

code: "HorizontalLayout {\n spacing: Theme.spacing * 20;\n\n CheckBtn {\n text: Logic.tr(self.checked ? \"Checked\" : \"Unchecked\");\n\n toggled => {\n debug(self.checked);\n }\n }\n\n CheckBtn {\n text: Logic.tr(\"Disable\");\n enabled: false;\n }\n}";
Expand Down Expand Up @@ -96,6 +102,12 @@ export component ButtonExample inherits Flickable {
text: Logic.tr("Disable");
enabled: false;
}

RadioBtn {
text: Logic.tr("Disable");
checked: true;
enabled: false;
}
}

code: "HorizontalLayout {\n spacing: Theme.spacing * 20;\n\n RadioBtn {\n text: Logic.tr(\"Unchecked\");\n\n check => {\n self.checked = !self.checked;\n debug(self.checked);\n }\n }\n\n RadioBtn {\n text: Logic.tr(\"Checked\");\n checked: true;\n\n check => {\n debug(self.checked);\n }\n }\n\n RadioBtn {\n text: Logic.tr(\"Disable\");\n }\n}";
Expand Down
3 changes: 2 additions & 1 deletion ui/util.slint
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,9 @@ export global Util {
return Theme.warning-color.darker(10%);
} else if (status == ToastStatus.Danger) {
return Theme.danger-color;
} else {
return Theme.info-color;
}
return Theme.info-color;
}

public pure function icon-source(status: ToastStatus) -> image {
Expand Down
2 changes: 1 addition & 1 deletion ui/web-window.slint
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export component AppWindow inherits Window {
width: Math.min(root.width * 0.9, self.vbox-preferred-width * 2);
}

if ToastSetting.text != "" && ToastSetting.status != ToastStatus.None: Toast {
if !ToastSetting.is-timeout || ToastSetting.is-hover: Toast {
x: root.width / 2 - self.width / 2;
y: 50px;
inner-max-width: root.width * 80%;
Expand Down

0 comments on commit cd4d599

Please sign in to comment.