Thread Tools Display Modes
09-10-14, 06:18 AM   #1
Benalish
A Flamescale Wyrmkin
 
Benalish's Avatar
Join Date: Dec 2012
Posts: 123
Editbox under slider

Hi. Can I create a slider like this, with the yellow title at the top and the editbox bottom without ace libraries ? If so, how should I proceed?
  Reply With Quote
09-10-14, 06:43 AM   #2
mikma
A Cyclonian
 
mikma's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2005
Posts: 45
Yeah sure. Just create a slider first and after that editbox under it.
Combine:

local slider = CreateFrame("Slider", "MySlider", nil, "OptionsSliderTemplate")
slider:SetWidth(144)
slider:SetHeight(17)
slider:SetOrientation("HORIZONTAL")
slider:SetThumbTexture("Interface\\Buttons\\UI-SliderBar-Button-Horizontal")
slider:SetMinMaxValues(1,100)
slider:SetValueStep(1)
slider:SetValue(1)

slider.tooltipText = 'Set the size of the note'
getglobal(slider:GetName() .. 'Low'):SetText('Left')
getglobal(slider:GetName() .. 'High'):SetText('Right')
getglobal(slider:GetName() .. 'Text'):SetText('Text!')
slider:SetScript("OnValueChanged", function(self, newvalue)
UpdateMySlider()
end)

and

local editbox = CreateFrame("EditBox", "MyEditBox", nil)
editbox:SetPoint("TOP")
editbox:SetPoint("LEFT")
editbox:SetPoint("RIGHT")
editbox:SetHeight(100)
editbox:SetFontObject(GameFontHighlightSmall)
editbox:SetTextInsets(2,2,2,2)
editbox:SetMultiLine(false)
editbox:SetAutoFocus(true)
editbox:SetScript("OnEscapePressed", function()
editbox:ClearFocus()
end)
editbox:SetScript("OnEditFocusLost", function(self) editbox:ClearFocus() end)
editbox:SetScript("OnShow", function(self)
self:SetText("")
self:SetFocus()
end)

Tweak and tune the rest.
  Reply With Quote
09-10-14, 08:49 AM   #3
Benalish
A Flamescale Wyrmkin
 
Benalish's Avatar
Join Date: Dec 2012
Posts: 123
As I build four similar slider in xml, there is a container (frame?) where put everything inside to be used as a model to inherit?
  Reply With Quote
09-10-14, 10:05 AM   #4
Duugu
Premium Member
 
Duugu's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 851
Create a new <frame> tag, add the virtual attribute, and place your stuff into <Frames></Frames> within the new frame.
Then use the new frame to inherit from.
  Reply With Quote
09-10-14, 10:18 AM   #5
Benalish
A Flamescale Wyrmkin
 
Benalish's Avatar
Join Date: Dec 2012
Posts: 123
The editbox beneath the slider in ace3 libraries what inherits? I would reproduce the same smooth frame , but I have no idea how to do it
  Reply With Quote
09-10-14, 10:41 AM   #6
Duugu
Premium Member
 
Duugu's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 851
It doesn't inherits from something. They build those widgets from a scratch:

