Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Development branch #101

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
60 changes: 52 additions & 8 deletions src/mruby-zest/example/TextLine.qml
Original file line number Diff line number Diff line change
Expand Up @@ -50,28 +50,72 @@ 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cursor_row instead of cursorrow

  • it's the same as in @edit.cursor_row, which reduces the mental load (we don't have to think whether to spell it one way or another)
  • using snake case seems standard in Ruby: https://namingconvention.org/ruby/


if(k.ord == 8)
self.label = self.label[0...-1]
elsif k.ord >= 32
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line disappeared with your change, and it's important. This is how TextLine ignores most of the non-printable characters.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @pgervais ,
This line is the same as self.label = ll[0...-1], because of that I removed it and tried to replace my line with the previous line and the result was the same.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to double check we're talking about the same thing. I was referring to the "elsif k.ord >= 32" line. Is that what you meant?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly an off-topic comment, but make sure to use a581036 in your branch if you're experiencing problems with creating shorter strings.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Phillip,
No, I mean the self.label line, but I used the else instead of this line (elsif k.ord >= 32) but I realized that in the else I include the case where k.ord between 8 and 32, so I think I need to modify it as you say, what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can implement it the way you prefer. What is most important is to make sure values of k.ord less than 32 are ignored (with the exception of 8)

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
}

function onMerge(val)
{
self.label = val.label
}
}
}
4 changes: 4 additions & 0 deletions src/mruby-zest/mrblib/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down