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
Changes from 1 commit
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
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

cursor_row = @edit.calc_cursor_y
Copy link
Contributor

Choose a reason for hiding this comment

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

calc_cursor_y is not defined in util.rb:EditRegion, which makes the UI crash as soon as you try typing something in the widget.

Have you committed all your changes?

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,
I added another commit to solve this issue and now it should work properly.


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+cursor_row) + ll.slice(pos+1+cursor_row, ll.length)
end
else
self.label = ll.insert(pos+cursor_row, 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
}
}
}