Skip to content

Add Transitions with :indefinite examples - #31

Merged
vlaaad merged 2 commits into
cljfx:masterfrom
frenchy64:transitions
Jul 27, 2019
Merged

Add Transitions with :indefinite examples#31
vlaaad merged 2 commits into
cljfx:masterfrom
frenchy64:transitions

Conversation

@frenchy64

@frenchy64 frenchy64 commented Jul 12, 2019

Copy link
Copy Markdown
Contributor

Based on the feedback of #30, this PR adds support for JavaFX transitions.

The example demonstrates all transitions using :indefinite cycles. I haven't tried transitions that are more responsive, and we should probably try them before merging this.

Example gif

@vlaaad vlaaad left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good stuff! There are some minor issues I want to see adressed first, then I'd be happy to merge it.

Comment thread src/cljfx/fx/animation.clj Outdated
:on-cycle-duration-changed [:property-change-listener lifecycle/change-listener]
:delay [:setter lifecycle/scalar :coerce coerce/duration :default 0]
:on-delay-changed [:property-change-listener lifecycle/change-listener]
:on-finished [:setter lifecycle/event-handler :coerce coerce/event-handler :default nil]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:default nil is default behavior, no need to specify it. What's more problematic, is that presence of :default will make it go through coerce function, and nil is not a valid input to coerce/event-handler. Removing default will assign nil to finished event handler, which is what we want.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes done.

Comment thread src/cljfx/fx/animation.clj Outdated
:auto-reverse [:setter lifecycle/scalar :default false]
:on-auto-reverse-changed [:property-change-listener lifecycle/change-listener]
:on-current-time-changed [:property-change-listener lifecycle/change-listener]
:cycle-count [:setter lifecycle/scalar :coerce coerce/animation :default 1.0]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cycle count is int, I know it's coerced to int, but I think default should also be int to make clear.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, in this case the javadoc for Animation was wrong.

:coerce #(if (string? %)
%
(coerce/duration %))]
:on-status-changed [:property-change-listener lifecycle/change-listener]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:on-status-changed will receive enum like Animation$Status/STOPPED. I'm not sure whether I want to receive it or keyword :stopped... From one hand, it's nice to have same values for :status and :on-status-changed, like we have :text and :on-text-changed for text field. On the other hand, cljfx does no preprocessing for events, and I find it valuable to have KeyEvents themselves in event handlers, because they have useful information. Although, enum is no better than keyword, and there is no additional information in this case.

What do you think?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a preprocessed event could be added to another :fx/* key other than :fx/event, but this seems consistent with the rest of cljfx, if ugly.

Comment thread src/cljfx/fx/fade_transition.clj Outdated
:duration [:setter lifecycle/scalar :coerce coerce/duration :default 400]
:from-value [:setter lifecycle/scalar :coerce double :default ##NaN]
:to-value [:setter lifecycle/scalar :coerce double :default ##NaN]
:by-value [:setter lifecycle/scalar :coerce double])))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:by-value should have :default 0

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment thread src/cljfx/fx/fill_transition.clj Outdated
:shape [:setter lifecycle/dynamic]
:duration [:setter lifecycle/scalar :coerce coerce/duration :default 400]
:from-value [:setter lifecycle/scalar :coerce coerce/color :default nil]
:to-value [:setter lifecycle/scalar :coerce coerce/color :default nil])))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should remove :defaults: nil is not a valid input for coerce/color

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment thread src/cljfx/coerce.clj Outdated
(= :indefinite x) Animation/INDEFINITE
:else (int x)))

(defn interpolator [x]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be moved to cljfx.fx.transition

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment thread src/cljfx/coerce.clj Outdated
(defn animation [x]
(cond
(= :indefinite x) Animation/INDEFINITE
:else (int x)))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be moved to cljfx.fx.animation

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment thread src/cljfx/coerce.clj Outdated
:linear Interpolator/LINEAR
(fail Interpolator x))))

(defn path-transition-orientation [x]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be moved to cljfx.fx.path-transition

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced with coerce/enum.

{:fx/type view
:state state}))))

(fx/mount-renderer *state renderer)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed you don't use state at all, in that case there is no need to introduce state/renderer in example, just use fx/create-component:

(fx/on-fx-thread
  (fx/create-component
    {:fx/type :stage
     :showing true
     :always-on-top true
     :width 600
     :height 500
     :scene {:fx/type :scene
             :root {:fx/type on-grid
                    :rows 5
                    :columns 2
                    :children (mapv
                                (fn [[header transition]]
                                  (with-header
                                    header
                                    {:fx/type start-transition-on
                                     :transition transition
                                     ; run each animation on a small rectangle
                                     :desc {:fx/type :rectangle
                                            :width 20
                                            :height 50}}))
                                indefinite-animations)}}}))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved the state stuff to a comment; I think it's always nice to be able to use state to play with the examples.

Comment thread src/cljfx/fx/translate_transition.clj Outdated
:playing (.play ^TranslateTransition %1)
:stopped (.stop ^TranslateTransition %1)))
lifecycle/scalar
:default :stopped])))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:state is covered by :status, there is no need for such prop, right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deleted.

@frenchy64

Copy link
Copy Markdown
Contributor Author

I've addressed all the changes, I'll let you resolve the change requests. Thanks for your time!

@vlaaad
vlaaad merged commit 9fa71bb into cljfx:master Jul 27, 2019
@vlaaad

vlaaad commented Jul 27, 2019

Copy link
Copy Markdown
Contributor

Thanks!

@frenchy64 frenchy64 mentioned this pull request Sep 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants