pub struct SliderValue {
pub value: f32,
pub min: f32,
pub max: f32,
pub step: Option<f32>,
}Expand description
Bounded scalar state for <slider> entities. value is held in [min, max]; the runtime emits on_slider(id, value) on drag or track click.
Fields§
§value: f32Current value, clamped to [min, max].
min: f32Lower bound.
max: f32Upper bound.
step: Option<f32>Authored step="..." increment for keyboard arrows and wheel
notches. None falls back to (max - min) / 100 - the
<input type=range> browser default of 100 discrete positions
(see Self::step_size).
Implementations§
Source§impl SliderValue
impl SliderValue
Sourcepub fn step_size(&self) -> f32
pub fn step_size(&self) -> f32
Effective step increment: the authored Self::step, or
(max - min) / 100 when unset.
Sourcepub fn clamp(&self, value: f32) -> f32
pub fn clamp(&self, value: f32) -> f32
value held to this slider’s bounds.
The bounds are taken either way round, so a slider authored with its
max below its min still has a range rather than an empty one.
Every path that puts a value on a slider comes through here: the spawner with what the markup authored, the signal binding with what a script wrote, and the web emitter writing the page ahead of both. A second copy of the rule would let a page disagree with the app that adopts it.
Sourcepub fn snap(&self, value: f32) -> f32
pub fn snap(&self, value: f32) -> f32
value moved to the nearest position on this slider’s step grid,
then held to its bounds.
The grid starts at the near bound and rises by Self::step_size,
which is what <input type=range> does and what a QSlider’s
integer range gives for free. A pointer landing anywhere on the
track therefore writes a value the arrow keys could also have
reached, so step="1024" means multiples of 1024 whichever way the
user moved it.
A range that is not a whole number of steps stops short of its far
bound: the last position on the grid is the highest one that fits,
so min="0" max="100" step="30" tops out at 90. That is what
<input type=range> does, and it is the only answer that keeps
every value the control can take on the grid.
A grid position is written with no more decimal places than the near
bound and the step carry between them, so min="0.8" step="0.1"
lands on 0.9 rather than on the 0.90000004 that adding the two in
binary floating point gives. That is the value a bound signal and a
label reading it show.
Trait Implementations§
Source§impl Clone for SliderValue
impl Clone for SliderValue
Source§fn clone(&self) -> SliderValue
fn clone(&self) -> SliderValue
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Component for SliderValue
impl Component for SliderValue
Source§const STORAGE_TYPE: StorageType = bevy_ecs::component::StorageType::Table
const STORAGE_TYPE: StorageType = bevy_ecs::component::StorageType::Table
Source§type Mutability = Mutable
type Mutability = Mutable
Component<Mutability = Mutable>,
while immutable components will instead have Component<Mutability = Immutable>. Read moreSource§fn register_required_components(
_requiree: ComponentId,
required_components: &mut RequiredComponentsRegistrator<'_, '_>,
)
fn register_required_components( _requiree: ComponentId, required_components: &mut RequiredComponentsRegistrator<'_, '_>, )
Source§fn clone_behavior() -> ComponentCloneBehavior
fn clone_behavior() -> ComponentCloneBehavior
Source§fn relationship_accessor() -> Option<ComponentRelationshipAccessor<Self>>
fn relationship_accessor() -> Option<ComponentRelationshipAccessor<Self>>
ComponentRelationshipAccessor] required for working with relationships in dynamic contexts. Read more§fn on_discard() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
fn on_discard() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
§fn on_despawn() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
fn on_despawn() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
§fn map_entities<E>(_this: &mut Self, _mapper: &mut E)where
E: EntityMapper,
fn map_entities<E>(_this: &mut Self, _mapper: &mut E)where
E: EntityMapper,
EntityMapper. This is used to remap entities in contexts like scenes and entity cloning.
When deriving Component, this is populated by annotating fields containing entities with #[entities] Read moreSource§impl Debug for SliderValue
impl Debug for SliderValue
Source§impl Default for SliderValue
impl Default for SliderValue
Source§impl From<&SliderValue> for A11yRole
impl From<&SliderValue> for A11yRole
Source§fn from(_: &SliderValue) -> Self
fn from(_: &SliderValue) -> Self
Source§impl From<&SliderValue> for A11yValue
impl From<&SliderValue> for A11yValue
Source§fn from(s: &SliderValue) -> Self
fn from(s: &SliderValue) -> Self
impl Copy for SliderValue
Auto Trait Implementations§
impl Freeze for SliderValue
impl RefUnwindSafe for SliderValue
impl Send for SliderValue
impl Sync for SliderValue
impl Unpin for SliderValue
impl UnsafeUnpin for SliderValue
impl UnwindSafe for SliderValue
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<C> Bundle for Cwhere
C: Component,
impl<C> Bundle for Cwhere
C: Component,
fn component_ids( components: &mut ComponentsRegistrator<'_>, ) -> impl Iterator<Item = ComponentId> + use<C>
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<C> DynamicBundle for Cwhere
C: Component,
impl<C> DynamicBundle for Cwhere
C: Component,
§unsafe fn get_components(
ptr: MovingPtr<'_, C>,
func: &mut impl FnMut(StorageType, OwningPtr<'_>),
) -> <C as DynamicBundle>::Effect
unsafe fn get_components( ptr: MovingPtr<'_, C>, func: &mut impl FnMut(StorageType, OwningPtr<'_>), ) -> <C as DynamicBundle>::Effect
§unsafe fn apply_effect(
_ptr: MovingPtr<'_, MaybeUninit<C>>,
_entity: &mut EntityWorldMut<'_>,
)
unsafe fn apply_effect( _ptr: MovingPtr<'_, MaybeUninit<C>>, _entity: &mut EntityWorldMut<'_>, )
§impl<T> FromTemplate for T
impl<T> FromTemplate for T
§impl<T> FromWorld for Twhere
T: Default,
impl<T> FromWorld for Twhere
T: Default,
§fn from_world(_world: &mut World) -> T
fn from_world(_world: &mut World) -> T
Creates Self using default().
§impl<T> IntoResult<T> for T
impl<T> IntoResult<T> for T
§fn into_result(self) -> Result<T, RunSystemError>
fn into_result(self) -> Result<T, RunSystemError>
§impl<T> Template for T
impl<T> Template for T
§fn build_template(
&self,
_context: &mut TemplateContext<'_, '_>,
) -> Result<<T as Template>::Output, BevyError>
fn build_template( &self, _context: &mut TemplateContext<'_, '_>, ) -> Result<<T as Template>::Output, BevyError>
entity context to produce a Template::Output.§fn clone_template(&self) -> T
fn clone_template(&self) -> T
Clone.