Pseudo-Code/Algorithm for an InputBox?

BlitzMax Forums/BlitzMax Programming/Pseudo-Code/Algorithm for an InputBox?

Gabriel(Posted 2006) [#1]
I'm trying to improve my InputBox gadget in my GUI module, and I'm struggling to find a good way to make it scroll. When there is more text than will fit into the inputbox, I currently just draw as much text as will fit, ending at the end of the string and starting as early as possible in the string without the string being too long to fit.

That's fine, unless the cursor is too far foward in the inputbox, in which case you can't see what you're editing, lol. So I'm wondering what the pseudo-code or algorithm to decide which part of the string to draw should be.

Obviously you can't give code because you don't have a clue what I'm doing in my code. That's fine, I don't need code. Just the pseudo code so I know what I should be trying to do is fine.


daaan(Posted 2006) [#2]
Well, think about it this way. If you are using the default font in blitz max each character is 8 pixels wide. So with the width of your given text box space you could only display that last number of characters that fill the space.

I'm drunk. Here is an example.

TextBox Alotted Width: 72 <-- Pixels
TextBox Text : Blitz Max Is The Coolest!
Displayed Text : " Coolest!" <-- 72/8 is 9 characters

I'll give it another shot in the morning.


LarsG(Posted 2006) [#3]
Maybe you need a variable which points to which character the current cursor is at (its position).


Gabriel(Posted 2006) [#4]
So with the width of your given text box space you could only display that last number of characters that fill the space.

That's what I do now. It has problems when the cursor is not in that section of the input.

Maybe you need a variable which points to which character the current cursor is at (its position).


I have one, or I wouldn't have asked how to do it. I'm still not sure exactly what I should be aiming for. Do I want to try to keep the cursor as close to the middle of the inputbox as possible? Do I want to keep it a certain number of characters from the end? A certain number of characters from the beginning? There are a hundred and one variations still.


LarsG(Posted 2006) [#5]
let the cursor have a "working-area" which spans across the entire input box..
when you're writing, the cursor is moving to the right, and if it reaches the right side of the box, then display the text from the end of the text, and x number of characters "backwards" (the x number would most likely be the length of the input box divided by the font width); this is also the "work area" for the cursor.
now if the user is moving the cursor to the left, then check if it reaches the left side of the box.. if it does, then start decreasing the "start" character of the text displayed in the box..

I hope you can understand what I mean from what I wrote, as I found it kind of hard to explain what I'm thinking. hehe

If you don't get it, let me know, and I'll see if I can explain a bit better..