diff --git a/src/ui/elements/ui_element.cpp b/src/ui/elements/ui_element.cpp index 3bc0a0f..8a8f470 100644 --- a/src/ui/elements/ui_element.cpp +++ b/src/ui/elements/ui_element.cpp @@ -48,21 +48,11 @@ void Element::add_child(Element *child) { } } -void Element::set_property(Rml::PropertyId property_id, const Rml::Property &property, Animation animation) { +void Element::set_property(Rml::PropertyId property_id, const Rml::Property &property) { assert(base != nullptr); - if (animation.type == AnimationType::None || animation.type == AnimationType::Set) { - base->SetProperty(property_id, property); - - if (animation.type == AnimationType::None) { - // Only non-animated properties should be stored as part of the style. - Style::set_property(property_id, property, animation); - } - } - else { - const Rml::String property_name = Rml::StyleSheetSpecification::GetPropertyName(property_id); - base->Animate(property_name, property, animation.duration); - } + base->SetProperty(property_id, property); + Style::set_property(property_id, property); } void Element::register_event_listeners(uint32_t events_enabled) { diff --git a/src/ui/elements/ui_element.h b/src/ui/elements/ui_element.h index 2a57b2c..506f850 100644 --- a/src/ui/elements/ui_element.h +++ b/src/ui/elements/ui_element.h @@ -32,7 +32,7 @@ private: void propagate_disabled(bool disabled); // Style overrides. - virtual void set_property(Rml::PropertyId property_id, const Rml::Property &property, Animation animation) override; + virtual void set_property(Rml::PropertyId property_id, const Rml::Property &property) override; // Rml::EventListener overrides. void ProcessEvent(Rml::Event &event) override final; diff --git a/src/ui/elements/ui_style.cpp b/src/ui/elements/ui_style.cpp index fb30903..b2db6b4 100644 --- a/src/ui/elements/ui_style.cpp +++ b/src/ui/elements/ui_style.cpp @@ -169,7 +169,7 @@ namespace recompui { } } - void Style::set_property(Rml::PropertyId property_id, const Rml::Property &property, Animation) { + void Style::set_property(Rml::PropertyId property_id, const Rml::Property &property) { property_map[property_id] = property; } @@ -184,10 +184,10 @@ namespace recompui { void Style::set_position(Position position) { switch (position) { case Position::Absolute: - set_property(Rml::PropertyId::Position, Rml::Style::Position::Absolute, Animation()); + set_property(Rml::PropertyId::Position, Rml::Style::Position::Absolute); break; case Position::Relative: - set_property(Rml::PropertyId::Position, Rml::Style::Position::Relative, Animation()); + set_property(Rml::PropertyId::Position, Rml::Style::Position::Relative); break; default: assert(false && "Unknown position."); @@ -195,184 +195,184 @@ namespace recompui { } } - void Style::set_left(float left, Unit unit, Animation animation) { - set_property(Rml::PropertyId::Left, Rml::Property(left, to_rml(unit)), animation); + void Style::set_left(float left, Unit unit) { + set_property(Rml::PropertyId::Left, Rml::Property(left, to_rml(unit))); } - void Style::set_top(float top, Unit unit, Animation animation) { - set_property(Rml::PropertyId::Top, Rml::Property(top, to_rml(unit)), animation); + void Style::set_top(float top, Unit unit) { + set_property(Rml::PropertyId::Top, Rml::Property(top, to_rml(unit))); } - void Style::set_right(float right, Unit unit, Animation animation) { - set_property(Rml::PropertyId::Right, Rml::Property(right, to_rml(unit)), animation); + void Style::set_right(float right, Unit unit) { + set_property(Rml::PropertyId::Right, Rml::Property(right, to_rml(unit))); } - void Style::set_bottom(float bottom, Unit unit, Animation animation) { - set_property(Rml::PropertyId::Bottom, Rml::Property(bottom, to_rml(unit)), animation); + void Style::set_bottom(float bottom, Unit unit) { + set_property(Rml::PropertyId::Bottom, Rml::Property(bottom, to_rml(unit))); } - void Style::set_width(float width, Unit unit, Animation animation) { - set_property(Rml::PropertyId::Width, Rml::Property(width, to_rml(unit)), animation); + void Style::set_width(float width, Unit unit) { + set_property(Rml::PropertyId::Width, Rml::Property(width, to_rml(unit))); } void Style::set_width_auto() { - set_property(Rml::PropertyId::Width, Rml::Property(Rml::Style::FlexBasis::Type::Auto, Rml::Unit::KEYWORD), Animation()); + set_property(Rml::PropertyId::Width, Rml::Property(Rml::Style::FlexBasis::Type::Auto, Rml::Unit::KEYWORD)); } - void Style::set_height(float height, Unit unit, Animation animation) { - set_property(Rml::PropertyId::Height, Rml::Property(height, to_rml(unit)), animation); + void Style::set_height(float height, Unit unit) { + set_property(Rml::PropertyId::Height, Rml::Property(height, to_rml(unit))); } void Style::set_height_auto() { - set_property(Rml::PropertyId::Height, Rml::Property(Rml::Style::FlexBasis::Type::Auto, Rml::Unit::KEYWORD), Animation()); + set_property(Rml::PropertyId::Height, Rml::Property(Rml::Style::FlexBasis::Type::Auto, Rml::Unit::KEYWORD)); } - void Style::set_min_width(float width, Unit unit, Animation animation) { - set_property(Rml::PropertyId::MinWidth, Rml::Property(width, to_rml(unit)), animation); + void Style::set_min_width(float width, Unit unit) { + set_property(Rml::PropertyId::MinWidth, Rml::Property(width, to_rml(unit))); } - void Style::set_min_height(float height, Unit unit, Animation animation) { - set_property(Rml::PropertyId::MinHeight, Rml::Property(height, to_rml(unit)), animation); + void Style::set_min_height(float height, Unit unit) { + set_property(Rml::PropertyId::MinHeight, Rml::Property(height, to_rml(unit))); } - void Style::set_max_width(float width, Unit unit, Animation animation) { - set_property(Rml::PropertyId::MaxWidth, Rml::Property(width, to_rml(unit)), animation); + void Style::set_max_width(float width, Unit unit) { + set_property(Rml::PropertyId::MaxWidth, Rml::Property(width, to_rml(unit))); } - void Style::set_max_height(float height, Unit unit, Animation animation) { - set_property(Rml::PropertyId::MaxHeight, Rml::Property(height, to_rml(unit)), animation); + void Style::set_max_height(float height, Unit unit) { + set_property(Rml::PropertyId::MaxHeight, Rml::Property(height, to_rml(unit))); } - void Style::set_padding(float padding, Unit unit, Animation animation) { - set_property(Rml::PropertyId::PaddingLeft, Rml::Property(padding, to_rml(unit)), animation); - set_property(Rml::PropertyId::PaddingTop, Rml::Property(padding, to_rml(unit)), animation); - set_property(Rml::PropertyId::PaddingRight, Rml::Property(padding, to_rml(unit)), animation); - set_property(Rml::PropertyId::PaddingBottom, Rml::Property(padding, to_rml(unit)), animation); + void Style::set_padding(float padding, Unit unit) { + set_property(Rml::PropertyId::PaddingLeft, Rml::Property(padding, to_rml(unit))); + set_property(Rml::PropertyId::PaddingTop, Rml::Property(padding, to_rml(unit))); + set_property(Rml::PropertyId::PaddingRight, Rml::Property(padding, to_rml(unit))); + set_property(Rml::PropertyId::PaddingBottom, Rml::Property(padding, to_rml(unit))); } - void Style::set_padding_left(float padding, Unit unit, Animation animation) { - set_property(Rml::PropertyId::PaddingLeft, Rml::Property(padding, to_rml(unit)), animation); + void Style::set_padding_left(float padding, Unit unit) { + set_property(Rml::PropertyId::PaddingLeft, Rml::Property(padding, to_rml(unit))); } - void Style::set_padding_top(float padding, Unit unit, Animation animation) { - set_property(Rml::PropertyId::PaddingTop, Rml::Property(padding, to_rml(unit)), animation); + void Style::set_padding_top(float padding, Unit unit) { + set_property(Rml::PropertyId::PaddingTop, Rml::Property(padding, to_rml(unit))); } - void Style::set_padding_right(float padding, Unit unit, Animation animation) { - set_property(Rml::PropertyId::PaddingRight, Rml::Property(padding, to_rml(unit)), animation); + void Style::set_padding_right(float padding, Unit unit) { + set_property(Rml::PropertyId::PaddingRight, Rml::Property(padding, to_rml(unit))); } - void Style::set_padding_bottom(float padding, Unit unit, Animation animation) { - set_property(Rml::PropertyId::PaddingBottom, Rml::Property(padding, to_rml(unit)), animation); + void Style::set_padding_bottom(float padding, Unit unit) { + set_property(Rml::PropertyId::PaddingBottom, Rml::Property(padding, to_rml(unit))); } - void Style::set_margin(float margin, Unit unit, Animation animation) { - set_property(Rml::PropertyId::MarginLeft, Rml::Property(margin, to_rml(unit)), animation); - set_property(Rml::PropertyId::MarginTop, Rml::Property(margin, to_rml(unit)), animation); - set_property(Rml::PropertyId::MarginRight, Rml::Property(margin, to_rml(unit)), animation); - set_property(Rml::PropertyId::MarginBottom, Rml::Property(margin, to_rml(unit)), animation); + void Style::set_margin(float margin, Unit unit) { + set_property(Rml::PropertyId::MarginLeft, Rml::Property(margin, to_rml(unit))); + set_property(Rml::PropertyId::MarginTop, Rml::Property(margin, to_rml(unit))); + set_property(Rml::PropertyId::MarginRight, Rml::Property(margin, to_rml(unit))); + set_property(Rml::PropertyId::MarginBottom, Rml::Property(margin, to_rml(unit))); } - void Style::set_margin_left(float margin, Unit unit, Animation animation) { - set_property(Rml::PropertyId::MarginLeft, Rml::Property(margin, to_rml(unit)), animation); + void Style::set_margin_left(float margin, Unit unit) { + set_property(Rml::PropertyId::MarginLeft, Rml::Property(margin, to_rml(unit))); } - void Style::set_margin_top(float margin, Unit unit, Animation animation) { - set_property(Rml::PropertyId::MarginTop, Rml::Property(margin, to_rml(unit)), animation); + void Style::set_margin_top(float margin, Unit unit) { + set_property(Rml::PropertyId::MarginTop, Rml::Property(margin, to_rml(unit))); } - void Style::set_margin_right(float margin, Unit unit, Animation animation) { - set_property(Rml::PropertyId::MarginRight, Rml::Property(margin, to_rml(unit)), animation); + void Style::set_margin_right(float margin, Unit unit) { + set_property(Rml::PropertyId::MarginRight, Rml::Property(margin, to_rml(unit))); } - void Style::set_margin_bottom(float margin, Unit unit, Animation animation) { - set_property(Rml::PropertyId::MarginBottom, Rml::Property(margin, to_rml(unit)), animation); + void Style::set_margin_bottom(float margin, Unit unit) { + set_property(Rml::PropertyId::MarginBottom, Rml::Property(margin, to_rml(unit))); } - void Style::set_border_width(float width, Unit unit, Animation animation) { + void Style::set_border_width(float width, Unit unit) { Rml::Property property(width, to_rml(unit)); - set_property(Rml::PropertyId::BorderTopWidth, property, animation); - set_property(Rml::PropertyId::BorderBottomWidth, property, animation); - set_property(Rml::PropertyId::BorderLeftWidth, property, animation); - set_property(Rml::PropertyId::BorderRightWidth, property, animation); + set_property(Rml::PropertyId::BorderTopWidth, property); + set_property(Rml::PropertyId::BorderBottomWidth, property); + set_property(Rml::PropertyId::BorderLeftWidth, property); + set_property(Rml::PropertyId::BorderRightWidth, property); } - void Style::set_border_left_width(float width, Unit unit, Animation animation) { - set_property(Rml::PropertyId::BorderLeftWidth, Rml::Property(width, to_rml(unit)), animation); + void Style::set_border_left_width(float width, Unit unit) { + set_property(Rml::PropertyId::BorderLeftWidth, Rml::Property(width, to_rml(unit))); } - void Style::set_border_top_width(float width, Unit unit, Animation animation) { - set_property(Rml::PropertyId::BorderTopWidth, Rml::Property(width, to_rml(unit)), animation); + void Style::set_border_top_width(float width, Unit unit) { + set_property(Rml::PropertyId::BorderTopWidth, Rml::Property(width, to_rml(unit))); } - void Style::set_border_right_width(float width, Unit unit, Animation animation) { - set_property(Rml::PropertyId::BorderRightWidth, Rml::Property(width, to_rml(unit)), animation); + void Style::set_border_right_width(float width, Unit unit) { + set_property(Rml::PropertyId::BorderRightWidth, Rml::Property(width, to_rml(unit))); } - void Style::set_border_bottom_width(float width, Unit unit, Animation animation) { - set_property(Rml::PropertyId::BorderBottomWidth, Rml::Property(width, to_rml(unit)), animation); + void Style::set_border_bottom_width(float width, Unit unit) { + set_property(Rml::PropertyId::BorderBottomWidth, Rml::Property(width, to_rml(unit))); } - void Style::set_border_radius(float radius, Unit unit, Animation animation) { + void Style::set_border_radius(float radius, Unit unit) { Rml::Property property(radius, to_rml(unit)); - set_property(Rml::PropertyId::BorderTopLeftRadius, property, animation); - set_property(Rml::PropertyId::BorderTopRightRadius, property, animation); - set_property(Rml::PropertyId::BorderBottomLeftRadius, property, animation); - set_property(Rml::PropertyId::BorderBottomRightRadius, property, animation); + set_property(Rml::PropertyId::BorderTopLeftRadius, property); + set_property(Rml::PropertyId::BorderTopRightRadius, property); + set_property(Rml::PropertyId::BorderBottomLeftRadius, property); + set_property(Rml::PropertyId::BorderBottomRightRadius, property); } - void Style::set_border_top_left_radius(float radius, Unit unit, Animation animation) { - set_property(Rml::PropertyId::BorderTopLeftRadius, Rml::Property(radius, to_rml(unit)), animation); + void Style::set_border_top_left_radius(float radius, Unit unit) { + set_property(Rml::PropertyId::BorderTopLeftRadius, Rml::Property(radius, to_rml(unit))); } - void Style::set_border_top_right_radius(float radius, Unit unit, Animation animation) { - set_property(Rml::PropertyId::BorderTopRightRadius, Rml::Property(radius, to_rml(unit)), animation); + void Style::set_border_top_right_radius(float radius, Unit unit) { + set_property(Rml::PropertyId::BorderTopRightRadius, Rml::Property(radius, to_rml(unit))); } - void Style::set_border_bottom_left_radius(float radius, Unit unit, Animation animation) { - set_property(Rml::PropertyId::BorderBottomLeftRadius, Rml::Property(radius, to_rml(unit)), animation); + void Style::set_border_bottom_left_radius(float radius, Unit unit) { + set_property(Rml::PropertyId::BorderBottomLeftRadius, Rml::Property(radius, to_rml(unit))); } - void Style::set_border_bottom_right_radius(float radius, Unit unit, Animation animation) { - set_property(Rml::PropertyId::BorderBottomRightRadius, Rml::Property(radius, to_rml(unit)), animation); + void Style::set_border_bottom_right_radius(float radius, Unit unit) { + set_property(Rml::PropertyId::BorderBottomRightRadius, Rml::Property(radius, to_rml(unit))); } - void Style::set_background_color(const Color &color, Animation animation) { + void Style::set_background_color(const Color &color) { Rml::Property property(Rml::Colourb(color.r, color.g, color.b, color.a), Rml::Unit::COLOUR); - set_property(Rml::PropertyId::BackgroundColor, property, animation); + set_property(Rml::PropertyId::BackgroundColor, property); } - void Style::set_border_color(const Color &color, Animation animation) { + void Style::set_border_color(const Color &color) { Rml::Property property(Rml::Colourb(color.r, color.g, color.b, color.a), Rml::Unit::COLOUR); - set_property(Rml::PropertyId::BorderTopColor, property, animation); - set_property(Rml::PropertyId::BorderBottomColor, property, animation); - set_property(Rml::PropertyId::BorderLeftColor, property, animation); - set_property(Rml::PropertyId::BorderRightColor, property, animation); + set_property(Rml::PropertyId::BorderTopColor, property); + set_property(Rml::PropertyId::BorderBottomColor, property); + set_property(Rml::PropertyId::BorderLeftColor, property); + set_property(Rml::PropertyId::BorderRightColor, property); } - void Style::set_border_left_color(const Color &color, Animation animation) { + void Style::set_border_left_color(const Color &color) { Rml::Property property(Rml::Colourb(color.r, color.g, color.b, color.a), Rml::Unit::COLOUR); - set_property(Rml::PropertyId::BorderLeftColor, property, animation); + set_property(Rml::PropertyId::BorderLeftColor, property); } - void Style::set_border_top_color(const Color &color, Animation animation) { + void Style::set_border_top_color(const Color &color) { Rml::Property property(Rml::Colourb(color.r, color.g, color.b, color.a), Rml::Unit::COLOUR); - set_property(Rml::PropertyId::BorderTopColor, property, animation); + set_property(Rml::PropertyId::BorderTopColor, property); } - void Style::set_border_right_color(const Color &color, Animation animation) { + void Style::set_border_right_color(const Color &color) { Rml::Property property(Rml::Colourb(color.r, color.g, color.b, color.a), Rml::Unit::COLOUR); - set_property(Rml::PropertyId::BorderRightColor, property, animation); + set_property(Rml::PropertyId::BorderRightColor, property); } - void Style::set_border_bottom_color(const Color &color, Animation animation) { + void Style::set_border_bottom_color(const Color &color) { Rml::Property property(Rml::Colourb(color.r, color.g, color.b, color.a), Rml::Unit::COLOUR); - set_property(Rml::PropertyId::BorderBottomColor, property, animation); + set_property(Rml::PropertyId::BorderBottomColor, property); } - void Style::set_color(const Color &color, Animation animation) { + void Style::set_color(const Color &color) { Rml::Property property(Rml::Colourb(color.r, color.g, color.b, color.a), Rml::Unit::COLOUR); - set_property(Rml::PropertyId::Color, property, animation); + set_property(Rml::PropertyId::Color, property); } void Style::set_cursor(Cursor cursor) { @@ -381,7 +381,7 @@ namespace recompui { assert(false && "Unimplemented."); break; case Cursor::Pointer: - set_property(Rml::PropertyId::Cursor, Rml::Property("pointer", Rml::Unit::STRING), Animation()); + set_property(Rml::PropertyId::Cursor, Rml::Property("pointer", Rml::Unit::STRING)); break; default: assert(false && "Unknown cursor."); @@ -389,53 +389,53 @@ namespace recompui { } } - void Style::set_opacity(float opacity, Animation animation) { - set_property(Rml::PropertyId::Opacity, Rml::Property(opacity, Rml::Unit::NUMBER), animation); + void Style::set_opacity(float opacity) { + set_property(Rml::PropertyId::Opacity, Rml::Property(opacity, Rml::Unit::NUMBER)); } void Style::set_display(Display display) { - set_property(Rml::PropertyId::Display, to_rml(display), Animation()); + set_property(Rml::PropertyId::Display, to_rml(display)); } void Style::set_justify_content(JustifyContent justify_content) { - set_property(Rml::PropertyId::JustifyContent, to_rml(justify_content), Animation()); + set_property(Rml::PropertyId::JustifyContent, to_rml(justify_content)); } - void Style::set_flex_grow(float grow, Animation animation) { - set_property(Rml::PropertyId::FlexGrow, Rml::Property(grow, Rml::Unit::NUMBER), animation); + void Style::set_flex_grow(float grow) { + set_property(Rml::PropertyId::FlexGrow, Rml::Property(grow, Rml::Unit::NUMBER)); } - void Style::set_flex_shrink(float shrink, Animation animation) { - set_property(Rml::PropertyId::FlexShrink, Rml::Property(shrink, Rml::Unit::NUMBER), animation); + void Style::set_flex_shrink(float shrink) { + set_property(Rml::PropertyId::FlexShrink, Rml::Property(shrink, Rml::Unit::NUMBER)); } void Style::set_flex_basis_auto() { - set_property(Rml::PropertyId::FlexBasis, Rml::Property(Rml::Style::FlexBasis::Type::Auto, Rml::Unit::KEYWORD), Animation()); + set_property(Rml::PropertyId::FlexBasis, Rml::Property(Rml::Style::FlexBasis::Type::Auto, Rml::Unit::KEYWORD)); } - void Style::set_flex_basis(float basis, Unit unit, Animation animation) { - set_property(Rml::PropertyId::FlexBasis, Rml::Property(basis, to_rml(unit)), animation); + void Style::set_flex_basis(float basis, Unit unit) { + set_property(Rml::PropertyId::FlexBasis, Rml::Property(basis, to_rml(unit))); } - void Style::set_flex(float grow, float shrink, Animation animation) { - set_flex_grow(grow, animation); - set_flex_shrink(shrink, animation); + void Style::set_flex(float grow, float shrink) { + set_flex_grow(grow); + set_flex_shrink(shrink); set_flex_basis_auto(); } - void Style::set_flex(float grow, float shrink, float basis, Unit basis_unit, Animation animation) { - set_flex_grow(grow, animation); - set_flex_shrink(shrink, animation); - set_flex_basis(basis, basis_unit, animation); + void Style::set_flex(float grow, float shrink, float basis, Unit basis_unit) { + set_flex_grow(grow); + set_flex_shrink(shrink); + set_flex_basis(basis, basis_unit); } void Style::set_flex_direction(FlexDirection flex_direction) { switch (flex_direction) { case FlexDirection::Row: - set_property(Rml::PropertyId::FlexDirection, Rml::Style::FlexDirection::Row, Animation()); + set_property(Rml::PropertyId::FlexDirection, Rml::Style::FlexDirection::Row); break; case FlexDirection::Column: - set_property(Rml::PropertyId::FlexDirection, Rml::Style::FlexDirection::Column, Animation()); + set_property(Rml::PropertyId::FlexDirection, Rml::Style::FlexDirection::Column); break; default: assert(false && "Unknown flex direction."); @@ -444,41 +444,41 @@ namespace recompui { } void Style::set_align_items(AlignItems align_items) { - set_property(Rml::PropertyId::AlignItems, to_rml(align_items), Animation()); + set_property(Rml::PropertyId::AlignItems, to_rml(align_items)); } void Style::set_overflow(Overflow overflow) { - set_property(Rml::PropertyId::OverflowX, to_rml(overflow), Animation()); - set_property(Rml::PropertyId::OverflowY, to_rml(overflow), Animation()); + set_property(Rml::PropertyId::OverflowX, to_rml(overflow)); + set_property(Rml::PropertyId::OverflowY, to_rml(overflow)); } void Style::set_overflow_x(Overflow overflow) { - set_property(Rml::PropertyId::OverflowX, to_rml(overflow), Animation()); + set_property(Rml::PropertyId::OverflowX, to_rml(overflow)); } void Style::set_overflow_y(Overflow overflow) { - set_property(Rml::PropertyId::OverflowY, to_rml(overflow), Animation()); + set_property(Rml::PropertyId::OverflowY, to_rml(overflow)); } - void Style::set_font_size(float size, Unit unit, Animation animation) { - set_property(Rml::PropertyId::FontSize, Rml::Property(size, to_rml(unit)), animation); + void Style::set_font_size(float size, Unit unit) { + set_property(Rml::PropertyId::FontSize, Rml::Property(size, to_rml(unit))); } - void Style::set_letter_spacing(float spacing, Unit unit, Animation animation) { - set_property(Rml::PropertyId::LetterSpacing, Rml::Property(spacing, to_rml(unit)), animation); + void Style::set_letter_spacing(float spacing, Unit unit) { + set_property(Rml::PropertyId::LetterSpacing, Rml::Property(spacing, to_rml(unit))); } - void Style::set_line_height(float height, Unit unit, Animation animation) { - set_property(Rml::PropertyId::LineHeight, Rml::Property(height, to_rml(unit)), animation); + void Style::set_line_height(float height, Unit unit) { + set_property(Rml::PropertyId::LineHeight, Rml::Property(height, to_rml(unit))); } void Style::set_font_style(FontStyle style) { switch (style) { case FontStyle::Normal: - set_property(Rml::PropertyId::FontStyle, Rml::Style::FontStyle::Normal, Animation()); + set_property(Rml::PropertyId::FontStyle, Rml::Style::FontStyle::Normal); break; case FontStyle::Italic: - set_property(Rml::PropertyId::FontStyle, Rml::Style::FontStyle::Italic, Animation()); + set_property(Rml::PropertyId::FontStyle, Rml::Style::FontStyle::Italic); break; default: assert(false && "Unknown font style."); @@ -486,41 +486,41 @@ namespace recompui { } } - void Style::set_font_weight(uint32_t weight, Animation animation) { - set_property(Rml::PropertyId::FontWeight, Rml::Style::FontWeight(weight), animation); + void Style::set_font_weight(uint32_t weight) { + set_property(Rml::PropertyId::FontWeight, Rml::Style::FontWeight(weight)); } void Style::set_text_align(TextAlign text_align) { - set_property(Rml::PropertyId::TextAlign, to_rml(text_align), Animation()); + set_property(Rml::PropertyId::TextAlign, to_rml(text_align)); } void Style::set_text_transform(TextTransform text_transform) { - set_property(Rml::PropertyId::TextTransform, to_rml(text_transform), Animation()); + set_property(Rml::PropertyId::TextTransform, to_rml(text_transform)); } - void Style::set_gap(float size, Unit unit, Animation animation) { - set_row_gap(size, unit, animation); - set_column_gap(size, unit, animation); + void Style::set_gap(float size, Unit unit) { + set_row_gap(size, unit); + set_column_gap(size, unit); } - void Style::set_row_gap(float size, Unit unit, Animation animation) { - set_property(Rml::PropertyId::RowGap, Rml::Property(size, to_rml(unit)), animation); + void Style::set_row_gap(float size, Unit unit) { + set_property(Rml::PropertyId::RowGap, Rml::Property(size, to_rml(unit))); } - void Style::set_column_gap(float size, Unit unit, Animation animation) { - set_property(Rml::PropertyId::ColumnGap, Rml::Property(size, to_rml(unit)), animation); + void Style::set_column_gap(float size, Unit unit) { + set_property(Rml::PropertyId::ColumnGap, Rml::Property(size, to_rml(unit))); } void Style::set_drag(Drag drag) { - set_property(Rml::PropertyId::Drag, to_rml(drag), Animation()); + set_property(Rml::PropertyId::Drag, to_rml(drag)); } void Style::set_tab_index(TabIndex tab_index) { - set_property(Rml::PropertyId::TabIndex, to_rml(tab_index), Animation()); + set_property(Rml::PropertyId::TabIndex, to_rml(tab_index)); } void Style::set_font_family(std::string_view family) { - set_property(Rml::PropertyId::FontFamily, Rml::Property(Rml::String{ family }, Rml::Unit::UNKNOWN), Animation()); + set_property(Rml::PropertyId::FontFamily, Rml::Property(Rml::String{ family }, Rml::Unit::UNKNOWN)); } } // namespace recompui \ No newline at end of file diff --git a/src/ui/elements/ui_style.h b/src/ui/elements/ui_style.h index 2697280..2d3654a 100644 --- a/src/ui/elements/ui_style.h +++ b/src/ui/elements/ui_style.h @@ -15,76 +15,76 @@ namespace recompui { private: std::map property_map; protected: - virtual void set_property(Rml::PropertyId property_id, const Rml::Property &property, Animation); + virtual void set_property(Rml::PropertyId property_id, const Rml::Property &property); ResourceId resource_id = ResourceId::null(); public: Style(); virtual ~Style(); void set_position(Position position); - void set_left(float left, Unit unit = Unit::Dp, Animation animation = Animation()); - void set_top(float top, Unit unit = Unit::Dp, Animation animation = Animation()); - void set_right(float right, Unit unit = Unit::Dp, Animation animation = Animation()); - void set_bottom(float bottom, Unit unit = Unit::Dp, Animation animation = Animation()); - void set_width(float width, Unit unit = Unit::Dp, Animation animation = Animation()); + void set_left(float left, Unit unit = Unit::Dp); + void set_top(float top, Unit unit = Unit::Dp); + void set_right(float right, Unit unit = Unit::Dp); + void set_bottom(float bottom, Unit unit = Unit::Dp); + void set_width(float width, Unit unit = Unit::Dp); void set_width_auto(); - void set_height(float height, Unit unit = Unit::Dp, Animation animation = Animation()); + void set_height(float height, Unit unit = Unit::Dp); void set_height_auto(); - void set_min_width(float width, Unit unit = Unit::Dp, Animation animation = Animation()); - void set_min_height(float height, Unit unit = Unit::Dp, Animation animation = Animation()); - void set_max_width(float width, Unit unit = Unit::Dp, Animation animation = Animation()); - void set_max_height(float height, Unit unit = Unit::Dp, Animation animation = Animation()); - void set_padding(float padding, Unit unit = Unit::Dp, Animation animation = Animation()); - void set_padding_left(float padding, Unit unit = Unit::Dp, Animation animation = Animation()); - void set_padding_top(float padding, Unit unit = Unit::Dp, Animation animation = Animation()); - void set_padding_right(float padding, Unit unit = Unit::Dp, Animation animation = Animation()); - void set_padding_bottom(float padding, Unit unit = Unit::Dp, Animation animation = Animation()); - void set_margin(float margin, Unit unit = Unit::Dp, Animation animation = Animation()); - void set_margin_left(float margin, Unit unit = Unit::Dp, Animation animation = Animation()); - void set_margin_top(float margin, Unit unit = Unit::Dp, Animation animation = Animation()); - void set_margin_right(float margin, Unit unit = Unit::Dp, Animation animation = Animation()); - void set_margin_bottom(float margin, Unit unit = Unit::Dp, Animation animation = Animation()); - void set_border_width(float width, Unit unit = Unit::Dp, Animation animation = Animation()); - void set_border_left_width(float width, Unit unit = Unit::Dp, Animation animation = Animation()); - void set_border_top_width(float width, Unit unit = Unit::Dp, Animation animation = Animation()); - void set_border_right_width(float width, Unit unit = Unit::Dp, Animation animation = Animation()); - void set_border_bottom_width(float width, Unit unit = Unit::Dp, Animation animation = Animation()); - void set_border_radius(float radius, Unit unit = Unit::Dp, Animation animation = Animation()); - void set_border_top_left_radius(float radius, Unit unit = Unit::Dp, Animation animation = Animation()); - void set_border_top_right_radius(float radius, Unit unit = Unit::Dp, Animation animation = Animation()); - void set_border_bottom_left_radius(float radius, Unit unit = Unit::Dp, Animation animation = Animation()); - void set_border_bottom_right_radius(float radius, Unit unit = Unit::Dp, Animation animation = Animation()); - void set_background_color(const Color &color, Animation animation = Animation()); - void set_border_color(const Color &color, Animation animation = Animation()); - void set_border_left_color(const Color &color, Animation animation = Animation()); - void set_border_top_color(const Color &color, Animation animation = Animation()); - void set_border_right_color(const Color &color, Animation animation = Animation()); - void set_border_bottom_color(const Color &color, Animation animation = Animation()); - void set_color(const Color &color, Animation animation = Animation()); + void set_min_width(float width, Unit unit = Unit::Dp); + void set_min_height(float height, Unit unit = Unit::Dp); + void set_max_width(float width, Unit unit = Unit::Dp); + void set_max_height(float height, Unit unit = Unit::Dp); + void set_padding(float padding, Unit unit = Unit::Dp); + void set_padding_left(float padding, Unit unit = Unit::Dp); + void set_padding_top(float padding, Unit unit = Unit::Dp); + void set_padding_right(float padding, Unit unit = Unit::Dp); + void set_padding_bottom(float padding, Unit unit = Unit::Dp); + void set_margin(float margin, Unit unit = Unit::Dp); + void set_margin_left(float margin, Unit unit = Unit::Dp); + void set_margin_top(float margin, Unit unit = Unit::Dp); + void set_margin_right(float margin, Unit unit = Unit::Dp); + void set_margin_bottom(float margin, Unit unit = Unit::Dp); + void set_border_width(float width, Unit unit = Unit::Dp); + void set_border_left_width(float width, Unit unit = Unit::Dp); + void set_border_top_width(float width, Unit unit = Unit::Dp); + void set_border_right_width(float width, Unit unit = Unit::Dp); + void set_border_bottom_width(float width, Unit unit = Unit::Dp); + void set_border_radius(float radius, Unit unit = Unit::Dp); + void set_border_top_left_radius(float radius, Unit unit = Unit::Dp); + void set_border_top_right_radius(float radius, Unit unit = Unit::Dp); + void set_border_bottom_left_radius(float radius, Unit unit = Unit::Dp); + void set_border_bottom_right_radius(float radius, Unit unit = Unit::Dp); + void set_background_color(const Color &color); + void set_border_color(const Color &color); + void set_border_left_color(const Color &color); + void set_border_top_color(const Color &color); + void set_border_right_color(const Color &color); + void set_border_bottom_color(const Color &color); + void set_color(const Color &color); void set_cursor(Cursor cursor); - void set_opacity(float opacity, Animation animation = Animation()); + void set_opacity(float opacity); void set_display(Display display); void set_justify_content(JustifyContent justify_content); - void set_flex_grow(float grow, Animation animation = Animation()); - void set_flex_shrink(float shrink, Animation animation = Animation()); + void set_flex_grow(float grow); + void set_flex_shrink(float shrink); void set_flex_basis_auto(); - void set_flex_basis(float basis, Unit unit = Unit::Percent, Animation animation = Animation()); - void set_flex(float grow, float shrink, Animation animation = Animation()); - void set_flex(float grow, float shrink, float basis, Unit basis_unit = Unit::Percent, Animation animation = Animation()); + void set_flex_basis(float basis, Unit unit = Unit::Percent); + void set_flex(float grow, float shrink); + void set_flex(float grow, float shrink, float basis, Unit basis_unit = Unit::Percent); void set_flex_direction(FlexDirection flex_direction); void set_align_items(AlignItems align_items); void set_overflow(Overflow overflow); void set_overflow_x(Overflow overflow); void set_overflow_y(Overflow overflow); - void set_font_size(float size, Unit unit = Unit::Dp, Animation animation = Animation()); - void set_letter_spacing(float spacing, Unit unit = Unit::Dp, Animation animation = Animation()); - void set_line_height(float height, Unit unit = Unit::Dp, Animation animation = Animation()); + void set_font_size(float size, Unit unit = Unit::Dp); + void set_letter_spacing(float spacing, Unit unit = Unit::Dp); + void set_line_height(float height, Unit unit = Unit::Dp); void set_font_style(FontStyle style); - void set_font_weight(uint32_t weight, Animation animation = Animation()); + void set_font_weight(uint32_t weight); void set_text_align(TextAlign text_align); void set_text_transform(TextTransform text_transform); - void set_gap(float size, Unit unit = Unit::Dp, Animation animation = Animation()); - void set_row_gap(float size, Unit unit = Unit::Dp, Animation animation = Animation()); - void set_column_gap(float size, Unit unit = Unit::Dp, Animation animation = Animation()); + void set_gap(float size, Unit unit = Unit::Dp); + void set_row_gap(float size, Unit unit = Unit::Dp); + void set_column_gap(float size, Unit unit = Unit::Dp); void set_drag(Drag drag); void set_tab_index(TabIndex focus); void set_font_family(std::string_view family); diff --git a/src/ui/elements/ui_toggle.cpp b/src/ui/elements/ui_toggle.cpp index 5711749..a58aea6 100644 --- a/src/ui/elements/ui_toggle.cpp +++ b/src/ui/elements/ui_toggle.cpp @@ -2,6 +2,8 @@ #include +#include + namespace recompui { Toggle::Toggle(Element *parent) : Element(parent, Events(EventType::Click, EventType::Hover, EventType::Enable), "button") { @@ -49,7 +51,15 @@ namespace recompui { if (this->checked != checked || setup) { this->checked = checked; - floater->set_left(floater_left_target(), Unit::Dp, animate ? Animation::tween(0.1f) : Animation::set()); + if (animate) { + last_time = ultramodern::time_since_start(); + queue_update(); + } + else { + floater_left = floater_left_target(); + } + + floater->set_left(floater_left, Unit::Dp); if (trigger_callbacks) { for (const auto &function : checked_callbacks) { @@ -87,10 +97,31 @@ namespace recompui { break; } case EventType::Update: { + std::chrono::high_resolution_clock::duration now = ultramodern::time_since_start(); + float delta_time = std::chrono::duration(now - last_time).count(); + last_time = now; + + constexpr float dp_speed = 740.0f; + const float target = floater_left_target(); + if (target < floater_left) { + floater_left += std::max(-dp_speed * delta_time, target - floater_left); + } + else { + floater_left += std::min(dp_speed * delta_time, target - floater_left); + } + + if (abs(target - floater_left) < 1e-4f) { + floater_left = target; + } + else { + queue_update(); + } + + floater->set_left(floater_left, Unit::Dp); + break; } default: - assert(false && "Unknown event type."); break; } } diff --git a/src/ui/elements/ui_toggle.h b/src/ui/elements/ui_toggle.h index 0f3eab5..257b42b 100644 --- a/src/ui/elements/ui_toggle.h +++ b/src/ui/elements/ui_toggle.h @@ -7,6 +7,8 @@ namespace recompui { class Toggle : public Element { protected: Element *floater; + float floater_left = 0.0f; + std::chrono::high_resolution_clock::duration last_time; std::list> checked_callbacks; Style checked_style; Style hover_style; diff --git a/src/ui/elements/ui_types.h b/src/ui/elements/ui_types.h index f9d3b11..47de3bf 100644 --- a/src/ui/elements/ui_types.h +++ b/src/ui/elements/ui_types.h @@ -229,23 +229,4 @@ namespace recompui { Auto }; - struct Animation { - AnimationType type = AnimationType::None; - float duration = 0.0f; - - static Animation set() { - Animation a; - a.type = AnimationType::Set; - a.duration = 0.0f; - return a; - } - - static Animation tween(float duration) { - Animation a; - a.type = AnimationType::Tween; - a.duration = duration; - return a; - } - }; - } // namespace recompui \ No newline at end of file diff --git a/src/ui/ui_api.cpp b/src/ui/ui_api.cpp index 736cd31..f99dc62 100644 --- a/src/ui/ui_api.cpp +++ b/src/ui/ui_api.cpp @@ -83,18 +83,6 @@ Style* arg_style(uint8_t* rdram, recomp_context* ctx) { return *resource; } -template -Animation arg_animation(uint8_t* rdram, recomp_context* ctx) { - PTR(Animation) anim_ptr = _arg(rdram, ctx); - - if (anim_ptr == NULLPTR) { - return Animation{}; - } - else { - return *TO_PTR(Animation, anim_ptr); - } -} - void return_resource(recomp_context* ctx, ResourceId resource) { _return(ctx, resource.slot_id); } @@ -172,18 +160,16 @@ extern "C" void recompui_set_width(uint8_t* rdram, recomp_context* ctx) { Style* resource = arg_style<0>(rdram, ctx); float width = _arg_float_a1(rdram, ctx); uint32_t unit = _arg<2, uint32_t>(rdram, ctx); - Animation animation = arg_animation<3>(rdram, ctx); - resource->set_width(width, static_cast(unit), animation); + resource->set_width(width, static_cast(unit)); } extern "C" void recompui_set_height(uint8_t* rdram, recomp_context* ctx) { Style* resource = arg_style<0>(rdram, ctx); float height = _arg_float_a1(rdram, ctx); uint32_t unit = _arg<2, uint32_t>(rdram, ctx); - Animation animation = arg_animation<3>(rdram, ctx); - resource->set_height(height, static_cast(unit), animation); + resource->set_height(height, static_cast(unit)); } extern "C" void recompui_set_display(uint8_t* rdram, recomp_context* ctx) { @@ -200,20 +186,18 @@ extern "C" void recompui_set_flex_direction(uint8_t* rdram, recomp_context* ctx) resource->set_flex_direction(static_cast(direction)); } -extern "C" void recompui_set_flex_grow(uint8_t* rdram, recomp_context* ctx) { // float grow, Animation animation = Animation() +extern "C" void recompui_set_flex_grow(uint8_t* rdram, recomp_context* ctx) { // float grow Style* resource = arg_style<0>(rdram, ctx); float grow = _arg_float_a1(rdram, ctx); - Animation animation = arg_animation<2>(rdram, ctx); - resource->set_flex_grow(grow, animation); + resource->set_flex_grow(grow); } -extern "C" void recompui_set_flex_shrink(uint8_t* rdram, recomp_context* ctx) { // float shrink, Animation animation = Animation() +extern "C" void recompui_set_flex_shrink(uint8_t* rdram, recomp_context* ctx) { // float shrink Style* resource = arg_style<0>(rdram, ctx); float shrink = _arg_float_a1(rdram, ctx); - Animation animation = arg_animation<2>(rdram, ctx); - resource->set_flex_shrink(shrink, animation); + resource->set_flex_shrink(shrink); } extern "C" void recompui_set_flex_basis_auto(uint8_t* rdram, recomp_context* ctx) { @@ -222,13 +206,12 @@ extern "C" void recompui_set_flex_basis_auto(uint8_t* rdram, recomp_context* ctx resource->set_flex_basis_auto(); } -extern "C" void recompui_set_flex_basis(uint8_t* rdram, recomp_context* ctx) { // float basis, Unit unit = Unit::Percent, Animation animation = Animation() +extern "C" void recompui_set_flex_basis(uint8_t* rdram, recomp_context* ctx) { // float basis, Unit unit = Unit::Percent Style* resource = arg_style<0>(rdram, ctx); float basis = _arg_float_a1(rdram, ctx); uint32_t unit = _arg<2, uint32_t>(rdram, ctx); - Animation animation = arg_animation<3>(rdram, ctx); - resource->set_flex_basis(basis, static_cast(unit), animation); + resource->set_flex_basis(basis, static_cast(unit)); } #define REGISTER_FUNC(name) recomp::overlays::register_base_export(#name, name)