Compare commits
2 Commits
8550420711
...
v0.1.2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
df5752d013 | ||
|
|
05a57dc4c8 |
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -2752,7 +2752,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "my-clock"
|
name = "my-clock"
|
||||||
version = "0.1.1"
|
version = "0.1.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"embed-resource",
|
"embed-resource",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "my-clock"
|
name = "my-clock"
|
||||||
version = "0.1.1"
|
version = "0.1.2"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
51
src/main.rs
51
src/main.rs
@@ -3,7 +3,7 @@ use chrono::{Local, Timelike};
|
|||||||
|
|
||||||
slint::slint! {
|
slint::slint! {
|
||||||
export component AppWindow inherits Window {
|
export component AppWindow inherits Window {
|
||||||
title: "Modern Clock";
|
title: "时钟";
|
||||||
icon: @image-url("../assets/icon.png");
|
icon: @image-url("../assets/icon.png");
|
||||||
no-frame: true;
|
no-frame: true;
|
||||||
background: transparent;
|
background: transparent;
|
||||||
@@ -15,6 +15,7 @@ slint::slint! {
|
|||||||
in-out property <float> minute: 0.0;
|
in-out property <float> minute: 0.0;
|
||||||
in-out property <float> second: 0.0;
|
in-out property <float> second: 0.0;
|
||||||
in-out property <bool> is_on_top: true;
|
in-out property <bool> is_on_top: true;
|
||||||
|
in-out property <bool> is_dark_mode: false;
|
||||||
in-out property <float> dial_opacity: 0.92;
|
in-out property <float> dial_opacity: 0.92;
|
||||||
in-out property <length> clock_size: 300px;
|
in-out property <length> clock_size: 300px;
|
||||||
|
|
||||||
@@ -29,7 +30,7 @@ slint::slint! {
|
|||||||
x: touch_area.mouse-x;
|
x: touch_area.mouse-x;
|
||||||
y: touch_area.mouse-y;
|
y: touch_area.mouse-y;
|
||||||
width: 160px;
|
width: 160px;
|
||||||
height: 200px;
|
height: 240px;
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
background: #1e1e1e;
|
background: #1e1e1e;
|
||||||
@@ -52,6 +53,14 @@ slint::slint! {
|
|||||||
t1 := TouchArea { clicked => { root.toggle_always_on_top(); menu_popup.close(); } }
|
t1 := TouchArea { clicked => { root.toggle_always_on_top(); menu_popup.close(); } }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Rectangle {
|
||||||
|
height: 30px;
|
||||||
|
background: t_theme.has-hover ? #333 : transparent;
|
||||||
|
border-radius: 4px;
|
||||||
|
Text { text: root.is_dark_mode ? "亮色主题" : "暗色主题"; color: #ddd; font-size: 14px; }
|
||||||
|
t_theme := TouchArea { clicked => { root.is_dark_mode = !root.is_dark_mode; menu_popup.close(); } }
|
||||||
|
}
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
height: 30px;
|
height: 30px;
|
||||||
background: t2.has-hover ? #333 : transparent;
|
background: t2.has-hover ? #333 : transparent;
|
||||||
@@ -102,7 +111,9 @@ slint::slint! {
|
|||||||
// 背景渐变层
|
// 背景渐变层
|
||||||
Rectangle {
|
Rectangle {
|
||||||
width: 100%; height: 100%;
|
width: 100%; height: 100%;
|
||||||
background: @radial-gradient(circle, #fff9a0 0%, #ffcc33 100%);
|
background: root.is_dark_mode ?
|
||||||
|
@radial-gradient(circle, #3a5dbd 0%, #1a2a6c 70%, #000055 100%) :
|
||||||
|
@radial-gradient(circle, #fff9a0 0%, #ffcc33 100%);
|
||||||
opacity: root.dial_opacity;
|
opacity: root.dial_opacity;
|
||||||
border-radius: self.width / 2;
|
border-radius: self.width / 2;
|
||||||
}
|
}
|
||||||
@@ -112,13 +123,13 @@ slint::slint! {
|
|||||||
width: 100%; height: 100%;
|
width: 100%; height: 100%;
|
||||||
border-radius: self.width / 2;
|
border-radius: self.width / 2;
|
||||||
border-width: 2.5px;
|
border-width: 2.5px;
|
||||||
border-color: rgba(255, 255, 255, 0.4);
|
border-color: root.is_dark_mode ? rgba(100, 150, 255, 0.3) : rgba(255, 255, 255, 0.4);
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
width: 97%; height: 97%;
|
width: 97%; height: 97%;
|
||||||
border-radius: self.width / 2;
|
border-radius: self.width / 2;
|
||||||
border-width: 1.2px;
|
border-width: 1.2px;
|
||||||
border-color: rgba(255, 255, 255, 0.2);
|
border-color: root.is_dark_mode ? rgba(100, 150, 255, 0.15) : rgba(255, 255, 255, 0.2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,18 +137,24 @@ slint::slint! {
|
|||||||
Rectangle {
|
Rectangle {
|
||||||
width: 100%; height: 100%;
|
width: 100%; height: 100%;
|
||||||
border-radius: self.width / 2;
|
border-radius: self.width / 2;
|
||||||
background: @radial-gradient(circle, rgba(255, 255, 255, 0.15) 0%, transparent 80%);
|
background: root.is_dark_mode ?
|
||||||
|
@radial-gradient(circle, rgba(100, 150, 255, 0.1) 0%, transparent 80%) :
|
||||||
|
@radial-gradient(circle, rgba(255, 255, 255, 0.15) 0%, transparent 80%);
|
||||||
}
|
}
|
||||||
|
|
||||||
for i in 12 : Path {
|
for i in 60 : Path {
|
||||||
viewbox-width: 100; viewbox-height: 100;
|
viewbox-width: 100; viewbox-height: 100;
|
||||||
width: 100%; height: 100%;
|
width: 100%; height: 100%;
|
||||||
stroke: rgba(0, 0, 0, 0.5);
|
property <bool> is_hour: (Math.mod(i, 5) == 0);
|
||||||
stroke-width: 2px;
|
stroke: root.is_dark_mode ?
|
||||||
property <float> angle: i * 30;
|
(is_hour ? rgba(200, 220, 255, 0.5) : rgba(200, 220, 255, 0.25)) :
|
||||||
|
(is_hour ? rgba(0, 0, 0, 0.5) : rgba(0, 0, 0, 0.25));
|
||||||
|
stroke-width: is_hour ? 2px : 1px;
|
||||||
|
property <float> angle: i * 6;
|
||||||
|
property <float> start_r: is_hour ? 42 : 45;
|
||||||
MoveTo {
|
MoveTo {
|
||||||
x: 50 + Math.sin(parent.angle * 1deg) * 42;
|
x: 50 + Math.sin(parent.angle * 1deg) * parent.start_r;
|
||||||
y: 50 - Math.cos(parent.angle * 1deg) * 42;
|
y: 50 - Math.cos(parent.angle * 1deg) * parent.start_r;
|
||||||
}
|
}
|
||||||
LineTo {
|
LineTo {
|
||||||
x: 50 + Math.sin(parent.angle * 1deg) * 47;
|
x: 50 + Math.sin(parent.angle * 1deg) * 47;
|
||||||
@@ -155,7 +172,7 @@ slint::slint! {
|
|||||||
x: parent.width / 2 + Math.sin(rad * 1rad) * r - self.width / 2;
|
x: parent.width / 2 + Math.sin(rad * 1rad) * r - self.width / 2;
|
||||||
y: parent.height / 2 - Math.cos(rad * 1rad) * r - self.height / 2;
|
y: parent.height / 2 - Math.cos(rad * 1rad) * r - self.height / 2;
|
||||||
text: entry.t;
|
text: entry.t;
|
||||||
color: rgba(0, 0, 0, 0.7);
|
color: root.is_dark_mode ? rgba(255, 255, 255, 0.8) : rgba(0, 0, 0, 0.7);
|
||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
}
|
}
|
||||||
@@ -163,7 +180,7 @@ slint::slint! {
|
|||||||
Path {
|
Path {
|
||||||
viewbox-width: 100; viewbox-height: 100;
|
viewbox-width: 100; viewbox-height: 100;
|
||||||
width: 100%; height: 100%;
|
width: 100%; height: 100%;
|
||||||
stroke: #1a1a1a;
|
stroke: root.is_dark_mode ? #e0e0e0 : #1a1a1a;
|
||||||
stroke-width: 5px;
|
stroke-width: 5px;
|
||||||
MoveTo { x: 50; y: 50; }
|
MoveTo { x: 50; y: 50; }
|
||||||
LineTo {
|
LineTo {
|
||||||
@@ -175,7 +192,7 @@ slint::slint! {
|
|||||||
Path {
|
Path {
|
||||||
viewbox-width: 100; viewbox-height: 100;
|
viewbox-width: 100; viewbox-height: 100;
|
||||||
width: 100%; height: 100%;
|
width: 100%; height: 100%;
|
||||||
stroke: #333333;
|
stroke: root.is_dark_mode ? #bdbdbd : #333333;
|
||||||
stroke-width: 3.5px;
|
stroke-width: 3.5px;
|
||||||
MoveTo { x: 50; y: 50; }
|
MoveTo { x: 50; y: 50; }
|
||||||
LineTo {
|
LineTo {
|
||||||
@@ -200,10 +217,10 @@ slint::slint! {
|
|||||||
x: (parent.width - self.width) / 2;
|
x: (parent.width - self.width) / 2;
|
||||||
y: (parent.height - self.height) / 2;
|
y: (parent.height - self.height) / 2;
|
||||||
width: 8px; height: 8px;
|
width: 8px; height: 8px;
|
||||||
background: #1a1a1a;
|
background: root.is_dark_mode ? #e0e0e0 : #1a1a1a;
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
border-width: 1.5px;
|
border-width: 1.5px;
|
||||||
border-color: #ffcc33;
|
border-color: root.is_dark_mode ? #1a2a6c : #ffcc33;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user