improv(segmented-button): Express vertical/horizontal variants as a state machine

It's difficult to make iterative developments when there's two
nearly-identical types that need to be kept synchronized to any change.
Rust gives us traits so we should use them instead of duplicating code.

This made it easier to make styling and layout improvements to both
instances of the segmented button.
This commit is contained in:
Michael Aaron Murphy 2023-01-04 05:37:20 +01:00
parent b704eea531
commit 357de5e9be
No known key found for this signature in database
GPG key ID: B2732D4240C9212C
9 changed files with 633 additions and 726 deletions

View file

@ -48,15 +48,10 @@ mod horizontal;
mod state;
mod style;
mod vertical;
mod widget;
pub use self::horizontal::{horizontal_segmented_button, HorizontalSegmentedButton};
pub use self::horizontal::{horizontal_segmented_button, Horizontal, HorizontalSegmentedButton};
pub use self::state::{ButtonContent, Key, SecondaryState, SharedWidgetState, State};
pub use self::style::{Appearance, ButtonAppearance, StyleSheet};
pub use self::vertical::{vertical_segmented_button, VerticalSegmentedButton};
/// State that is maintained by each individual widget.
#[derive(Default)]
struct UniqueWidgetState {
/// The ID of the button that is being hovered. Defaults to null.
hovered: Key,
}
pub use self::style::{Appearance, ButtonAppearance, ButtonStatusAppearance, StyleSheet};
pub use self::vertical::{vertical_segmented_button, Vertical, VerticalSegmentedButton};
pub use self::widget::{SegmentedButton, SegmentedVariant};