Sha256: 74d291d8ff2a7e69c71e18e3866c9d66c1acaa17c463f797751c5a95130f7d67
Contents?: true
Size: 1.96 KB
Versions: 6
Compression:
Stored size: 1.96 KB
Contents
<!-- # @markup markdown # @title 6. wxRuby geometry classes --> # 6. wxRuby Geometry classes ## Size (Wx::Size) and position (Wx::Point) The wxWidgets API has a lot methods that require either `wxSize`, `wxPoint` or both type of value as argument. Although this can be specified in C++ still relatively concise like ```ruby new wxFrame(nullptr, -1, "title", wxPoint(0,0), wxSize(500,400)) ``` in Ruby this expands to the more verbose ```ruby Wx::Frame.new(nil, -1, 'title', Wx::Point.new(0,0), Wx::Size.new(500,400)) ``` which starts to feel awkward to specify what are in essence just pairs of integers. To provide a simpler, more compact and more Ruby-like, alternative the wxRuby API therefor supports specifying arrays of integer pairs in (almost) all cases where `Wx::Size` or `Wx::Point` is expected. So the following code is equivalent to the previous code: ```ruby Wx::Frame.new(nil, -1, 'title', [0,0], [500,400]) ``` In addition `Wx::Size` and `Wx::Point` support parallel assignment semantics such that you can write code like ```ruby win.paint do | dc | # ... x, y = win.get_position dc.draw_circle(x, y, 4) dc.draw_rectangle(x-4, y-4, 8, 8) end ``` instead of ```ruby win.paint do | dc | # ... pos = win.get_position dc.draw_circle(pos.x, pos.y, 4) dc.draw_rectangle(pos.x-4, pos.y-4, 8, 8) end ``` ## Areas (Wx::Rect) Like `Wx::Size` and `Wx::Point` wxRuby supports parallel assignment for `Wx::Rect` such that you can write code like ```ruby x, y, width, height = win.get_client_rect ``` Providing arrays of integers as alternative for `Wx::Rect` arguments is not supported as specifying `[0, 0, 20, 40]` is ambiguous. This could either mean a rectangle with origin `x=0,y=0` and size `width=20,height=40` (`Wx::Rect.new(0,0,20,40)`) or a rectangle from origin top left `x=0,y=0` to point bottom right `x=20,y=40` (`Wx::Rect.new(Wx::Point.new(0,0), Wx::Point.new(20,40))`).
Version data entries
6 entries across 6 versions & 1 rubygems