aiaf Posted July 6, 2018 Share Posted July 6, 2018 label_error = Widget::Label(" ", 20, Math::Round(gcon->getContext()->GetWidth() / 9) + 150, 160, 28, gcon->getGui()->GetBase()); label_error->SetText(label_error_connect); How can i clear the text from a label ? After code below i still have the old text printed.SetText draw over the existing text. if (event.source == button_back) { label_error->SetText(""); } And how can i color the label text ? calling SetColor i still have white text Quote I made this with Leadwerks/UAK: Structura | Stacky Desktop Edition Website: Binary Station Link to comment Share on other sites More sharing options...
macklebee Posted July 7, 2018 Share Posted July 7, 2018 I can't say based on the information why your text is not clearing out properly. Maybe you need to redraw the panel or the label? - not enough info to try to recreate but this simple example seems to work: window = Window:Create("Label Example",0,0,400,300,Window.Titlebar + Window.Center) context = Context:Create(window) gui = GUI:Create(context) base = gui:GetBase() base:SetScript("Scripts/GUI/panel.lua") text1 = "Center with border and vertical align" text2 = "" widget = Widget:Label(text1,20,20,300,80,base) widget:SetString("align","Center") widget:SetString("valign","Center") widget:SetBool("border",true) toggle = 0 while not window:KeyHit(Key.Escape) do if window:Closed() then return false end if window:KeyHit(Key.Space) then toggle = 1 - toggle if toggle == 1 then widget:SetText(text2) else widget:SetText(text1) end widget:Redraw() end context:Sync() end As for color - this seems like its a huge class member missing from the Widget class? Not sure why there isn't a way to set the colors of your widgets or text. The label.lua script has no mention of color. The panel.lua script has color being set but its all hardcoded and I haven't been able to change the colors by accessing the apparent color related members. So unless you decide to start rewriting a lot of the scripts, I am not sure you can change the Widget colors inherently - which just seems to be a fairly large omission? Maybe I am missing something. Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
aiaf Posted July 7, 2018 Author Share Posted July 7, 2018 panel = Widget::Panel (20, Math::Round(gcon->getContext()->GetWidth() / 9), 200, 200, gcon->getGui()->GetBase()); label_error = Widget::Label(" ", 20, 20 + 150, 160, 28, panel); If there is a panel drawn the label gets updated.So this change got my issue solved. @Josh maybe can provide us some info on how to set text color in label. Thanks macklebee 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 7, 2018 Share Posted July 7, 2018 to set a label's text color you would need to either edit the default label.lua or create a custom one. here is code for a colorLabel: --Styles if Style==nil then Style={} end if Style.Label==nil then Style.Label={} end Style.Label.Left=0 Style.Label.Center=16 Style.Label.Right=8 Style.Label.VCenter=32 Script.bordercolor = Vec4(0.2,0.2,0.2,1) Script.textcolor = Vec4(0.7,0.7,0.7,1) --[[ Const LABEL_LEFT=0 Const LABEL_FRAME=1 Const LABEL_SUNKENFRAME=2 Const LABEL_SEPARATOR=3 Const LABEL_RIGHT=8 Const LABEL_CENTER=16 ]] function Script:Draw(x,y,width,height) local gui = self.widget:GetGUI() local pos = self.widget:GetPosition(true) local sz = self.widget:GetSize(true) local scale = gui:GetScale() local text = self.widget:GetText() local indent=4 if self.border==true then gui:SetColor(self.bordercolor.r, self.bordercolor.g, self.bordercolor.b, self.bordercolor.a) gui:DrawRect(pos.x,pos.y,sz.width,sz.height,1) end --gui:SetColor(0.7,0.7,0.7) gui:SetColor(self.textcolor.r,self.textcolor.g,self.textcolor.b,self.textcolor.a) if text~="" then local style=0 if self.align=="Left" then style = Text.Left end if self.align=="Center" then style = Text.Center end if self.align=="Right" then style = Text.Right end if self.valign=="Center" then style = style + Text.VCenter end if self.wordwrap==true then style = style + Text.WordWrap end if self.border==true then gui:DrawText(text,pos.x+scale*indent,pos.y+scale*indent,sz.width-scale*indent*2,sz.height-scale*indent*2,style) else gui:DrawText(text,pos.x,pos.y,sz.width,sz.height,style) end end end function Script:bitand(set, flag) return set % (2*flag) >= flag end 2 Quote Link to comment Share on other sites More sharing options...
aiaf Posted July 7, 2018 Author Share Posted July 7, 2018 Thanks for example. Im hoping there will be a way to set label colors from c++ code. 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 7, 2018 Share Posted July 7, 2018 better yet c++ can call functions straight out of the widgetscript. so create a nice widget script set it to your widget and call functions from c++. other than that c++ can do exactly the same as lua can when it comes to widgets. sorry i forgot to add usage for the colorlabel. use the above colorlabel script like this: --create a custom widget colorlabel = Widget:Create("", 100, 100, 250, 12, gui:GetBase(), "Scripts/GUI/ColorLabel.lua") colorlabel:SetObject("textcolor", Vec4(1.0, 0.0, 0.0, 1.0)) Quote 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.