Class: Clogs::Canvas
- Inherits:
-
Object
- Object
- Clogs::Canvas
- Defined in:
- lib/clogs/canvas.rb
Overview
Owns a uiArea and turns libui's callbacks into ordinary Ruby ones.
Everything Clogs draws lives in a single area per window. That is not a stylistic choice: libui has no container that positions native controls at arbitrary coordinates, and Shoes' layout model requires exactly that. So Clogs paints the whole Shoes document itself and synthesises the widgets Shoes needs. See docs/libui_shoes_coverage.md.
Defined Under Namespace
Classes: KeyEvent, MouseEvent
Instance Attribute Summary collapse
-
#area ⇒ Object
readonly
Returns the value of attribute area.
-
#on_crossed ⇒ Object
Returns the value of attribute on_crossed.
-
#on_draw ⇒ Object
Returns the value of attribute on_draw.
-
#on_key ⇒ Object
Returns the value of attribute on_key.
-
#on_mouse ⇒ Object
Returns the value of attribute on_mouse.
Instance Method Summary collapse
-
#initialize(scrolling: false, scroll_width: 0, scroll_height: 0) ⇒ Canvas
constructor
A new instance of Canvas.
- #redraw ⇒ Object
- #scroll_to(x, y, w, h) ⇒ Object
- #set_scroll_size(w, h) ⇒ Object
Constructor Details
#initialize(scrolling: false, scroll_width: 0, scroll_height: 0) ⇒ Canvas
Returns a new instance of Canvas.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/clogs/canvas.rb', line 18 def initialize(scrolling: false, scroll_width: 0, scroll_height: 0) @handler = UI.malloc(UI::L::FFI::AreaHandler) @handler.Draw = UI.callback(0, [1, 1, 1]) do |_h, _area, params| p = UI::L::FFI::AreaDrawParams.new(params) painter = Painter.new(p.Context, p.AreaWidth, p.AreaHeight) @on_draw&.call(painter, p) 0 end @handler.MouseEvent = UI.callback(0, [1, 1, 1]) do |_h, _area, evt| e = UI::L::FFI::AreaMouseEvent.new(evt) @on_mouse&.call(mouse_event(e)) 0 end @handler.MouseCrossed = UI.callback(0, [1, 1, 0]) do |_h, _area, left| @on_crossed&.call(left != 0) 0 end @handler.DragBroken = UI.callback(0, [1, 1]) { 0 } @handler.KeyEvent = UI.callback(1, [1, 1, 1]) do |_h, _area, evt| e = UI::L::FFI::AreaKeyEvent.new(evt) handled = @on_key&.call(key_event(e)) handled ? 1 : 0 end @area = if scrolling UI::L.new_scrolling_area(@handler, scroll_width, scroll_height) else UI::L.new_area(@handler) end @scrolling = scrolling end |
Instance Attribute Details
#area ⇒ Object (readonly)
Returns the value of attribute area.
15 16 17 |
# File 'lib/clogs/canvas.rb', line 15 def area @area end |
#on_crossed ⇒ Object
Returns the value of attribute on_crossed.
16 17 18 |
# File 'lib/clogs/canvas.rb', line 16 def on_crossed @on_crossed end |
#on_draw ⇒ Object
Returns the value of attribute on_draw.
16 17 18 |
# File 'lib/clogs/canvas.rb', line 16 def on_draw @on_draw end |
#on_key ⇒ Object
Returns the value of attribute on_key.
16 17 18 |
# File 'lib/clogs/canvas.rb', line 16 def on_key @on_key end |
#on_mouse ⇒ Object
Returns the value of attribute on_mouse.
16 17 18 |
# File 'lib/clogs/canvas.rb', line 16 def on_mouse @on_mouse end |
Instance Method Details
#redraw ⇒ Object
55 56 57 |
# File 'lib/clogs/canvas.rb', line 55 def redraw UI::L.area_queue_redraw_all(@area) end |