Skip to content

Commit 6b85e30

Browse files
committed
Add block_constructor macro to AreaHandler and TableModelHandler classes
1 parent 1d2f030 commit 6b85e30

3 files changed

Lines changed: 18 additions & 14 deletions

File tree

src/uing/area/area_handler.cr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
module UIng
22
class AreaHandler
3+
block_constructor
4+
35
def initialize(@cstruct : LibUI::AreaHandler = LibUI::AreaHandler.new)
46
end
57

src/uing/control.cr

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
11
module UIng
2+
macro block_constructor
3+
def self.new(*args, &block)
4+
instance = new(*args)
5+
with instance yield
6+
instance
7+
end
8+
9+
def self.new(*args, **kwargs, &block)
10+
instance = new(*args, **kwargs)
11+
with instance yield
12+
instance
13+
end
14+
end
15+
216
module MethodMissing
317
# Dynamic method generation macro that automatically creates wrapper methods
418
# for libui C API functions based on the calling class and method name.
@@ -34,20 +48,6 @@ module UIng
3448
end
3549
{% end %}
3650
end
37-
38-
macro block_constructor
39-
def self.new(*args, &block)
40-
instance = new(*args)
41-
with instance yield
42-
instance
43-
end
44-
45-
def self.new(*args, **kwargs, &block)
46-
instance = new(*args, **kwargs)
47-
with instance yield
48-
instance
49-
end
50-
end
5151
end
5252

5353
module Control

src/uing/table/table_model_handler.cr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
module UIng
22
class TableModelHandler
3+
block_constructor
4+
35
def initialize(@cstruct : LibUI::TableModelHandler = LibUI::TableModelHandler.new)
46
end
57

0 commit comments

Comments
 (0)