Hi again,
Is there an isNumeric for strings or something similar? FloatFromString needs some input vetting before it's used.
I can do it by hand, but just thought I'd ask as I would've thought a lot of folk would use it?
If I'm the first then of course I could be wrong...
Numeric check
Re: Numeric check
Hi shakeshuck,
There are some options here.
eC being a C super-set, anything C will work (e.g. strtod(), strtol()).
The current eC way is probably calling OnGetDataFromString() on your numeric type:
This will however return success even if there are further characters after a numeric value.
Use strtol() or strtod() for finer control, which returns a pointer saying where the parsing ended.
You may also want to look into using a SavingDataBox with a data type set to float or double, which will automatically convert to numbers and reject invalid input.
Regards,
-Jerome
There are some options here.
eC being a C super-set, anything C will work (e.g. strtod(), strtol()).
The current eC way is probably calling OnGetDataFromString() on your numeric type:
Code: Select all
float x;
if(a.OnGetDataFromString(string))
PrintLn("Successfully parsed float value: ", x);
Use strtol() or strtod() for finer control, which returns a pointer saying where the parsing ended.
You may also want to look into using a SavingDataBox with a data type set to float or double, which will automatically convert to numbers and reject invalid input.
Regards,
-Jerome
-
- Posts: 31
- Joined: Tue Dec 01, 2015 6:52 pm
Re: Numeric check
The input fields are ListBoxes; I did initially try setting the data type, but then discovered alignment doesn't work if you do.jerome wrote:You may also want to look into using a SavingDataBox with a data type set to float or double, which will automatically convert to numbers and reject invalid input.
(With reference to the other thread on number alignment, in this case I wanted the value centered).
I'll take a look at these, thanks.Use strtol() or strtod() for finer control, which returns a pointer saying where the parsing ended.
Re: Numeric check
If you set the data type to e.g. float for a ListBox field, the data will normally be displayed with the alignment you setup for that field. But only when editing that data, it will be left-aligned.
This could be a work around for now, if you want the editing to be e.g. right-aligned as well.
However, this requires a tweak in DataBox.ec, otherwise the DataBox will currently unset that autoSize property if autoSize is not set on the DataBox itself (and auto-size DataBox don't work well with the ListBox):
This is the line in the source:
https://github.com/ecere/ecere-sdk/blob ... ox.ec#L132
Then this should work:
This could be a work around for now, if you want the editing to be e.g. right-aligned as well.
Code: Select all
class MyFloat : float
{
Window OnEdit(DataBox dataBox, DataBox obsolete, int x, int y, int w, int h, void * userData)
{
EditBox editor = (EditBox)class::OnEdit(dataBox, obsolete, x, y, w, h, userData);
editor.anchor = { top = 2, right = -4 };
editor.autoSize = true;
editor.OnPostCreate();
return editor;
}
}
Code: Select all
if(autoSize) // Need to add this if check
((EditBox)editor).autoSize = autoSize;
https://github.com/ecere/ecere-sdk/blob ... ox.ec#L132
Then this should work:
Code: Select all
DataField fld3 { dataType = class(MyFloat), alignment = right, width = 120, editable = true };
-
- Posts: 31
- Joined: Tue Dec 01, 2015 6:52 pm
Re: Numeric check
That's what I thought, but it isn't doing that for me; with alignment set to center, centering (at display time) is not occurring if I change the dataType to int or float.jerome wrote:If you set the data type to e.g. float for a ListBox field, the data will normally be displayed with the alignment you setup for that field. But only when editing that data, it will be left-aligned.
Of course it's highly possible I've unset something somewhere else that's causing this to happen...
Re: Numeric check
Please post some sample code to compare.
If you follow my example above it should work.
(But you will need the custom type and the libecere tweak to get the 'edited' data box to follow the alignment as well)
If you follow my example above it should work.
(But you will need the custom type and the libecere tweak to get the 'edited' data box to follow the alignment as well)
-
- Posts: 31
- Joined: Tue Dec 01, 2015 6:52 pm
Re: Numeric check
Video sent, using same MakeActive sample as before...
Cheers.
Cheers.
Re: Numeric check
Hi shakeshuck,
I see what you mean.
What happens is that the data types have a 'default alignment', and setting the dataType property after the alignment will set it to that default alignment. If you change the code to set the alignment after the dataType it will work again.
Regards,
Jerome
I see what you mean.
What happens is that the data types have a 'default alignment', and setting the dataType property after the alignment will set it to that default alignment. If you change the code to set the alignment after the dataType it will work again.
Regards,
Jerome