slint-ui / slint

Slint is a declarative GUI toolkit to build native user interfaces for Rust, C++, or JavaScript apps.
https://slint.dev
Other
17.55k stars 601 forks source link

TimePicker widget #5087

Closed FloVanGH closed 5 months ago

FloVanGH commented 6 months ago

This task is part of #46 (Initial Android support).

image

Base requirements

References

FloVanGH commented 6 months ago

API draft

This is the collection of some ideas how the TimePicker could looks like from API side and should be used as base for discussions.

export component TimePicker {
      in-out property <date-time> current-time;
      in property <string> local: "en_US";
}

Use as component and inside of a PopupWindow

import { Button, TimePicker } from "std-widgets.slint";

export component MainWindow inherits Window {
      width: 600px;
      height: 400px;

      time-picker-popup := PopupWindow {
          width: 200px;
          height: 200px;

          TimePicker {}
      }

      VerticalLayout {
          time-picker := TimePicker {}
          Text {
              text: time-picker.current-time;
          }

          Button {
                text: "Open TimePicker Popup";
                clicked => {
                    time-picker-popup.show();
                }
          }
      }

}

Ready to use dialog

export component TimePickerPopup {
      in-out property <date-time> current-time;
      in property <string> local: "en_US";

      public function show() -> date-time {
            //...
      }
}
import { TimePickerPopup } from "std-widgets.slint";

export component MainWindow inherits Window {
      width: 600px;
      height: 400px;

      time-picker-popup := TimePickerPopup {
            width: 200px;
            height: 200px;
      }

        Button {
                text: "Open TimePicker Popup";
                clicked => {
                    debug(time-picker-popup.show());
                }
          }
}

Use with LineEdit

The idea is that if input-type of LineEdit is set and it gets focus a time picker popup open automatically. As alternative a more explicit method that give more flexibility when the popup should be open could be possible.

import { LineEdit } from "std-widgets.slint";

export component MainWindow inherits Window {
      width: 600px;
      height: 400px;

      LineEdit {
            input-type:  InputType.time;
      }
}
WilstonOreo commented 6 months ago

Regarding the date-time type, I added a separate issue to track this: https://github.com/slint-ui/slint/issues/5122