Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added TimePicker widget #5251

Merged
merged 33 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
0f2c580
TimePicker: startup
FloVanGH Apr 18, 2024
6a90157
TimePicker: base styles and documentation
FloVanGH May 2, 2024
13904ec
TimePicker: cleanup, tests and refactoring
FloVanGH May 13, 2024
d36d613
TimePicker: small improvements to the docs
FloVanGH May 17, 2024
c09e33e
TimePicker: code review feedback fix in the docu
FloVanGH May 29, 2024
6171d93
TimePicker: code cleanup
FloVanGH May 29, 2024
ae78fd0
TimePicker: fixed material button
FloVanGH May 31, 2024
51cebbb
Update internal/compiler/widgets/common/time-picker-base.slint
FloVanGH May 31, 2024
edd62cf
TimePicker: move title to base
FloVanGH May 31, 2024
3f72923
TimePicker: wip 24 hour format refactoring
FloVanGH Jun 3, 2024
6b81a84
Update internal/compiler/widgets/common/internal-components.slint
FloVanGH May 31, 2024
676cf18
Update internal/compiler/widgets/fluent-base/time-picker.slint
FloVanGH May 31, 2024
5d4d850
Update tests/cases/widgets/timepicker.slint
FloVanGH May 31, 2024
8fdf202
Update internal/compiler/widgets/qt/time-picker.slint
FloVanGH May 31, 2024
bfbd4d2
Update internal/compiler/widgets/material-base/time-picker.slint
FloVanGH May 31, 2024
7d576a6
Update internal/compiler/widgets/cupertino-base/time-picker.slint
FloVanGH May 31, 2024
575e67f
Update internal/compiler/widgets/cosmic-base/time-picker.slint
FloVanGH May 31, 2024
b1b431a
Update internal/compiler/widgets/common/time-picker-base.slint
FloVanGH May 31, 2024
1f258cc
Update docs/reference/src/language/widgets/timepicker.md
FloVanGH May 31, 2024
19c4fde
Update docs/reference/src/language/widgets/timepicker.md
FloVanGH May 31, 2024
fa93b2e
Update docs/reference/src/language/widgets/timepicker.md
FloVanGH May 31, 2024
3d8f9f0
TimePicker: use 24 hour format cpp
FloVanGH Jun 3, 2024
2153d1b
Update internal/core/date_time.rs
FloVanGH Jun 4, 2024
657ee30
Fix typo
tronical Jun 5, 2024
428d93c
Remove stray debug call
tronical Jun 5, 2024
0e091a9
TimePicker: added second field to Time
FloVanGH Jun 5, 2024
75bd4e1
Remove unused NativeTime struct
tronical Jun 5, 2024
d72b284
Add missing icons to the Qt time picker input toggle
tronical Jun 5, 2024
8144418
Use use-24-hour-format function from SlintInternals basis for the tim…
tronical Jun 5, 2024
06fbcd6
Add missing code fence closure for time picker test
tronical Jun 5, 2024
7edad71
Fix reuse check
tronical Jun 5, 2024
d8d736d
Make the time picker tests pass in Rust and C++
tronical Jun 5, 2024
0b5551d
Fix timepicker C++ test with picky compilers :)
tronical Jun 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .reuse/dep5
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ Files: internal/compiler/widgets/cosmic-base/_*.svg
Copyright: "Cosmic Icons" by System76 <https://github.com/pop-os/cosmic-icons>
License: CC-BY-SA-4.0

Files: internal/compiler/widgets/qt/_*.svg
Copyright: "Cosmic Icons" by System76 <https://github.com/pop-os/cosmic-icons>
License: CC-BY-SA-4.0