Lua Code:
  1. local frame = CreateFrame("Frame", nil, UIParent)
  2.  
  3.     frame:EnableMouse(true)
  4.     frame:SetScript("OnMouseDown", Frame_OnMouseDown)
  5.  
  6.     local label = frame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
  7.     label:SetPoint("TOPLEFT")
  8.     label:SetPoint("TOPRIGHT")
  9.     label:SetJustifyH("CENTER")
  10.     label:SetHeight(15)
  11.  
  12.     local slider = CreateFrame("Slider", nil, frame)
  13.     slider:SetOrientation("HORIZONTAL")
  14.     slider:SetHeight(15)
  15.     slider:SetHitRectInsets(0, 0, -10, 0)
  16.     slider:SetBackdrop(SliderBackdrop)
  17.     slider:SetThumbTexture("Interface\\Buttons\\UI-SliderBar-Button-Horizontal")
  18.     slider:SetPoint("TOP", label, "BOTTOM")
  19.     slider:SetPoint("LEFT", 3, 0)
  20.     slider:SetPoint("RIGHT", -3, 0)
  21.     slider:SetValue(0)
  22.     slider:SetScript("OnValueChanged",Slider_OnValueChanged)
  23.     slider:SetScript("OnEnter", Control_OnEnter)
  24.     slider:SetScript("OnLeave", Control_OnLeave)
  25.     slider:SetScript("OnMouseUp", Slider_OnMouseUp)
  26.     slider:SetScript("OnMouseWheel", Slider_OnMouseWheel)
  27.  
  28.     local lowtext = slider:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
  29.     lowtext:SetPoint("TOPLEFT", slider, "BOTTOMLEFT", 2, 3)
  30.  
  31.     local hightext = slider:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
  32.     hightext:SetPoint("TOPRIGHT", slider, "BOTTOMRIGHT", -2, 3)
  33.  
  34.     local editbox = CreateFrame("EditBox", nil, frame)
  35.     editbox:SetAutoFocus(false)
  36.     editbox:SetFontObject(GameFontHighlightSmall)
  37.     editbox:SetPoint("TOP", slider, "BOTTOM")
  38.     editbox:SetHeight(14)
  39.     editbox:SetWidth(70)
  40.     editbox:SetJustifyH("CENTER")
  41.     editbox:EnableMouse(true)
  42.     editbox:SetBackdrop(ManualBackdrop)
  43.     editbox:SetBackdropColor(0, 0, 0, 0.5)
  44.     editbox:SetBackdropBorderColor(0.3, 0.3, 0.30, 0.80)
  45.     editbox:SetScript("OnEnter", EditBox_OnEnter)
  46.     editbox:SetScript("OnLeave", EditBox_OnLeave)
  47.     editbox:SetScript("OnEnterPressed", EditBox_OnEnterPressed)
  48.     editbox:SetScript("OnEscapePressed", EditBox_OnEscapePressed)
  Reply With Quote
09-10-14, 12:33 PM   #7
Benalish
A Flamescale Wyrmkin
 
Benalish's Avatar
Join Date: Dec 2012
Posts: 123
In XML

Code:
...
<EditBox name="editbox" parent="frame">						
	<Scripts>
		<OnLoad>
			editbox:SetAutoFocus(false)
                        editbox:SetFontObject(GameFontHighlightSmall)
                        editbox:SetPoint("TOP", slider, "BOTTOM")
                        editbox:SetHeight(14)
                        editbox:SetWidth(70)
                        editbox:SetJustifyH("CENTER")
                        editbox:EnableMouse(true)
                        editbox:SetBackdrop(ManualBackdrop)
                        editbox:SetBackdropColor(0, 0, 0, 0.5)
                        editbox:SetBackdropBorderColor(0.3, 0.3, 0.30, 0.80)				
		</OnLoad>
	</Scripts>
</EditBox>
...
Works evertything but SetBackdropColor and SetBackdropBorderColor

Last edited by Benalish : 09-10-14 at 12:38 PM.
  Reply With Quote
09-10-14, 01:34 PM   #8
p3lim
A Pyroguard Emberseer
 
p3lim's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 1,710
Why in gods name are you using xml?
Also, you're creating a global called "editbox", that will definitely create some issues!
  Reply With Quote
09-10-14, 01:54 PM   #9
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
If you really want to use XML (probably because you hate kittens, yourself, life, and the universe in general) then you should be aware that all of your OnLoad, OnEvent, etc. scripts receive the same arguments that those script receive when you define them in Lua. The first argument is always a variable named "self" that refers to the frame. So, you do not need to use your frame's global name inside the script. Just use "self" to refer to it.

But really, don't use XML. It's horrible.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
09-11-14, 04:41 AM   #10
Benalish
A Flamescale Wyrmkin
 
Benalish's Avatar
Join Date: Dec 2012
Posts: 123
Could you at least tell me what is the equivalent of SetBackdropBorderColor in XML?
  Reply With Quote
09-11-14, 05:31 AM   #11
Lombra
A Molten Giant
 
Lombra's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 554
Code:
editbox:SetBackdrop(ManualBackdrop)
ManualBackdrop is not defined anywhere, so setting the colors won't have any visible effect. You'll want to do something like this:
Code:
editbox:SetBackdrop({
	bgFile = [[Interface\Buttons\WHITE8X8]],
	edgeFile = [[Interface\Buttons\WHITE8X8]],
	edgeSize = 1,
})
Also, if you're using "XML" solely for the OnLoad script, that's completely pointless as that's still Lua code. Just have everything in the Lua file for sanity!
__________________
Grab your sword and fight the Horde!
  Reply With Quote
09-11-14, 05:51 AM   #12
Benalish
A Flamescale Wyrmkin
 
Benalish's Avatar
Join Date: Dec 2012
Posts: 123
If I want solid color instead of texture?
  Reply With Quote
09-11-14, 06:03 AM   #13
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Originally Posted by Benalish View Post
If I want solid color instead of texture?
Just color the white texture with:

Lua Code:
  1. frame:SetBackdropColor(0, 0, 0, 1) -- r, b, g, a

I personally use this for normal EditBoxes, you can remove the title and resize it for sliders if you want:

Lua Code:
  1. function EditBox:CreateEditBox(parent)
  2.     local frame = CreateFrame("EditBox", nil, parent)
  3.     frame:SetWidth(200)
  4.     frame:SetHeight(26)
  5.     frame:SetJustifyH("Left")
  6.     frame:SetAutoFocus(false)
  7.     frame:SetFontObject(GameFontHighlight)
  8.     frame:SetTextInsets(4, 4, 2, 2)
  9.     frame:SetHitRectInsets(0, 0, 0, 0)
  10.     frame:SetBackdrop({
  11.         bgFile = [[Interface\Buttons\White8X8]],
  12.         edgeFile = [[Interface\Tooltips\UI-Tooltip-Border]],
  13.         tile = true,
  14.         tileSize = 16,
  15.         edgeSize = 14,
  16.         insets = {left = 2, right = 2, top = 2, bottom = 2}
  17.     })
  18.     frame:SetBackdropColor(0, 0, 0, 0.75)
  19.     frame:SetBackdropBorderColor(0.3, 0.3, 0.3, 1.0)
  20.     frame.Title = frame:CreateFontString(nil, "Overlay")
  21.     frame.Title:SetFontObject(GameFontNormal)
  22.     frame.Title:SetJustifyH("Left")
  23.     frame.Title:SetJustifyV("Middle")
  24.     frame.Title:SetWordWrap(false)
  25.     frame.Title:SetSize(1, 20)
  26.     frame.Title:SetPoint("BottomLeft", frame, "TopLeft", 3, 0)
  27.     frame.Title:SetPoint("BottomRight", frame, "TopRight", -3, 0)
  28.     frame.Title:SetText("EditBox")
  29.     frame:SetScript("OnEnter", function(self)
  30.         self:SetBackdropBorderColor(0.5, 0.5, 0.5, 1.0)
  31.     end)
  32.     frame:SetScript("OnLeave", function(self)
  33.         self:SetBackdropBorderColor(0.3, 0.3, 0.3, 1.0)
  34.     end)
  35.     frame:SetScript("OnEscapePressed", function(self)
  36.         self:ClearFocus()
  37.     end)
  38.     frame:SetScript("OnEnterPressed", function(self)
  39.         self:ClearFocus()
  40.     end)
  41.     frame:SetScript("OnEditFocusLost", function(self)
  42.         self:HighlightText(0, 0)
  43.     end)
  44.     frame:SetScript("OnEditFocusGained", function(self)
  45.         self:HighlightText(0, -1)
  46.     end)
  47.     return frame
  48. end

