slint/internal/compiler/widgets/qt/time-picker.slint
Arkadiusz Żmudzin d89f8cfe17
Align DatePickerPopup and TimePickerPopup placement logic (#9410)
Updated the `width` and `height` properties of `DatePickerPopup` and `TimePickerPopup` components to use dynamic sizing based on `dialog` dimensions instead of fixed pixel values.

Previously, the lack of `width` and `height` in `TimePickerPopup` caused inconsistent placement when displayed at a specific location:
- `DatePickerPopup` was centered on the given (x, y)
- `TimePickerPopup` used its top-left corner as the anchor point

Now both components consistently render centered at the specified (x, y).

Fixes #9262
2025-09-15 09:46:39 +02:00

111 lines
3.6 KiB
Text

// Copyright © SixtyFPS GmbH <info@slint.dev>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
import { Time, TimePickerBase } from "../common/time-picker-base.slint";
import { VerticalBox } from "../common/layout.slint";
import { Button } from "./button.slint";
import { Palette } from "./std-widgets-impl.slint";
import { Icons } from "./styling.slint";
import { StandardButton } from "../common/standardbutton.slint";
export { Time }
export component TimePickerPopup inherits PopupWindow {
in property <bool> use-24-hour-format <=> base.use-24-hour-format;
in property <string> title: "Select time";
in property <Time> time <=> base.time;
callback canceled();
callback accepted(/* current-time */ Time);
width: dialog.width;
height: dialog.height;
close-policy: PopupClosePolicy.no-auto-close;
background-layer := Rectangle {
width: dialog.width;
height: dialog.height;
border-radius: 8px;
background: Palette.control-background;
}
dialog := Dialog {
padding: 8px;
base := TimePickerBase {
title: root.title;
style: {
foreground: Palette.foreground,
vertical-spacing: 8px,
horizontal-spacing: 4px,
clock-style: {
background: Palette.alternate-background,
foreground: Palette.accent-background,
time-selector-style: {
foreground: Palette.foreground,
foreground-selected: Palette.accent-foreground,
font-size: 12 * 0.0625rem,
font-weight: 400
}
},
input-style: {
background: Palette.alternate-background,
background-selected: Palette.accent-background,
foreground: Palette.foreground,
foreground-selected: Palette.foreground,
border-radius: 8px,
font-size: 57 * 0.0625rem,
font-weight: 400
},
period-selector-style: {
border-radius: 8px,
border-width: 1px,
border-brush: Palette.border,
item-style: {
font-size: 14 * 0.0625rem,
font-weight: 400,
foreground: Palette.foreground,
background-selected: Palette.accent-background,
foreground-selected: Palette.accent-foreground
}
},
title-style: {
font-size: 12 * 0.0625rem,
font-weight: 300,
foreground: Palette.foreground,
},
};
}
Button {
icon: base.selection-mode ? Icons.keyboard : Icons.clock;
colorize-icon: true;
accessible-label: "Toggle input picker";
dialog-button-role: action;
clicked => {
base.selection-mode = !base.selection-mode;
}
}
StandardButton {
kind: cancel;
clicked => {
root.close();
root.canceled();
}
}
StandardButton {
enabled: base.ok-enabled();
kind: ok;
clicked => {
root.close();
root.accepted(base.get-current-time());
}
}
}
}