Ecere SDK/eC Forums • View topic - Clearing a float DataField




Ecere SDK/eC Forums

Ecere Developers Community

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.

Clearing a float DataField

Postby shakeshuck » Tue Jan 05, 2016 9:25 am

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. :(
shakeshuck
 
Posts: 31
Joined: Tue Dec 01, 2015 6:52 pm

Re: Clearing a float DataField

Postby jerome » Tue Jan 05, 2016 4:12 pm

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
jerome
Site Admin
 
Posts: 609
Joined: Sat Jan 16, 2010 11:16 pm

Re: Clearing a float DataField

Postby shakeshuck » Tue Jan 05, 2016 6:06 pm

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

Postby shakeshuck » Thu Jan 07, 2016 1:16 pm

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. :(
shakeshuck
 
Posts: 31
Joined: Tue Dec 01, 2015 6:52 pm

Re: Clearing a float DataField

Postby jerome » Thu Jan 07, 2016 11:06 pm

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
jerome
Site Admin
 
Posts: 609
Joined: Sat Jan 16, 2010 11:16 pm


Return to GUI Toolkit & 2D Graphics

Who is online

Users browsing this forum: No registered users and 1 guest

cron