Files: internal/backends/linuxkms/mouse-pointer.svg examples/virtual_keyboard/ui/assets/*.svg examples/ffmpeg/pause.svg examples/ffmpeg/play.svg examples/gstreamer-player/*.svg examples/uefi-demo/resource/cursor.png
Copyright: Copyright © 2018 Dave Gandy & Fork Awesome
License: MIT
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ All notable changes to this project are documented in this file.
- Fixed set current-index of ComboBox to -1 does not reset current-value
- Fixed issue where the text of `SpinBox` is not updated after value is changed from outside
- Added `step-size` to `SpinBox`
- Added `TimePicker` widget.

## [1.6.0] - 2024-05-13

Expand Down
5 changes: 5 additions & 0 deletions api/cpp/include/slint.h
Original file line number Diff line number Diff line change
Expand Up @@ -1266,6 +1266,11 @@ inline SharedString translate(const SharedString &original, const SharedString &
return result;
}

inline bool use_24_hour_format()
{
return cbindgen_private::slint_use_24_hour_format();
}

} // namespace private_api

#ifdef SLINT_FEATURE_GETTEXT
Expand Down
4 changes: 4 additions & 0 deletions api/rs/slint/private_unstable_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ pub fn init_translations(domain: &str, dirname: impl Into<std::path::PathBuf>) {
i_slint_core::translations::gettext_bindtextdomain(domain, dirname.into()).unwrap()
}

pub fn use_24_hour_format() -> bool {
i_slint_core::date_time::use_24_hour_format()
}

/// internal re_exports used by the macro generated
pub mod re_exports {
pub use alloc::boxed::Box;
Expand Down
1 change: 1 addition & 0 deletions docs/reference/src/language/widgets/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ Widgets
tabwidget.md
textedit.md
verticalbox.md
timepicker.md
63 changes: 63 additions & 0 deletions docs/reference/src/language/widgets/timepicker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<!-- Copyright © SixtyFPS GmbH <info@slint.dev> ; SPDX-License-Identifier: MIT -->

## struct `Time`

Defines a time with hours, minutes, and seconds.

### Fields

- **`hour`(int)**: The hour value (range from 0 to 23).
- **`minute`(int)**: The minute value (range from 1 to 59).
- **`second`(int)**: The second value (range form 1 to 59).

## `TimePicker`

Use the timer picker to select the time, in either 24-hour or 12-hour mode (AM/PM).

### Properties

- **`use-24-hour-format`**: (_in_ _bool_): If set to `true` 24 hours are displayed otherwise it is displayed in AM/PM mode. (default: system default, if cannot be determined then `true`)
- **`title`** (_in_ _string_): The text that is displayed at the top of the picker.
- **`cancel-label`** (_in_ _string_): The text written in the cancel button.
- **`ok-label`** (_in_ _string_): The text written in the ok button.
- **`time`**: (_in_ _Time_): Set the initial displayed time.

### Callbacks

- **`canceled()`**: The cancel button was clicked.
- **`accepted(Time)`** The ok button was clicked.

### Example

```slint
import { TimePicker, Button } from "std-widgets.slint";
export component Example inherits Window {
width: 600px;
height: 600px;

time-picker-button := Button {
text: @tr("Open TimePicker");

clicked => {
time-picker.show();
}
}

time-picker := PopupWindow {
width: 340px;
height: 500px;
close-on-click: false;

TimePicker {
canceled => {
time-picker.close();
}

accepted(time) => {
debug(time);
time-picker.close();
}
}
}
}
```
31 changes: 29 additions & 2 deletions examples/gallery/ui/pages/controls_page.slint
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: MIT

import { Button, GroupBox, SpinBox, ComboBox, CheckBox, LineEdit, TabWidget, VerticalBox, HorizontalBox,
Slider, ProgressIndicator, SpinBox, Switch, Spinner, GridBox } from "std-widgets.slint";
Slider, ProgressIndicator, SpinBox, Switch, Spinner, GridBox, TimePicker } from "std-widgets.slint";
import { GallerySettings } from "../gallery_settings.slint";
import { Page } from "page.slint";

Expand Down Expand Up @@ -87,7 +87,7 @@ export component ControlsPage inherits Page {
}

GroupBox {
title: @tr("LineEdit - SpinBox");
title: @tr("LineEdit - SpinBox - TimePicker");
vertical-stretch: 0;

HorizontalBox {
Expand All @@ -104,6 +104,14 @@ export component ControlsPage inherits Page {
value: 42;
enabled: GallerySettings.widgets-enabled;
}

time-picker-button := Button {
text: @tr("Open TimePicker");

clicked => {
time-picker.show();
}
}
}
}

Expand Down Expand Up @@ -139,6 +147,7 @@ export component ControlsPage inherits Page {
row: 0;
col: 1;
rowspan: 2;

Spinner {
progress: i-progress-indicator.progress;
indeterminate: i-progress-indicator.indeterminate;
Expand Down Expand Up @@ -211,4 +220,22 @@ export component ControlsPage inherits Page {
}
}
}

time-picker := PopupWindow {
x: (root.width - 340px) / 2;
y: (root.height - 500px) / 2;
width: 340px;
height: 500px;
close-on-click: false;

TimePicker {
canceled => {
time-picker.close();
}

accepted(time) => {
time-picker.close();
}
}
}
}
6 changes: 6 additions & 0 deletions internal/compiler/expression_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ pub enum BuiltinFunction {
RegisterCustomFontByMemory,
RegisterBitmapFont,
Translate,
Use24HourFormat,
}

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -273,6 +274,9 @@ impl BuiltinFunction {
Type::Array(Type::String.into()),
],
},
BuiltinFunction::Use24HourFormat => {
Type::Function { return_type: Box::new(Type::Bool), args: vec![] }
}
}
}

Expand Down Expand Up @@ -330,6 +334,7 @@ impl BuiltinFunction {
| BuiltinFunction::RegisterCustomFontByMemory
| BuiltinFunction::RegisterBitmapFont => false,
BuiltinFunction::Translate => false,
BuiltinFunction::Use24HourFormat => false,
}
}

Expand Down Expand Up @@ -380,6 +385,7 @@ impl BuiltinFunction {
| BuiltinFunction::RegisterCustomFontByMemory
| BuiltinFunction::RegisterBitmapFont => false,
BuiltinFunction::Translate => true,
BuiltinFunction::Use24HourFormat => true,
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions internal/compiler/generator/cpp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3321,6 +3321,9 @@ fn compile_builtin_function_call(
BuiltinFunction::Translate => {
format!("slint::private_api::translate({})", a.join(","))
}
BuiltinFunction::Use24HourFormat => {
format!("slint::private_api::use_24_hour_format()")
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions internal/compiler/generator/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2666,6 +2666,9 @@ fn compile_builtin_function_call(
BuiltinFunction::Translate => {
quote!(slint::private_unstable_api::translate(#((#a) as _),*))
}
BuiltinFunction::Use24HourFormat => {
quote!(slint::private_unstable_api::use_24_hour_format())
}
BuiltinFunction::ItemAbsolutePosition => {
if let [Expression::PropertyReference(pr)] = arguments {
let item_rc = access_item_rc(pr, ctx);
Expand Down
1 change: 1 addition & 0 deletions internal/compiler/llr/optim_passes/inline_expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ fn builtin_function_cost(function: &BuiltinFunction) -> isize {
BuiltinFunction::SetTextInputFocused => PROPERTY_ACCESS_COST,
BuiltinFunction::TextInputFocused => PROPERTY_ACCESS_COST,
BuiltinFunction::Translate => 2 * ALLOC_COST + PROPERTY_ACCESS_COST,
BuiltinFunction::Use24HourFormat => 2 * ALLOC_COST + PROPERTY_ACCESS_COST,
}
}

Expand Down
38 changes: 29 additions & 9 deletions internal/compiler/lookup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -814,16 +814,36 @@ impl LookupObject for SlintInternal {
ctx: &LookupCtx,
f: &mut impl FnMut(&str, LookupResult) -> Option<R>,
) -> Option<R> {
f(
"color-scheme",
Expression::FunctionCall {
function: Expression::BuiltinFunctionReference(BuiltinFunction::ColorScheme, None)
None.or_else(|| {
f(
"color-scheme",
Expression::FunctionCall {
function: Expression::BuiltinFunctionReference(
BuiltinFunction::ColorScheme,
None,
)
.into(),
arguments: vec![],
source_location: ctx.current_token.as_ref().map(|t| t.to_source_location()),
}
.into(),
)
arguments: vec![],
source_location: ctx.current_token.as_ref().map(|t| t.to_source_location()),
}
.into(),
)
.or_else(|| {
f(
"use-24-hour-format",
Expression::FunctionCall {
function: Expression::BuiltinFunctionReference(
BuiltinFunction::Use24HourFormat,
None,
)
.into(),
arguments: vec![],
source_location: ctx.current_token.as_ref().map(|t| t.to_source_location()),
}
.into(),
)
})
})
}
}

Expand Down
8 changes: 8 additions & 0 deletions internal/compiler/widgets/common/internal-components.slint
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// 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

export struct TextStyle {
font-size: length,
font-weight: int,
foreground: brush,
}
Loading
Loading