class AuthorEngine::CodeEditor
Constants
- DEFAULT_STRING
Attributes
x_offset[RW]
y_offset[RW]
Public Instance Methods
blur()
click to toggle source
# File lib/author_engine/views/code_editor.rb, line 63 def blur window.text_input = nil end
code()
click to toggle source
# File lib/author_engine/views/code_editor.rb, line 103 def code; @text_input.text; end
draw()
click to toggle source
Calls superclass method
# File lib/author_engine/views/code_editor.rb, line 67 def draw # Gosu.draw_rect(0, window.container.header_height, @width, @height, white) super Gosu.clip_to(0, window.container.header_height, window.width, window.height - window.container.header_height) do Gosu.draw_rect(0, window.container.header_height, @line_numbers_width, @height, dark_gray) Gosu.translate(0, @y_offset) do min_width = @font.text_width("0")+@x_padding (@text.message.lines.map(&:chomp)).each_with_index do |line, index| min_width = @font.text_width("#{index+1}") if @font.text_width("#{index+1}") > min_width @font.draw_text("#{index+1}", 1, window.container.header_height + (@font.height * index), 0) end @line_numbers_width = min_width @text.x = @line_numbers_width+@x_padding end end Gosu.clip_to(@line_numbers_width, window.container.header_height, window.width, @height) do Gosu.translate(@x_offset, @y_offset) do @text.draw_markup @cursor.draw end end end
focus()
click to toggle source
# File lib/author_engine/views/code_editor.rb, line 58 def focus window.text_input = @text_input window.caption = "Code Editor" end
setup()
click to toggle source
# File lib/author_engine/views/code_editor.rb, line 38 def setup @font_size = 5 * window.square_scale.floor @font = Gosu::Font.new(@font_size, name: Text::FONT_DEFAULT_BOLD) # "Consolas" @line_numbers_spacing = "00" @line_numbers_width = @font.text_width(@line_numbers_spacing) @text_input = CodeInput.new if window.container.savefile.code.nil? @text_input.text = DEFAULT_STRING else @text_input.text = window.container.savefile.code end @text = AuthorEngine::Text.new(message: "", size: @font_size, x: @line_numbers_width+@x_padding, y: window.container.header_height, font: Text::FONT_DEFAULT) # "DejaVu Sans Mono" @cursor = Cursor.new(view: self, text_input: @text_input, text: @text) @highlighting = Highlighting.new @x_offset, @y_offset = 0, 0 end
update()
click to toggle source
Calls superclass method
# File lib/author_engine/views/code_editor.rb, line 94 def update super # @text_input.text+="\n" if Gosu.button_down?(Gosu::KbEnter) || Gosu.button_down?(Gosu::KbReturn) # FIXME @caret_pos = @text_input.caret_pos @highlighting.highlight(string: @text_input.text, text: @text) @cursor.update end