diff --git a/Makefile b/Makefile index 1d7a385c..33351fc2 100644 --- a/Makefile +++ b/Makefile @@ -41,6 +41,7 @@ osx: deps/libuv.a $(CC) test-libversion.c deps/pugl/build/libpugl-0.a -ldl -o zest -framework OpenGL -framework AppKit -lpthread -I deps/pugl -std=gnu99 windows: buildpuglwin deps/libuv-win.a + ruby ./rebuild-fcache.rb cd deps/nanovg/src && $(CC) -mstackrealign nanovg.c -c $(AR) rc deps/libnanovg.a deps/nanovg/src/*.o cd src/osc-bridge && CFLAGS="-mstackrealign -I ../../deps/libuv/include " make lib diff --git a/src/mruby-zest/example/TextLine.qml b/src/mruby-zest/example/TextLine.qml index 6859c598..00a27e35 100644 --- a/src/mruby-zest/example/TextLine.qml +++ b/src/mruby-zest/example/TextLine.qml @@ -50,23 +50,67 @@ Widget { (0...l.length).each do |i| l[i] = "?" if l.getbyte(i) > 127 end - vg.text(8,h/2,l) - bnd = vg.text_bounds(0,0,l) - if(@state) - vg.text(8+bnd,h/2,"|") + + @edit ||= EditRegion.new($vg, self.label, w-20, h*0.8) + @edit.each_string do |x, y, str, cursor| + if(cursor == false) + vg.text(x+10, y, str) + else + if(@state) + vg.text_align NVG::ALIGN_LEFT| NVG::ALIGN_MIDDLE + vg.text(x+10, y, str) + end + end end + } function onKey(k, mode) { return if mode != "press" + pos = self.label.length + pos = @edit.pos if @edit + ll = self.label + + cursorrow = @edit.cursor_row + if(k.ord == 8) - self.label = self.label[0...-1] - elsif k.ord >= 32 - self.label += k + pos -= 1 + if(pos >= ll.length) + self.label = ll[0...-1] + elsif(pos >= 0) + self.label = ll.slice(0, pos+cursorrow) + ll.slice(pos+1+cursorrow, ll.length) + end + else + self.label = ll.insert(pos+cursorrow, k) end + ll = self.label whenValue.call if whenValue valueRef.value = self.label if valueRef + @edit = EditRegion.new($vg, ll, w-20, 0.8*h) + if(k.ord == 8) + @edit.pos = pos + else + @edit.pos = pos+1 + end + damage_self + } + + + function onSpecial(k, mode) + { + return if @edit.nil? + return if mode != :press + + if(k == :left) + @edit.left + elsif(k == :right) + @edit.right + end + + @state = true + now = Time.new + @next = now + 0.7 damage_self } @@ -74,4 +118,4 @@ Widget { { self.label = val.label } -} +} \ No newline at end of file diff --git a/src/mruby-zest/mrblib/util.rb b/src/mruby-zest/mrblib/util.rb index 0afcd41e..e6259086 100644 --- a/src/mruby-zest/mrblib/util.rb +++ b/src/mruby-zest/mrblib/util.rb @@ -16,6 +16,10 @@ def pad(scale, bb) bb[3] = h; end +def cursor_row() + return @cursor_row +end + class EditRegion def initialize(vg, string, width, height)