Files
uno-game/ui/ConnectPage.slint
Kieran Kihn 150e29c25c feat(ui): add dynamic scaling support
- Introduced `scale` property across components for responsive design.
- Adjusted dimensions and positions dynamically based on scale.
- Enhanced flexibility for varying display resolutions.
2025-12-18 11:42:29 +08:00

102 lines
2.8 KiB
Plaintext

import {
VerticalBox,
HorizontalBox,
} from "std-widgets.slint";
import { Button, LabeledInput } from "Components.slint";
export component ConnectPage inherits Rectangle {
in property <float> scale;
in property <bool> is-connecting;
callback request-connect(string, string, string);
width: 100%;
height: 100%;
// 背景渐变 (从左上角的米色到右下角的淡粉色)
Rectangle {
background: @linear-gradient(135deg, #fdfbf7 0%, #f3e7e9 100%);
}
// 中心卡片
Rectangle {
width: 600px * scale;
height: 600px * scale; // 根据内容高度调整
background: #FDFBF8; // 略微区别于背景的米白色
border-radius: 20px * scale;
// 简单的阴影模拟
drop-shadow-blur: 20px * scale;
drop-shadow-color: #00000015;
drop-shadow-offset-y: 4px * scale;
VerticalLayout {
padding: 40px * scale;
spacing: 20px * scale;
alignment: center;
// 标题区域
VerticalLayout {
spacing: 8px * scale;
alignment: center;
Text {
text: "UNO";
font-size: 96px * scale;
font-weight: 700;
color: #222222;
horizontal-alignment: center;
}
Text {
text: "连接至服务器以开始游戏";
font-size: 14px * scale;
color: #666666;
horizontal-alignment: center;
}
}
// 占位间隔
Rectangle {
height: 10px * scale;
}
// 表单区域
address-input := LabeledInput {
scale: root.scale;
label-text: "服务器地址";
value: "localhost";
}
port-input := LabeledInput {
scale: root.scale;
label-text: "服务器端口";
value: "10001";
input-type: InputType.number;
}
name-input := LabeledInput {
scale: root.scale;
label-text: "玩家昵称";
value: "Player";
}
// 底部按钮区域 (增加一点顶部间距)
HorizontalLayout {
padding-top: 10px * scale;
alignment: center;
Button {
scale: root.scale;
text: is-connecting ? "正在连接..." : "连接";
enabled: !is-connecting;
clicked => {
root.request-connect(address-input.value, port-input.value, name-input.value);
}
}
}
}
}
}