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

Adjust::Center #7

Closed
ParkinT opened this Issue Aug 29, 2012 · 5 comments

Comments

Projects
None yet
2 participants
@ParkinT
Contributor

ParkinT commented Aug 29, 2012

I simply love this gem. You have done a magnificent job with it.
I did some hacking on the 'adjust.rb' and added this neat little bit.

##|  CENTER (in parent frame)
# you can set 'direction' with any number of forms: 'horiz', 'vert', 'x', 'x and y'
def center(element=1, total=1, direction='horizontal', verbose=true)
  @@sugarcube_view ||= nil
  raise "no view has been assigned to SugarCube::Adjust::adjust" unless @@sugarcube_view

  view = @@sugarcube_view
  left = view.origin.x
  top = view.origin.y
  pwidth = view.superview.frame.width
  pheight = view.superview.frame.height
  left = ((pwidth - view.frame.width) * element) / (total + 1) if /hor|x/.match(direction.downcase)
  top = ((pheight - view.frame.height) * element) / (total + 1) if /ver|y/.match(direction.downcase)
  self.origin left, top

  puts "#{view.class.name}.origin = [#{left}, #{top}]" if verbose # output in a format to be copied and pasted into your source
end

If you like what I have done, I will continue with a few more ideas and submit a proper Pull Request from a Fork.

@ParkinT

This comment has been minimized.

Show comment
Hide comment
@ParkinT

ParkinT Aug 29, 2012

Contributor

BTW: The purpose (and usage) on this addition is to help in CENTERING controls.
I find myself struggling with cumbersome math or, now with SugarCube, a lot of nudging.
This allows me to automatically center a control in its parent view (and the output is formatted to paste into my code).
A few example calls would be:
center #default is horizontal center of one control
center 1, 3 #this is will be in the ONE position of THREE centered controls
center 2,3 #place this control as the SECOND in a set of three
center 1,3,'vert' #Vertical center. By default it is horizontal
center 3,3,'vert_horiz' #center both vertically and horizontally as the THIRD of THREE

The final parameter is a verbose switch to control the output that can be pasted back into source code for the final position.

Contributor

ParkinT commented Aug 29, 2012

BTW: The purpose (and usage) on this addition is to help in CENTERING controls.
I find myself struggling with cumbersome math or, now with SugarCube, a lot of nudging.
This allows me to automatically center a control in its parent view (and the output is formatted to paste into my code).
A few example calls would be:
center #default is horizontal center of one control
center 1, 3 #this is will be in the ONE position of THREE centered controls
center 2,3 #place this control as the SECOND in a set of three
center 1,3,'vert' #Vertical center. By default it is horizontal
center 3,3,'vert_horiz' #center both vertically and horizontally as the THIRD of THREE

The final parameter is a verbose switch to control the output that can be pasted back into source code for the final position.

@colinta

This comment has been minimized.

Show comment
Hide comment
@colinta

colinta Aug 29, 2012

Member

Very cool! I'm heading to bed, but I'll definitely be checking this out in the morning.

On Aug 28, 2012, at 9:06 PM, Thom Parkin notifications@github.com wrote:

BTW: The purpose (and usage) on this addition is to help in CENTERING controls.
I find myself struggling with cumbersome math or, now with SugarCube, a lot of nudging.
This allows me to automatically center a control in its parent view (and the output is formatted to paste into my code).
A few example calls would be:
center #default is horizontal center of one control
center 1, 3 #this is will be in the ONE position of THREE centered controls
center 2,3 #place this control as the SECOND in a set of three
center 1,3,'vert' #Vertical center. By default it is horizontal
center 3,3,'vert_horiz' #center both vertically and horizontally as the THIRD of THREE

The final parameter is a verbose switch to control the output that can be pasted back into source code for the final position.


Reply to this email directly or view it on GitHub.

Member

colinta commented Aug 29, 2012

Very cool! I'm heading to bed, but I'll definitely be checking this out in the morning.

On Aug 28, 2012, at 9:06 PM, Thom Parkin notifications@github.com wrote:

BTW: The purpose (and usage) on this addition is to help in CENTERING controls.
I find myself struggling with cumbersome math or, now with SugarCube, a lot of nudging.
This allows me to automatically center a control in its parent view (and the output is formatted to paste into my code).
A few example calls would be:
center #default is horizontal center of one control
center 1, 3 #this is will be in the ONE position of THREE centered controls
center 2,3 #place this control as the SECOND in a set of three
center 1,3,'vert' #Vertical center. By default it is horizontal
center 3,3,'vert_horiz' #center both vertically and horizontally as the THIRD of THREE

The final parameter is a verbose switch to control the output that can be pasted back into source code for the final position.


Reply to this email directly or view it on GitHub.

@colinta

This comment has been minimized.

Show comment
Hide comment
@colinta

colinta Sep 11, 2012

Member

Where's your pull request! :-)

Member

colinta commented Sep 11, 2012

Where's your pull request! :-)

@ParkinT

This comment has been minimized.

Show comment
Hide comment
@ParkinT

ParkinT Sep 12, 2012

Contributor

Ah.
This was so simple, I just posted ALL THE CODE in this issue (along with usage for the documentation).

I plan to work on more features (and maybe find more bugs) and at that time I will submit pull request(s).

Contributor

ParkinT commented Sep 12, 2012

Ah.
This was so simple, I just posted ALL THE CODE in this issue (along with usage for the documentation).

I plan to work on more features (and maybe find more bugs) and at that time I will submit pull request(s).

@ParkinT

This comment has been minimized.

Show comment
Hide comment
@ParkinT

ParkinT Oct 5, 2012

Contributor

This Pull Request represents the feature.

Contributor

ParkinT commented Oct 5, 2012

This Pull Request represents the feature.

@ParkinT ParkinT closed this Oct 5, 2012

colinta added a commit that referenced this issue Oct 19, 2012

Added CENTER command to the ::Adjust capability.
Answer to [issue #7](#7).
Sorry it took me so long to commit this

colinta pushed a commit that referenced this issue Nov 29, 2017

update travis.yml (#7)
* travis cache
* osx_image: xcode9.1, xcode8.3

Signed-off-by: Liu Lantao <liulantao@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment