www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - DlangUI EditLine question

reply "Kyle" <blah blah.blah> writes:
I have a variable, x, which I want to update when the content of 
a DlangUI EditLine is modified. I tried making this work with the 
"onContentChange" method listed in the API documentation, but dmd 
told me it's not there. I've got this working now by implementing 
a custom subclass of EditLine as below:


class XEditLine : EditLine
{
     this(string ID, dstring initialContent = null)
     {
         super(ID, initialContent);
     }

     override bool onKeyEvent(KeyEvent e)
     {
         super.onKeyEvent(e);
         x = to!double(this.text);
         return true;
     }
}


This works but it seems like there should be a cleaner way to do 
this, any suggestions? Thanks.
Mar 15 2015
parent reply "Vadim Lopatin" <coolreader.org gmail.com> writes:
On Sunday, 15 March 2015 at 16:21:21 UTC, Kyle wrote:
 I have a variable, x, which I want to update when the content 
 of a DlangUI EditLine is modified. I tried making this work 
 with the "onContentChange" method listed in the API 
 documentation, but dmd told me it's not there. I've got this 
 working now by implementing a custom subclass of EditLine as 
 below:


 class XEditLine : EditLine
 {
     this(string ID, dstring initialContent = null)
     {
         super(ID, initialContent);
     }

     override bool onKeyEvent(KeyEvent e)
     {
         super.onKeyEvent(e);
         x = to!double(this.text);
         return true;
     }
 }


 This works but it seems like there should be a cleaner way to 
 do this, any suggestions? Thanks.
You can either override onContentChange or use onContentChangeListener override void onContentChange(EditableContent content, EditOperation operation, ref TextRange rangeBefore, ref TextRange rangeAfter, Object source) { super.onContentChange(content, operation, rangeBefore, rangeAfter, source); // do something x = to!double(this.text); } or EditLine line = new EditLine(); line.onContentChangeListener = delegate(EditableContent) { // do something x = to!double(line.text); }
 of a DlangUI EditLine is modified. I tried making this work 
 with the "onContentChange" method listed in the API 
 documentation, but dmd told me it's not there. I've got this
If you don't see onContentChange method, probably you have older version of DlangUI. Try dub upgrade --force-remove
Mar 16 2015
parent "Kyle" <blah blah.blah> writes:
Thanks! I'll try this out after I get home.
Mar 16 2015