-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(widgets): 🎸 Added the widget of Slider
- Loading branch information
1 parent
1b8026a
commit 0145549
Showing
7 changed files
with
535 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+1.87 KB
test_cases/ribir_widgets/slider/tests/slider_widgets_with_default_by_wgpu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+4.56 KB
test_cases/ribir_widgets/slider/tests/slider_widgets_with_material_by_wgpu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
use ribir_core::prelude::*; | ||
use ribir_widgets::prelude::*; | ||
|
||
use crate::md; | ||
|
||
const INDICATOR_HEIGHT: f32 = 44.; | ||
const TRACK_HEIGHT: f32 = 16.; | ||
const TRACK_WIDTH: f32 = 4.; | ||
|
||
const SMALL_RADIUS: f32 = 2.; | ||
const LARGE_RADIUS: f32 = 8.; | ||
const STOP_INDICATOR_MARGIN: EdgeInsets = EdgeInsets::horizontal(6.); | ||
const STOP_INDICATOR_SIZE: Size = Size::new(4., 4.); | ||
|
||
class_names! { | ||
BASE_SLIDER_TRACK, | ||
} | ||
|
||
macro_rules! stop_indicator_class { | ||
($($field: ident: $value: expr),* ) => { | ||
style_class! { | ||
v_align: VAlign::Center, | ||
border_radius: Radius::all(SMALL_RADIUS), | ||
margin: STOP_INDICATOR_MARGIN, | ||
clamp: BoxClamp::fixed_size(STOP_INDICATOR_SIZE), | ||
$($field: $value),* | ||
} | ||
}; | ||
} | ||
|
||
pub(super) fn init(classes: &mut Classes) { | ||
classes.insert(BASE_SLIDER_TRACK, |w| { | ||
fn_widget! { | ||
let flex = Provider::of::<Stateful<Expanded>>(BuildCtx::get()).unwrap(); | ||
part_writer!(&mut flex.flex).transition( | ||
EasingTransition { | ||
easing: easing::LinearEasing, | ||
duration: md::easing::duration::SHORT2, | ||
}); | ||
let w = FatObj::new(w); | ||
@ $w { | ||
clamp: BoxClamp::fixed_height(TRACK_HEIGHT), | ||
} | ||
} | ||
.into_widget() | ||
}); | ||
|
||
classes.insert( | ||
SLIDER_CONTAINER, | ||
style_class!( | ||
clamp: BoxClamp::fixed_height(INDICATOR_HEIGHT) | ||
), | ||
); | ||
classes.insert(SLIDER_ACTIVE_TRACK, |w| { | ||
fn_widget! { | ||
let w = FatObj::new(w); | ||
@ $w { | ||
class: BASE_SLIDER_TRACK, | ||
background: Palette::of(BuildCtx::get()).primary(), | ||
border_radius: Radius::new(LARGE_RADIUS, SMALL_RADIUS, LARGE_RADIUS, SMALL_RADIUS), | ||
} | ||
} | ||
.into_widget() | ||
}); | ||
|
||
classes.insert(SLIDER_INACTIVE_TRACK, |w| { | ||
fn_widget! { | ||
let w = FatObj::new(w); | ||
@ $w { | ||
class: BASE_SLIDER_TRACK, | ||
background: Palette::of(BuildCtx::get()).secondary_container(), | ||
border_radius: Radius::new(SMALL_RADIUS, LARGE_RADIUS, SMALL_RADIUS, LARGE_RADIUS), | ||
} | ||
} | ||
.into_widget() | ||
}); | ||
|
||
classes.insert(SLIDER_INDICATOR, |w| { | ||
fn_widget! { | ||
let w = FatObj::new(w); | ||
@ Cursor { | ||
cursor: CursorIcon::Pointer, | ||
@ $w { | ||
v_align: VAlign::Center, | ||
background: Palette::of(BuildCtx::get()).primary(), | ||
margin: EdgeInsets::horizontal(6.), | ||
clamp: BoxClamp::fixed_size(Size::new(TRACK_WIDTH, INDICATOR_HEIGHT)), | ||
} | ||
} | ||
} | ||
.into_widget() | ||
}); | ||
|
||
classes.insert(RANGE_SLIDER_INACTIVE_TRACK_LEFT, |w| { | ||
fn_widget! { | ||
let w = FatObj::new(w); | ||
@ $w { | ||
class: BASE_SLIDER_TRACK, | ||
border_radius: Radius::new(LARGE_RADIUS, SMALL_RADIUS, LARGE_RADIUS, SMALL_RADIUS), | ||
background: Palette::of(BuildCtx::get()).secondary_container(), | ||
} | ||
} | ||
.into_widget() | ||
}); | ||
|
||
classes.insert(RANGE_SLIDER_INACTIVE_TRACK_RIGHT, |w| { | ||
fn_widget! { | ||
let w = FatObj::new(w); | ||
@ $w { | ||
class: BASE_SLIDER_TRACK, | ||
border_radius: Radius::new(SMALL_RADIUS, LARGE_RADIUS, SMALL_RADIUS, LARGE_RADIUS,), | ||
background: Palette::of(BuildCtx::get()).secondary_container(), | ||
} | ||
} | ||
.into_widget() | ||
}); | ||
|
||
classes.insert(RANGE_SLIDER_ACTIVE_TRACK, |w| { | ||
fn_widget! { | ||
let w = FatObj::new(w); | ||
@ $w { | ||
class: BASE_SLIDER_TRACK, | ||
border_radius: Radius::all(SMALL_RADIUS), | ||
background: Palette::of(BuildCtx::get()).primary(), | ||
} | ||
} | ||
.into_widget() | ||
}); | ||
|
||
classes.insert(STOP_INDICATOR_ACTIVE, stop_indicator_class! { | ||
background: Palette::of(BuildCtx::get()).on_primary() | ||
}); | ||
|
||
classes.insert(STOP_INDICATOR_INACTIVE, stop_indicator_class! { | ||
background: Palette::of(BuildCtx::get()).on_secondary_container() | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.