Clearing a float DataField

General help with the Ecere Cross Platform GUI toolkit: Window, common controls, events, etc.
Help with the 2D Graphics library: Surface, Display, Bitmap, Font and others.
Post Reply
shakeshuck
Posts: 31
Joined: Tue Dec 01, 2015 6:52 pm

Clearing a float DataField

Post by shakeshuck »

Happy new year all. :D

Unfortunately I'm back with another query...!

I have a DataField in a ListBox with type float.
It initially displays with no value (which is how I want it). After a value has been added, however, there does not seem to be a way to accept user input to clear the field again (empty is valid in this case). Typing in a space or using backspace to clear the field are both considered invalid. :(
jerome
Site Admin
Posts: 608
Joined: Sat Jan 16, 2010 11:16 pm

Re: Clearing a float DataField

Post by jerome »

Happy New Year Shakeshuck!

We're always glad to see you back with queries!

You're right that there is no built-in way to clear a ListBox data cell after it is set.

There is however a method, UnsetData() to do just that.
It was suffering from a bug however, for which I just pushed a fix:

https://github.com/ecere/ecere-sdk/comm ... ef5fc94190

You can then write your own code to add a way to clear a data cell, here is one example of mapping Ctrl-Q to do so:

Code: Select all

   ListBox listBox1
   {
      this, caption = $"listBox1", size = { 320, 164 }, position = { 120, 56 }, hasHeader = true, alwaysEdit = true, selectionColor = { r = 240, g = 240, b = 240 }, black;
 
      bool OnKeyHit(Key key, unichar ch)
      {
         if(key == ctrlQ)
         {
            DataField fld = currentField;
            currentRow.UnsetData(fld);
            currentRow.Edit(null); // Must re-trigger edition so that the DataBox updates with the new value
            currentRow.Edit(fld);
            return false;
         }
         return ListBox::OnKeyHit(key, ch);
      }
   };
You could also do something like a right-click context menu with a 'Clear' option, as we did in the IDE project settings:

https://github.com/ecere/ecere-sdk/blob ... gs.ec#L305

Hope this helps.

-Jerome
shakeshuck
Posts: 31
Joined: Tue Dec 01, 2015 6:52 pm

Re: Clearing a float DataField

Post by shakeshuck »

Hi Jerome,

Instead of getting the user to do something "extra", I thought I'd see what happens during editing, so I set NotifyEdited on the ListBox to see what it showed.

NotifyEdited gets called as soon as a number is hit, but trying to read the input using

Code: Select all

listBox.GetData(listBox.currentField)
gives me a segfault. Is this because currentField isn't set until the editing is finished?
shakeshuck
Posts: 31
Joined: Tue Dec 01, 2015 6:52 pm

Re: Clearing a float DataField

Post by shakeshuck »

After poking around a bit more, it seems the segfault was caused by casting the GetData request to float (the DataField was float).
Using String instead does not cause a failure, but the contents of the String are always either null or empty, regardless of what was entered in the field. :(
jerome
Site Admin
Posts: 608
Joined: Sat Jan 16, 2010 11:16 pm

Re: Clearing a float DataField

Post by jerome »

Hi Shakeshuck,

Sorry for the late reply.
The data internally is stored as a float when using a float data type.
However the ListBox doesn't really provide a proper public API to query unset cells.
In fact, assigning the result of a GetData() to a float will crash on a cell with an unset float value.

Something which does happen to work at the moment however is the following:

Code: Select all

float * f = currentRow.GetData(fld);
You can then check whether f is null, and de-reference it if it is non-null to access the float value.

This will not help address the fact that the user would still need to specifically 'clear' the cell, as there is still no built-in mechanism to 'unset' the value. If the user deletes the whole contents of the edit box and try to save, it will leave the previous value in the ListBox cell.

We certainly need to improve on the usability of unset data cells.

Regards,

-Jerome
Post Reply