MCPcopy Create free account
hub / github.com/DioxusLabs/dioxus-components / SliderImpl

Function SliderImpl

primitives/src/slider.rs:304–443  ·  view source on GitHub ↗
(props: SliderImplProps)

Source from the content-addressed store, hash-verified

302
303#[component]
304fn SliderImpl(props: SliderImplProps) -> Element {
305 let orientation = if props.horizontal {
306 "horizontal"
307 } else {
308 "vertical"
309 };
310
311 let mut dragging = use_signal(|| false);
312 // Index of the thumb currently being interacted with via pointer. Only meaningful while
313 // `dragging` is true; reads outside a drag may return a stale value from the prior interaction.
314 let active_thumb = use_signal(|| 0usize);
315
316 let ctx = use_context_provider(|| SliderContext {
317 thumbs: props.thumbs,
318 set_thumb: props.set_thumb,
319 min: props.min,
320 max: props.max,
321 step: props.step,
322 disabled: props.disabled,
323 horizontal: props.horizontal,
324 inverted: props.inverted,
325 dragging: dragging.into(),
326 active_thumb,
327 label: props.label,
328 });
329
330 let mut movement = use_move_interaction(dragging);
331 let mut granular_thumbs = use_hook(move || CopyValue::new(props.thumbs.peek().clone()));
332
333 let size = movement.rect().map(|r| {
334 if props.horizontal {
335 r.width()
336 } else {
337 r.height()
338 }
339 });
340
341 use_effect(move || {
342 if !dragging() {
343 return;
344 }
345
346 let Some(size) = size else {
347 return;
348 };
349
350 let Some(move_event) = movement.pointer_move() else {
351 return;
352 };
353
354 let delta_pos = if ctx.horizontal {
355 move_event.delta_x
356 } else {
357 move_event.delta_y
358 };
359
360 let value_delta = delta_pos / size * ctx.range_size();
361

Callers

nothing calls this directly

Calls 5

use_move_interactionFunction · 0.85
rectMethod · 0.80
pointer_moveMethod · 0.80
range_sizeMethod · 0.80
clamp_forMethod · 0.80

Tested by

no test coverage detected