Usage example for toggle group - #2
nader-eloshaiker wants to merge 5 commits into
Conversation
|
@hanjoes thought it might be a good idea to show how the grouping would work |
|
yep, once i added the tests I will put that in the demo |
|
While I'm trying to build the demo, I had some more thoughts about the toggle feature. I want to know your opinion:
@nader-eloshaiker please let me know your thoughts. (I feel we can hold off 2, but 1 is more important to me at the moment.) |
|
Also the current way of adding each other to the toggle group will introduce strong reference cycles if not used properly , also adding mutual dependency doesn't feel right if we have a lot of buttons while using some centralized store for toggle groups can potentially make the maintenance a lot easier. |
|
Point 1 sounds like a good approach, however, with point 2, you will need a way for the button to know it is associated with a toggle group to ensure certain behaviour, ie perhaps not trigger toggle off behaviour. Perhaps start a branch and we can work on this together? |
|
With point 2, perhaps we should consider creating an entirely new concrete class called SKSpriteButtonGroup and attach action listerners to that as well of the toggle action on the button itself. eg That way, if the dev want to create a plain old toggle button, he can add action listeners to the button, but if the dev wants to create a group, then he/she only needs to assign one listener. Doing this, get around having to check if the button belongs to a group and not calling toggle off actions as the dev doesn't have to worry about it. |
|
Thinking about this some more, you will still need, at the very least, a weak reference to the button group object to be able to call the group actions on a button touch event. |
|
I like the SKSpriteButtonGroup idea. actually had some local implementation after my comments yesterday (with exactly the same name!) along with an "Unowned" wrapper (I prefer unowned here since it doesn't make sense for an empty wrapper in the button use case and we are not exposing that wrapper to users.) Here are some simple code example: struct SKUnowned<T: AnyObject & Hashable>: Hashable {
var hashValue: Int {
return value.hashValue * 31
}
static func ==(lhs: SKUnowned<T>, rhs: SKUnowned<T>) -> Bool {
return lhs == rhs
}
unowned var value: T
}
class SKSpriteButtonGroup {
public var buttons = Set<SKUnowned<SKSpriteButton>>()
public func add(button: SKSpriteButton) {
buttons.insert(SKUnowned(value: button))
}
public func remove(button: SKSpriteButton) {
buttons.remove(SKUnowned(value: button))
}
}This button group should really be general, but it serves features like toggling. For group toggling to work, we should let user creates a group and adds the buttons to group (during insertion we assign the group back to each button's "group" property). The I will create a remote branch. Currently we have 3 main things to do:
|
|
How do you feel about the idea of adding a handler to the SKSpriteButtonGroup class |
|
If it's not absolutely needed at the moment for implementing toggle group, we don't need to add it immediately. |
|
Definitely not a must have, we can add it in at a later time if we still think it is a good idea. |
|
cool, i can work on 2 and maybe you can finishing up toggling with 1 and 3? |
|
Great :) |
|
added toggle-group remote branch :) |
|
I'll need permissions to write to it (saves me having to manually sync my fork) |
|
I'm happy for you to be the gate keeper for merges into master. |
|
sure, let me add you to collaborator |
|
Hey;
Sorry it has been a while since I last spoke with you. Life is slowly returning back to normal for me so I have started to look at coding at home again.
I’ll go over what I was planning over the following week and make a start.
How have you been? Have you done anything lately with the code?
…--
Sent from my ENIAC®
On 15 Jan 2018, at 3:54 pm, hanjoes ***@***.***> wrote:
sure, let me add you to collaborator
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#2 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AB0Oxct0SxS-MOaiXk3mVIauey_cNgtLks5tKtoigaJpZM4Ranyb>.
|
|
Hey! Glad you are back.
I worked on this repo intermittently lately.
Changes including
1. refactoring for the “disable” feature with unit tests.
2. removed “toggle" from mainline as it was not completed according to our discussion.
Feel free to submit a PR for the toggle feature if you are going to work on it.
hanjoes
… On Mar 24, 2018, at 1:53 AM, Nader Eloshaiker ***@***.***> wrote:
Hey;
Sorry it has been a while since I last spoke with you. Life is slowly returning back to normal for me so I have started to look at coding at home again.
I’ll go over what I was planning over the following week and make a start.
How have you been? Have you done anything lately with the code?
--
Sent from my ENIAC®
> On 15 Jan 2018, at 3:54 pm, hanjoes ***@***.***> wrote:
>
> sure, let me add you to collaborator
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub <#2 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AB0Oxct0SxS-MOaiXk3mVIauey_cNgtLks5tKtoigaJpZM4Ranyb>.
>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#2 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AGGhx1XxuaAkBoKALD0o8Y-k6Y-2ZpUgks5thgmGgaJpZM4Ranyb>.
|
|
Yeah I have just noticed and issue with switching from disabled to enabled.
I think sprite might have a problem with continually switch the userinteractionenabled property
Sent from my ENIAC®
… On 25 Mar 2018, at 1:58 pm, hanjoes ***@***.***> wrote:
Hey! Glad you are back.
I worked on this repo intermittently lately.
Changes including
1. refactoring for the “disable” feature with unit tests.
2. removed “toggle" from mainline as it was not completed according to our discussion.
Feel free to submit a PR for the toggle feature if you are going to work on it.
hanjoes
> On Mar 24, 2018, at 1:53 AM, Nader Eloshaiker ***@***.***> wrote:
>
> Hey;
>
> Sorry it has been a while since I last spoke with you. Life is slowly returning back to normal for me so I have started to look at coding at home again.
>
> I’ll go over what I was planning over the following week and make a start.
>
> How have you been? Have you done anything lately with the code?
>
> --
> Sent from my ENIAC®
>
> > On 15 Jan 2018, at 3:54 pm, hanjoes ***@***.***> wrote:
> >
> > sure, let me add you to collaborator
> >
> > —
> > You are receiving this because you were mentioned.
> > Reply to this email directly, view it on GitHub <#2 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AB0Oxct0SxS-MOaiXk3mVIauey_cNgtLks5tKtoigaJpZM4Ranyb>.
> >
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub <#2 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AGGhx1XxuaAkBoKALD0o8Y-k6Y-2ZpUgks5thgmGgaJpZM4Ranyb>.
>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
|
Hey Hanjoes;
Have you looked at my pull request? It’s a pretty big refactor.
Regards
Nader
… On 25 Mar 2018, at 1:58 pm, hanjoes ***@***.***> wrote:
Hey! Glad you are back.
I worked on this repo intermittently lately.
Changes including
1. refactoring for the “disable” feature with unit tests.
2. removed “toggle" from mainline as it was not completed according to our discussion.
Feel free to submit a PR for the toggle feature if you are going to work on it.
hanjoes
> On Mar 24, 2018, at 1:53 AM, Nader Eloshaiker ***@***.***> wrote:
>
> Hey;
>
> Sorry it has been a while since I last spoke with you. Life is slowly returning back to normal for me so I have started to look at coding at home again.
>
> I’ll go over what I was planning over the following week and make a start.
>
> How have you been? Have you done anything lately with the code?
>
> --
> Sent from my ENIAC®
>
> > On 15 Jan 2018, at 3:54 pm, hanjoes ***@***.***> wrote:
> >
> > sure, let me add you to collaborator
> >
> > —
> > You are receiving this because you were mentioned.
> > Reply to this email directly, view it on GitHub <#2 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AB0Oxct0SxS-MOaiXk3mVIauey_cNgtLks5tKtoigaJpZM4Ranyb>.
> >
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub <#2 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AGGhx1XxuaAkBoKALD0o8Y-k6Y-2ZpUgks5thgmGgaJpZM4Ranyb>.
>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#2 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AB0OxVqRaWf7Jlc0fuJzZEftARa7XTvZks5thwfagaJpZM4Ranyb>.
|
|
Hey! Got distracted by something else. Sorry, i will take a look this weekend. It does seem to be a big refactoring. |
No description provided.