From 7d1883f35e1bc1af684648f3b7efc2560b2e6eba Mon Sep 17 00:00:00 2001 From: top1million <1180620@student.birzeit.edu> Date: Sat, 25 Mar 2023 15:55:50 +0300 Subject: [PATCH 1/5] cursor --- src/mruby-zest/mrblib/util.rb | 10 +++++++++- src/mruby-zest/qml/TextEdit.qml | 8 ++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/mruby-zest/mrblib/util.rb b/src/mruby-zest/mrblib/util.rb index 0afcd41e..5b2624f6 100644 --- a/src/mruby-zest/mrblib/util.rb +++ b/src/mruby-zest/mrblib/util.rb @@ -55,6 +55,14 @@ def initialize(vg, string, width, height) calc_cursor_x end + def calc_cursor_x() + return @cursor_row + end + + def calc_cursor_y() + return @cursor_row + end + def check_args(vg, string, width, height) if(!([Float,Integer].include? width.class)) raise TypeError.new("Invalid width <#{width.inspect}> expected Integer/Float, got #{width.class}") @@ -123,6 +131,7 @@ def string_to_stats @chrcls << :space elsif(c == "\n" || c == "\r") @chrcls << :line + else @chrcls << :chr end @@ -142,7 +151,6 @@ def string_to_lines push_char(@string[i], @widths[i]) elsif(@chrcls[i] == :line) flush_word_buffer() - @line_widths[@active_line] = @lastw @lastw = @activew = 0 @active_line += 1 diff --git a/src/mruby-zest/qml/TextEdit.qml b/src/mruby-zest/qml/TextEdit.qml index 5ca26fe5..a9144d5c 100644 --- a/src/mruby-zest/qml/TextEdit.qml +++ b/src/mruby-zest/qml/TextEdit.qml @@ -65,15 +65,18 @@ Widget { pos = self.label.length pos = @edit.pos if @edit ll = self.label + size = ll.split(" ").length + line = @edit.calc_cursor_y + puts @cursor[1] if(k.ord == 8) pos -= 1 if(pos >= ll.length) self.label = ll.slice(0, ll.length-1) elsif(pos >= 0) - self.label = ll.slice(0, pos) + ll.slice(pos+1, ll.length) + self.label = ll.slice(0, pos+line) + ll.slice(pos+1+line, ll.length) end else - self.label = ll.insert(pos, k) + self.label = ll.insert(pos+line, k) end ll = self.label self.valueRef.value = ll if self.valueRef @@ -114,6 +117,7 @@ Widget { if(@state) vg.text_align NVG::ALIGN_CENTER | NVG::ALIGN_MIDDLE vg.text(x+10, y, str) + @cursor = [x+10, y] end end end From 6f9c248f0395dd7b415ab14a74df2fe7afe6f544 Mon Sep 17 00:00:00 2001 From: top1million <1180620@student.birzeit.edu> Date: Sat, 25 Mar 2023 15:59:36 +0300 Subject: [PATCH 2/5] cursor removed --- src/mruby-zest/qml/TextEdit.qml | 1 - 1 file changed, 1 deletion(-) diff --git a/src/mruby-zest/qml/TextEdit.qml b/src/mruby-zest/qml/TextEdit.qml index a9144d5c..02931653 100644 --- a/src/mruby-zest/qml/TextEdit.qml +++ b/src/mruby-zest/qml/TextEdit.qml @@ -117,7 +117,6 @@ Widget { if(@state) vg.text_align NVG::ALIGN_CENTER | NVG::ALIGN_MIDDLE vg.text(x+10, y, str) - @cursor = [x+10, y] end end end From 81a680015ec892cda92fbce39b9f55806fa64f18 Mon Sep 17 00:00:00 2001 From: top1million <1180620@student.birzeit.edu> Date: Tue, 28 Mar 2023 20:15:12 +0300 Subject: [PATCH 3/5] fixed the bugs gotta check windows now --- src/mruby-zest/mrblib/util.rb | 8 +------- src/mruby-zest/qml/TextEdit.qml | 4 +--- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/src/mruby-zest/mrblib/util.rb b/src/mruby-zest/mrblib/util.rb index 5b2624f6..0e2bf685 100644 --- a/src/mruby-zest/mrblib/util.rb +++ b/src/mruby-zest/mrblib/util.rb @@ -55,11 +55,7 @@ def initialize(vg, string, width, height) calc_cursor_x end - def calc_cursor_x() - return @cursor_row - end - - def calc_cursor_y() + def cursor_row() return @cursor_row end @@ -131,7 +127,6 @@ def string_to_stats @chrcls << :space elsif(c == "\n" || c == "\r") @chrcls << :line - else @chrcls << :chr end @@ -147,7 +142,6 @@ def string_to_lines @activew += @widths[i] elsif(@chrcls[i] == :space) flush_word_buffer() - push_char(@string[i], @widths[i]) elsif(@chrcls[i] == :line) flush_word_buffer() diff --git a/src/mruby-zest/qml/TextEdit.qml b/src/mruby-zest/qml/TextEdit.qml index 02931653..6baed8e8 100644 --- a/src/mruby-zest/qml/TextEdit.qml +++ b/src/mruby-zest/qml/TextEdit.qml @@ -65,9 +65,7 @@ Widget { pos = self.label.length pos = @edit.pos if @edit ll = self.label - size = ll.split(" ").length - line = @edit.calc_cursor_y - puts @cursor[1] + line = @edit.cursor_row if(k.ord == 8) pos -= 1 if(pos >= ll.length) From 475976750d8a501071f26eb6d65fef2cc17ccead Mon Sep 17 00:00:00 2001 From: top1million <1180620@student.birzeit.edu> Date: Wed, 29 Mar 2023 21:16:29 +0300 Subject: [PATCH 4/5] change line name to cursor row --- src/mruby-zest/qml/TextEdit.qml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/mruby-zest/qml/TextEdit.qml b/src/mruby-zest/qml/TextEdit.qml index 6baed8e8..e83d8ce2 100644 --- a/src/mruby-zest/qml/TextEdit.qml +++ b/src/mruby-zest/qml/TextEdit.qml @@ -65,7 +65,8 @@ Widget { pos = self.label.length pos = @edit.pos if @edit ll = self.label - line = @edit.cursor_row + // Fixing the cursor position bug , by adding the cursor_row to the position + cursor_row = @edit.calc_cursor_y if(k.ord == 8) pos -= 1 if(pos >= ll.length) From 963a209153fa7c371ca4bd27491fab0953c4f2d8 Mon Sep 17 00:00:00 2001 From: top1million <1180620@student.birzeit.edu> Date: Wed, 10 May 2023 21:52:19 +0300 Subject: [PATCH 5/5] Used attr_reader for cursor_row --- src/mruby-zest/mrblib/util.rb | 4 +--- src/mruby-zest/qml/TextEdit.qml | 7 +++---- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/mruby-zest/mrblib/util.rb b/src/mruby-zest/mrblib/util.rb index 0e2bf685..651b3c97 100644 --- a/src/mruby-zest/mrblib/util.rb +++ b/src/mruby-zest/mrblib/util.rb @@ -55,9 +55,7 @@ def initialize(vg, string, width, height) calc_cursor_x end - def cursor_row() - return @cursor_row - end + attr_reader :cursor_row def check_args(vg, string, width, height) if(!([Float,Integer].include? width.class)) diff --git a/src/mruby-zest/qml/TextEdit.qml b/src/mruby-zest/qml/TextEdit.qml index e83d8ce2..69f8083f 100644 --- a/src/mruby-zest/qml/TextEdit.qml +++ b/src/mruby-zest/qml/TextEdit.qml @@ -65,17 +65,16 @@ Widget { pos = self.label.length pos = @edit.pos if @edit ll = self.label - // Fixing the cursor position bug , by adding the cursor_row to the position - cursor_row = @edit.calc_cursor_y + cursor_row = @edit.cursor_row if(k.ord == 8) pos -= 1 if(pos >= ll.length) self.label = ll.slice(0, ll.length-1) elsif(pos >= 0) - self.label = ll.slice(0, pos+line) + ll.slice(pos+1+line, ll.length) + self.label = ll.slice(0, pos+cursor_row) + ll.slice(pos+1+cursor_row, ll.length) end else - self.label = ll.insert(pos+line, k) + self.label = ll.insert(pos+cursor_row, k) end ll = self.label self.valueRef.value = ll if self.valueRef