Last edited by Resike : 09-11-14 at 06:13 AM.
  Reply With Quote
09-11-14, 06:29 AM   #14
Lombra
A Molten Giant
 
Lombra's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 554
Originally Posted by Benalish View Post
If I want solid color instead of texture?
When it comes to backdrops, you have to provide a real texture (eg, a file). The texture I provided is a solid white texture, so it effectively works as a simple, solid color.
__________________
Grab your sword and fight the Horde!
  Reply With Quote
09-11-14, 07:37 PM   #15
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Your other option for a solid background would be to use a simple texture instead of a "real" backdrop. This would create a 50% opaque red background:

Code:
local bg = frame:CreateTexture(nil, "BACKGROUND") -- does not need a global name
bg:SetAllPoints(true) -- if you want it inset or outside, set explicit points
bg:SetTexture(1, 0, 0, 0.5) -- you can pass colors instead of a texture if you just want a solid color
frame.bg = bg -- so it's easy to access later from other scopes
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
09-11-14, 08:18 PM   #16
Benalish
A Flamescale Wyrmkin
 
Benalish's Avatar
Join Date: Dec 2012
Posts: 123
From this page: "Backdrops are deprecated in favour of the new tiling mechanisms". What it the new tiling mechanism?
  Reply With Quote
09-11-14, 11:45 PM   #17
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Backdrops weren't deprecated after all (they're still widely used in the default UI, and work just as they always have) but the "tiling mechanism" is the ability for textures to be tiled. Let's say you have a frame that's 400px square, and a texture file that's 100px square.

Code:
local tex = frame:CreateTexture(nil, "BACKGROUND")
tex:SetAllPoints()
tex:SetTexture("Path//To//The//Texture")
At this point the texture is stretched to 400% so that it covers the whole frame.

Code:
tex:SetHorizTile(true)
Now the texture will tile (repeat) horizontally, so you'll end up with 4 visual copies of the texture, side by side, each 100px wide, but still stretched to 400px height.

Code:
tex:SetVertTile(true)
Now the texture will tile in both directions, so you now have 16 visual copies of the texture in a 4x4 grid, each 100px square.

There's no way to control the tile size; it will always use the real pixel dimensions of the source file.

The idea was that Blizzard was going to use this, plus a series of individual textures to make up the border, and they do use this system on some newer things like the battle pet tooltip, but backdrops are still a thing.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
09-12-14, 09:37 AM   #18
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Since i'm pretty sure i'll need this in the future here is a lua only fancy slider, it's pretty basic yet but still much better then the blizzard ones.

