Class: Nuklear::Context
- Inherits:
-
Object
- Object
- Nuklear::Context
- Includes:
- UI::Container
- Defined in:
- lib/nuklear/context.rb,
ext/nuklear/nkrb_context.c
Defined Under Namespace
Classes: EventSink
Instance Attribute Summary collapse
-
#events ⇒ Object
readonly
Returns the value of attribute events.
-
#renderer ⇒ Object
Returns the value of attribute renderer.
Instance Method Summary collapse
- #dsl(&block) ⇒ Object
- #initialize(font) ⇒ Object constructor
- #process_commands ⇒ Object
- #tick ⇒ Object
-
#trigger(event_name, *event_args) ⇒ Object
Triggers an event.
-
#ui ⇒ Object
}.
- #user_data ⇒ Object
- #user_data=(userdata) ⇒ Object
Methods included from UI::Container
#<<, #commands, #find, #layout_row_dynamic, #method_missing, #run_command, #run_commands, #traverse, #ui_checkbox, #ui_color_picker, #ui_combo, #ui_edit_focus, #ui_edit_string, #ui_layout_row_begin, #ui_layout_row_dynamic, #ui_layout_row_push, #ui_layout_row_static, #ui_layout_row_template_begin, #ui_layout_row_template_dynamic, #ui_layout_row_template_end, #ui_layout_row_template_static, #ui_layout_row_template_variable, #ui_layout_space_begin, #ui_layout_space_end, #ui_layout_space_push, #ui_layout_widget_bounds, #ui_menu_item, #ui_option, #ui_selectable, #ui_window_close
Constructor Details
#initialize(font) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'ext/nuklear/nkrb_context.c', line 59
VALUE nkrb_context_initialize(VALUE context, VALUE font) {
struct nk_context *ctx = nkrb_context_get(context);
if (nk_init_default(ctx, nkrb_font_to_nk(font)) == 0) {
rb_raise(rb_eStandardError, "Failed to initialize Nuklear context");
}
set_default_style(ctx);
VALUE event_sink = rb_funcall(cNuklearContextEventSink, rb_intern("new"), 1, context);
rb_ivar_set(context, rb_intern("@event_sink"), event_sink);
rb_ivar_set(context, rb_intern("@font"), font);
rb_ivar_set(context, rb_intern("@null"), nkrb_font_get_null(font));
rb_ivar_set(context, rb_intern("@ui_builder"), rb_funcall(cNuklearUIBuilder, rb_intern("new"), 1, context));
return context;
}
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Nuklear::UI::Container
Instance Attribute Details
#events ⇒ Object (readonly)
Returns the value of attribute events.
5 6 7 |
# File 'lib/nuklear/context.rb', line 5 def events @events end |
#renderer ⇒ Object
Returns the value of attribute renderer.
4 5 6 |
# File 'lib/nuklear/context.rb', line 4 def renderer @renderer end |
Instance Method Details
#dsl(&block) ⇒ Object
26 27 28 |
# File 'lib/nuklear/context.rb', line 26 def dsl(&block) Nuklear::DSL.new(self, &block) end |
#process_commands ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/nuklear/context.rb', line 11 def process_commands remaining = commands.dup while remaining.any? cmd = remaining.shift # cmd.tick(delta) if cmd.respond_to?(:tick) remaining.concat cmd.commands if cmd.respond_to?(:commands) end end |
#tick ⇒ Object
86 87 88 89 90 91 92 93 94 |
# File 'ext/nuklear/nkrb_context.c', line 86 VALUE nkrb_context_tick(VALUE self) { VALUE_TO_NK(self, ctx); nk_input_begin(ctx); rb_funcall(self, rb_intern("process_pending_events"), 0); nk_input_end(ctx); rb_funcall(self, rb_intern("paint"), 0); nk_clear(ctx); return self; } |
#trigger(event_name, *event_args) ⇒ Object
Triggers an event. The event name must be one of the symbols defined in Nuklear::EventBuffer::EVENT_NAMES.
22 23 24 |
# File 'lib/nuklear/context.rb', line 22 def trigger(event_name, *event_args) events.add(event_name, *event_args) end |
#ui ⇒ Object
}
216 217 218 219 220 221 |
# File 'ext/nuklear/nkrb_context.c', line 216 VALUE nkrb_context_ui(VALUE self) { VALUE ui = rb_ivar_get(self, rb_intern("@ui_builder")); rb_need_block(); rb_funcall_with_block(ui, rb_intern("instance_eval"), 0, NULL, rb_block_proc()); return ui; } |
#user_data ⇒ Object
82 83 84 |
# File 'ext/nuklear/nkrb_context.c', line 82 VALUE nkrb_context_get_user_data(VALUE self) { return rb_ivar_get(self, rb_intern("@userdata")); } |
#user_data=(userdata) ⇒ Object
74 75 76 77 78 79 80 |
# File 'ext/nuklear/nkrb_context.c', line 74
VALUE nkrb_context_set_user_data(VALUE self, VALUE userdata) {
VALUE_TO_NK(self, ctx);
// maybe come back to this, might be able to access user data later on through context
// nk_set_user_data(ctx, userdata);
rb_ivar_set(self, rb_intern("@userdata"), userdata);
return userdata;
}
|