Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add slider widget with horizontal and vertical support #853

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions masonry/src/core/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ pub enum Action {
TextEntered(String),
/// A checkbox was toggled.
CheckboxToggled(bool),
/// Slider value changed.
SliderValueChanged(f64),
/// Slider editing state changed.
SliderEditingChanged(bool),
// FIXME - This is a huge hack
/// Other.
Other(Box<dyn Any + Send>),
Expand All @@ -34,6 +38,8 @@ impl PartialEq for Action {
(Self::TextChanged(l0), Self::TextChanged(r0)) => l0 == r0,
(Self::TextEntered(l0), Self::TextEntered(r0)) => l0 == r0,
(Self::CheckboxToggled(l0), Self::CheckboxToggled(r0)) => l0 == r0,
(Self::SliderValueChanged(l0), Self::SliderValueChanged(r0)) => l0 == r0,
(Self::SliderEditingChanged(l0), Self::SliderEditingChanged(r0)) => l0 == r0,
// FIXME
// (Self::Other(val_l), Self::Other(val_r)) => false,
_ => false,
Expand All @@ -48,6 +54,13 @@ impl std::fmt::Debug for Action {
Self::TextChanged(text) => f.debug_tuple("TextChanged").field(text).finish(),
Self::TextEntered(text) => f.debug_tuple("TextEntered").field(text).finish(),
Self::CheckboxToggled(b) => f.debug_tuple("CheckboxChecked").field(b).finish(),
Self::SliderValueChanged(value) => {
f.debug_tuple("SliderValueChanged").field(value).finish()
}
Self::SliderEditingChanged(editing) => f
.debug_tuple("SliderEditingChanged")
.field(editing)
.finish(),
Self::Other(_) => write!(f, "Other(...)"),
}
}
Expand Down
14 changes: 14 additions & 0 deletions masonry/src/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,20 @@ pub const WIDGET_PADDING_VERTICAL: f64 = 10.0;
pub const WIDGET_PADDING_HORIZONTAL: f64 = 8.0;
pub const WIDGET_CONTROL_COMPONENT_PADDING: f64 = 4.0;

// Slider theme constants
pub const SLIDER_DEFAULT_WIDTH: f64 = 200.0;
pub const SLIDER_DEFAULT_HEIGHT: f64 = 40.0;
pub const SLIDER_BASE_TRACK_THICKNESS: f64 = 4.0;
pub const SLIDER_TRACK_PADDING: f64 = 5.0;
pub const SLIDER_THUMB_WIDTH: f64 = 12.0;
pub const SLIDER_THUMB_HEIGHT: f64 = 20.0;
pub const SLIDER_HOVER_GLOW_COLOR: Color = Color::from_rgba8(0xff, 0xff, 0xff, 0x32);
pub const SLIDER_THUMB_RADIUS: f64 = 5.0;
pub const SLIDER_TRACK_RADIUS: f64 = 2.0;
pub const SLIDER_HOVER_GLOW_BLUR_RADIUS: f64 = 5.0;
pub const SLIDER_HOVER_GLOW_SPREAD_RADIUS: f64 = 2.0;
pub const SLIDER_STEP: f64 = 1.0;

static DEBUG_COLOR: &[Color] = &[
Color::from_rgb8(230, 25, 75),
Color::from_rgb8(60, 180, 75),
Expand Down
2 changes: 2 additions & 0 deletions masonry/src/widgets/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ mod prose;
mod root_widget;
mod scroll_bar;
mod sized_box;
mod slider;
mod spinner;
mod split;
mod text_area;
Expand All @@ -42,6 +43,7 @@ pub use self::prose::Prose;
pub use self::root_widget::RootWidget;
pub use self::scroll_bar::ScrollBar;
pub use self::sized_box::{Padding, SizedBox};
pub use self::slider::Slider;
pub use self::spinner::Spinner;
pub use self::split::Split;
pub use self::text_area::TextArea;
Expand Down
Loading
Loading