Class: Nuklear::Context

Inherits:
Object
  • Object
show all
Includes:
UI::Container
Defined in:
lib/nuklear/context.rb,
ext/nuklear/nkrb_context.c

Defined Under Namespace

Classes: EventSink

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#eventsObject (readonly)

Returns the value of attribute events.



5
6
7
# File 'lib/nuklear/context.rb', line 5

def events
  @events
end

#rendererObject

Returns the value of attribute renderer.



4
5
6
# File 'lib/nuklear/context.rb', line 4

def renderer
  @renderer
end

Instance Method Details

#any_editor_active?Boolean

Returns:

  • (Boolean)


223
224
225
226
227
228
229
230
231
232
233
# File 'ext/nuklear/nkrb_context.c', line 223

static VALUE nkrb_context_is_any_editor_active(VALUE self) {
  struct nk_context *ctx = nkrb_context_get(self);
  struct nk_window *iter;
  iter = ctx->begin;
  while (iter) {
    if (iter->edit.active & NK_EDIT_ACTIVE)
      return Qtrue;
    iter = iter->next;
  }
  return Qfalse;
}

#any_item_active?Boolean

Returns:

  • (Boolean)


235
236
237
238
239
# File 'ext/nuklear/nkrb_context.c', line 235

static VALUE nkrb_context_is_any_item_active(VALUE self) {
  struct nk_context *ctx = nkrb_context_get(self);
  if (nkrb_context_is_any_editor_active(self) == Qtrue) return Qtrue;
  return nk_item_is_any_active(ctx) ? Qtrue : Qfalse;
}

#dsl(&block) ⇒ Object



26
27
28
# File 'lib/nuklear/context.rb', line 26

def dsl(&block)
  Nuklear::DSL.new(self, &block)
end

#process_commandsObject



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

#tickObject



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

#uiObject

}



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_dataObject



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;
}