aiaf Posted July 8, 2018 Share Posted July 8, 2018 text_field_name->Show(); choice_box_faction_label->Show(); choice_box_faction->Show(); db << "select count(name) from session where name = '" + text_field_name->GetText() + "';" >> user_registered; if (user_registered == 1) { choice_box_faction->Disable(); } I disable a choice box if the user already exist. My problem is that i want to enable the choice_box_faction in case the text_field_name is changed in any way. Need an event (key down or widget selected). Any idea ? Hope i was clear with this description. Quote I made this with Leadwerks/UAK: Structura | Stacky Desktop Edition Website: Binary Station Link to comment Share on other sites More sharing options...
aiaf Posted July 8, 2018 Author Share Posted July 8, 2018 if (event.source == text_field_name) { if (initial_name != text_field_name->GetText()) { choice_box_faction->Enable(); } } I input some text in text_field_name.The event above only triggers on click , anywhere outside text box. Looks like when focus was lost on the textbox. So not exactly what i want , have to do one extra click to change the choice box. Need an event when text was changed first time. Any way to do this ? or maybe im missing some other way of doing Quote I made this with Leadwerks/UAK: Structura | Stacky Desktop Edition Website: Binary Station Link to comment Share on other sites More sharing options...
Solution GorzenDev Posted July 9, 2018 Solution Share Posted July 9, 2018 I'm not at my pc right now but from the top of my head I would say. Open textfield.lua, scroll all the way down and add a widget event call to the keychar or keydown/up method. You will find examples of calling an event inside any widget script. I will add a proper example when I get home. Quote Link to comment Share on other sites More sharing options...
aiaf Posted July 9, 2018 Author Share Posted July 9, 2018 function Script:MouseLeave(x,y) self.hovered = false self.widget:Redraw() EventQueue:Emit(Event.WidgetAction,self.widget) end I added the emit in MouseLeave for TextField.lua. All fine. Figured out how this gui is supposed to work. Thanks Grozen 1 Quote I made this with Leadwerks/UAK: Structura | Stacky Desktop Edition Website: Binary Station Link to comment Share on other sites More sharing options...
GorzenDev Posted July 9, 2018 Share Posted July 9, 2018 we basicly posted at the same time you could use different approaches. either send a widget event whenevver any text is typed into the field by using "Option 1". or send a widget event whenevver the "ENTER" key is pressed "Option 2". (assume the user is done typing) or send an widget event whenevver the "TAB" key is pressed "Option 3". (assume the user wants to switch to the next element in case of a form that needs filling) if a WidgetAction event interferes with other events you could always use WidgetSelect or WidgetMenu events --OPTION 1-- function Script:KeyChar(charcode) local s = self.widget:GetText() local c = String:Chr(charcode) if c=="\b" then --Backspace if String:Length(s)>0 then if self.sellen==0 then if self.caretposition==String:Length(s) then s = String:Left(s,String:Length(s)-1) elseif self.caretposition>0 then s = String:Left(s,self.caretposition-1)..String:Right(s,String:Length(s)-self.caretposition) end self.caretposition = self.caretposition - 1 self.caretposition = math.max(0,self.caretposition) else local c1 = math.min(self.caretposition,self.caretposition+self.sellen) local c2 = math.max(self.caretposition,self.caretposition+self.sellen) s = String:Left(s,c1)..String:Right(s,String:Length(s) - c2) self.caretposition = c1 self.sellen = 0 end self.widget:GetGUI():ResetCursorBlink() self.cursorblinkmode=true self.widget.text = s self.widget:Redraw() end elseif c~="\r" and c~="" then --Insert a new character local c1 = math.min(self.caretposition,self.caretposition+self.sellen) local c2 = math.max(self.caretposition,self.caretposition+self.sellen) s = String:Left(s,c1)..c..String:Right(s,String:Length(s) - c2) self.caretposition = self.caretposition + 1 if self.sellen<0 then self.caretposition = self.caretposition + self.sellen end self.sellen=0 self.widget:GetGUI():ResetCursorBlink() self.cursorblinkmode=true self.widget.text = s self.widget:Redraw() -- --OPTION 1-- --send event with data = 999 EventQueue:Emit(Event.WidgetAction,self.widget,999) end end function Script:KeyUp(keycode) if keycode==Key.Shift then self.shiftpressed=false end -- if keycode==Key.Enter then self.widget:GetGUI():SetFocus(nil) -- --OPTION 2-- --send event with data = 997 EventQueue:Emit(Event.WidgetAction,self.widget,997) elseif keycode==Key.Tab then self.widget:GetGUI():SetFocus(nil) -- --OPTION 3-- --send event with data = 998 EventQueue:Emit(Event.WidgetAction,self.widget,998) end end Quote Link to comment Share on other sites More sharing options...
aiaf Posted July 9, 2018 Author Share Posted July 9, 2018 Its so flexible i come up with a different solution Event data makes sense now. This kind of things should be in a gui manual. 1 3 Quote I made this with Leadwerks/UAK: Structura | Stacky Desktop Edition Website: Binary Station Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.