Lua Code:
  1. local function CreateSlider(parent)
  2.     local frame = CreateFrame("Slider", nil, parent)
  3.     frame:SetSize(200, 17)
  4.     frame:EnableMouseWheel(true)
  5.     frame:SetHitRectInsets(0, 0, -14, -15)
  6.     frame:SetMinMaxValues(0, 100)
  7.     frame:SetValue(50)
  8.     frame:SetValueStep(1)
  9.     frame:SetHitRectInsets(0, 0, 0, 0)
  10.     frame:SetObeyStepOnDrag(true)
  11.     frame:EnableMouseWheel(true)
  12.     frame:SetOrientation("Horizontal")
  13.     frame:SetBackdrop({
  14.         bgFile = "Interface\\Buttons\\UI-SliderBar-Background",
  15.         edgeFile = "Interface\\Buttons\\UI-SliderBar-Border",
  16.         tile = true,
  17.         edgeSize = 8,
  18.         tileSize = 8,
  19.         insets = {left = 3, right = 3, top = 6, bottom = 6}
  20.     })
  21.     frame:SetBackdropBorderColor(0.7, 0.7, 0.7, 1.0)
  22.     frame:SetScript("OnEnter", function(self)
  23.         self:SetBackdropBorderColor(1, 1, 1, 1)
  24.     end)
  25.     frame:SetScript("OnLeave", function(self)
  26.         self:SetBackdropBorderColor(0.7, 0.7, 0.7, 1.0)
  27.     end)
  28.     frame:SetScript("OnMouseWheel", function(self, delta)
  29.         if delta > 0 then
  30.             self:SetValue(self:GetValue() + self:GetValueStep())
  31.         else
  32.             self:SetValue(self:GetValue() - self:GetValueStep())
  33.         end
  34.     end)
  35.     frame:SetScript("OnValueChanged", function(self, value)
  36.         frame.EditBox:SetText(value)
  37.     end)
  38.     frame.MinLabel = frame:CreateFontString(nil, "Overlay")
  39.     frame.MinLabel:SetFontObject(GameFontHighlightSmall)
  40.     frame.MinLabel:SetSize(0, 14)
  41.     frame.MinLabel:SetWordWrap(false)
  42.     frame.MinLabel:SetPoint("TopLeft", frame, "BottomLeft", 0, -1)
  43.     local min, max = frame:GetMinMaxValues()
  44.     frame.MinLabel:SetText(min)
  45.     frame.MaxLabel = frame:CreateFontString(nil, "Overlay")
  46.     frame.MaxLabel:SetFontObject(GameFontHighlightSmall)
  47.     frame.MaxLabel:SetSize(0, 14)
  48.     frame.MaxLabel:SetWordWrap(false)
  49.     frame.MaxLabel:SetPoint("TopRight", frame, "BottomRight", 0, -1)
  50.     frame.MaxLabel:SetText(max)
  51.     frame.Title = frame:CreateFontString(nil, "Overlay")
  52.     frame.Title:SetFontObject(GameFontNormal)
  53.     frame.Title:SetSize(0, 14)
  54.     frame.Title:SetWordWrap(false)
  55.     frame.Title:SetPoint("Bottom", frame, "Top")
  56.     frame.Title:SetText("Slider")
  57.     frame.Thumb = frame:CreateTexture(nil, "Artwork")
  58.     frame.Thumb:SetSize(32, 32)
  59.     frame.Thumb:SetTexture("Interface\\Buttons\\UI-SliderBar-Button-Horizontal")
  60.     frame:SetThumbTexture(frame.Thumb)
  61.     frame.EditBox = CreateFrame("EditBox", nil, frame)
  62.     frame.EditBox:EnableMouseWheel(true)
  63.     frame.EditBox:SetAutoFocus(false)
  64.     frame.EditBox:SetNumeric(false)
  65.     frame.EditBox:SetJustifyH("Center")
  66.     frame.EditBox:SetFontObject(GameFontHighlightSmall)
  67.     frame.EditBox:SetSize(50, 14)
  68.     frame.EditBox:SetPoint("Top", frame, "Bottom", 0, -1)
  69.     frame.EditBox:SetTextInsets(4, 4, 0, 0)
  70.     frame.EditBox:SetBackdrop({
  71.         bgFile = "Interface\\ChatFrame\\ChatFrameBackground",
  72.         edgeFile = "Interface\\ChatFrame\\ChatFrameBackground",
  73.         tile = true,
  74.         edgeSize = 1,
  75.         tileSize = 5
  76.     })
  77.     frame.EditBox:SetBackdropColor(0, 0, 0, 1)
  78.     frame.EditBox:SetBackdropBorderColor(0.2, 0.2, 0.2, 1.0)
  79.     frame.EditBox:SetText(frame:GetValue())
  80.     --[[frame.EditBox:SetScript("OnShow", function(self)
  81.         self:SetText("")
  82.         self:SetText(frame:GetValue())
  83.     end)]]
  84.     if InterfaceOptionsFrame then
  85.         InterfaceOptionsFrame:HookScript("OnShow", function(self)
  86.             frame.EditBox:SetText("")
  87.             frame.EditBox:SetText(frame:GetValue())
  88.         end)
  89.     end
  90.     frame.EditBox:SetScript("OnEnter", function(self)
  91.         self:SetBackdropBorderColor(0.4, 0.4, 0.4, 1.0)
  92.     end)
  93.     frame.EditBox:SetScript("OnLeave", function(self)
  94.         self:SetBackdropBorderColor(0.2, 0.2, 0.2, 1.0)
  95.     end)
  96.     frame.EditBox:SetScript("OnMouseWheel", function(self, delta)
  97.         if delta > 0 then
  98.             frame:SetValue(frame:GetValue() + frame:GetValueStep())
  99.         else
  100.             frame:SetValue(frame:GetValue() - frame:GetValueStep())
  101.         end
  102.     end)
  103.     frame.EditBox:SetScript("OnEscapePressed", function(self)
  104.         self:ClearFocus()
  105.     end)
  106.     frame.EditBox:SetScript("OnEnterPressed", function(self)
  107.         local value = tonumber(self:GetText())
  108.         if value then
  109.             local min, max = frame:GetMinMaxValues()
  110.             if value >= min and value <= max then
  111.                 frame:SetValue(value)
  112.             elseif value < min then
  113.                 frame:SetValue(min)
  114.             elseif value > max then
  115.                 frame:SetValue(max)
  116.             end
  117.             frame.EditBox:SetText(frame:GetValue())
  118.         else
  119.             frame:SetValue(frame:GetValue())
  120.         end
  121.         self:ClearFocus()
  122.     end)
  123.     frame.EditBox:SetScript("OnEditFocusLost", function(self)
  124.         self:HighlightText(0, 0)
  125.     end)
  126.     frame.EditBox:SetScript("OnEditFocusGained", function(self)
  127.         self:HighlightText(0, -1)
  128.     end)
  129.     frame.Plus = CreateFrame("Button", nil, frame)
  130.     frame.Plus:SetSize(18, 18)
  131.     frame.Plus:RegisterForClicks("AnyUp")
  132.     frame.Plus:SetPoint("Left", frame.EditBox, "Right", 0, 0)
  133.     frame.Plus:SetNormalTexture("Interface\\Buttons\\UI-SpellbookIcon-NextPage-Up")
  134.     frame.Plus:SetPushedTexture("Interface\\Buttons\\UI-SpellbookIcon-NextPage-Down")
  135.     frame.Plus:SetHighlightTexture("Interface\\ChatFrame\\UI-ChatIcon-BlinkHilight")
  136.     frame.Plus:SetScript("OnClick", function(self)
  137.         frame:SetValue(frame:GetValue() + frame:GetValueStep())
  138.     end)
  139.     frame.Minus = CreateFrame("Button", nil, frame)
  140.     frame.Minus:SetSize(18, 18)
  141.     frame.Minus:RegisterForClicks("AnyUp")
  142.     frame.Minus:SetPoint("Right", frame.EditBox, "Left", 0, 0)
  143.     frame.Minus:SetNormalTexture("Interface\\Buttons\\UI-SpellbookIcon-PrevPage-Up")
  144.     frame.Minus:SetPushedTexture("Interface\\Buttons\\UI-SpellbookIcon-PrevPage-Down")
  145.     frame.Minus:SetHighlightTexture("Interface\\ChatFrame\\UI-ChatIcon-BlinkHilight")
  146.     frame.Minus:SetScript("OnClick", function(self)
  147.         frame:SetValue(frame:GetValue() - frame:GetValueStep())
  148.     end)
  149.     return frame
  150. end

Last edited by Resike : 09-12-14 at 09:52 AM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Editbox under slider

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off