bevy icon indicating copy to clipboard operation
bevy copied to clipboard

UI Slider Widget

Open Pietrek14 opened this issue 3 years ago • 5 comments

Objective

Added a premade UI slider widget. Fixes #6196.

Solution

  • Added a RelativeCursorPosition component that updates alongside Interaction, which stores the cursor position relative to the node.
  • Added a Slider component that stores values specific to sliders
  • Added a SliderBundle and a SliderHandleBundle
  • Added update_slider_value and update_slider_handle systems
  • Made a slider example in the ui directory

Changelog

  • There is an easy way to create UI sliders now
  • If applicable, organize changes under "Added", "Changed", or "Fixed" sub-headings
  • Added:
    • RelativeCursorPosition component
    • Slider component
    • SliderBundle
    • SliderHandleBundle
    • update_slider_value and update_slider_handle systems
    • slider example

Pietrek14 avatar Oct 11 '22 06:10 Pietrek14

how the example looks like:

https://user-images.githubusercontent.com/8672791/195031790-b3a0c314-32f1-4c58-bb6b-c2c868a2a2ed.mp4

mockersf avatar Oct 11 '22 07:10 mockersf

Based on this approach, I've started working on #6517. Does it make sense that both the slider widget and the progress-widget shares the same representation of "progress"?

Something like this?

struct Progress
{
    /// Max value
    max: f32,
    /// Min value
    min: f32,
    /// Current value of the widget. Somewhere between min and max.
    value: f32,
}

Then SliderWidget could look like

struct Slider
{
    progress: Progress,
    step: f32,
}

And the ProgressBarWidget could look like

struct ProgressBar
{
    progress: Progress,
    direction: Direction,
}

Weibye avatar Nov 12 '22 09:11 Weibye

Note that for the Progress struct, you can't have public fields: you must use getters and setters to ensure invariants. I do generally think you could share those components though.

alice-i-cecile avatar Nov 12 '22 11:11 alice-i-cecile

@Weibye Are you going to open a PR with the Progress struct? If so, please mention it in this thread.

Pietrek14 avatar Nov 14 '22 07:11 Pietrek14

@Weibye Are you going to open a PR with the Progress struct? If so, please mention it in this thread.

Yes! Will try to have it up by end of day.

Weibye avatar Nov 14 '22 07:11 Weibye

I tried fixing the merge conflicts, but I think I just broke it even more. Closing in favor of #7116 .

Pietrek14 avatar Jan 07 '23 02:01 Pietrek14