View Single Post
01-11-23, 10:24 AM   #1
Benalish
A Flamescale Wyrmkin
 
Benalish's Avatar
Join Date: Dec 2012
Posts: 123
Adjusting editbox width

Finally I created my combobox template. Only one thing missing: since the dropdown menu width is automatic, how can I make the editbox and the dropdown menu have the same width?

Code:
<Frame name="combobox_template" virtual="true">
	<Size x="1" y="1" />
	<Frames>
		<EditBox name="$parent_flageditbox" parentKey="flageditbox">
			<Size x="75" y="20" />
			<Anchors>
				<Anchor point="LEFT" >
					<Offset>
						<AbsDimension x="27" y="5"/>
					</Offset>
				</Anchor>
			</Anchors>
			<Backdrop bgFile="Interface\Buttons\WHITE8X8" edgeFile="Interface\Tooltips\UI-Tooltip-Border" tile="true">
				<BackgroundInsets>
					<AbsInset left="2" right="2" top="2" bottom="2" />
				</BackgroundInsets>
				<EdgeSize>
					<AbsValue val="10"/>
				</EdgeSize>
			</Backdrop>
			<Scripts>
				<OnLoad>
					self:EnableKeyboard(false)
					self:EnableMouse(false)
					self:SetTextInsets(0,0,-3,0)
					self:SetBackdropColor(0, 0, 0, 0.75)
					self:SetBackdropBorderColor(0.3, 0.3, 0.3, 1)
				</OnLoad>
			</Scripts>
			<FontString justifyH="CENTER" justifyV="TOP" inherits="GameFontNormal"/>
			<Frames>
				<Button name="$parentFlagButton" parentKey="button" enableMouse="true">
					<Size>
						<AbsDimension x="24" y="24"/>
					</Size>
					<Anchors>
						<Anchor point="LEFT" relativeTo="$parent" relativePoint="RIGHT">
							<Offset x="-3" y="0"/>
						</Anchor>
					</Anchors>
					<Scripts>
						<OnMouseDown> flag_dd_OnClick() </OnMouseDown>
					</Scripts>
					<HighlightTexture file="Interface/Buttons/UI-Common-MouseHilight" alphaMode="ADD"/>
					<NormalTexture file="Interface/CHATFRAME/UI-ChatIcon-ScrollDown-Up" setAllPoints="true"/>
					<PushedTexture file="Interface/CHATFRAME/UI-ChatIcon-ScrollDown-Down" setAllPoints="true"/>
				</Button>
			</Frames>
		</EditBox>
		<Frame name="flag_dd" inherits="UIDropDownMenuTemplate" enableMouse="true" hidden="true">
			<Anchors>
				<Anchor point="TOP"/>
			</Anchors>
			<Scripts>
				<OnLoad>
					UIDropDownMenu_Initialize(self, flag_dd_OnLoad, "MENU");
				</OnLoad>
			</Scripts>
		</Frame>
	</Frames>
</Frame>
Lua Code:
  1. CreateFrame("Frame", nil, UIParent, "combobox_template")
  2. main:SetSize(100,25)
  3. main:SetPoint("CENTER")
  4.  
  5. local flags = { "player", "target", "focus", "pet", "mouseover", "arena1", "arena2" }
  6.  
  7. function flag_dd_OnLoad(self)
  8.     for _, flag in ipairs(flags) do
  9.         local info = UIDropDownMenu_CreateInfo()
  10.         info.text = flag
  11.         function info.func(button)
  12.             main.flageditbox:SetText(flag)
  13.         end
  14.         UIDropDownMenu_AddButton(info)
  15.     end
  16.  end
  17.  
  18. function flag_dd_OnClick()
  19.     ToggleDropDownMenu(1, nil, flag_dd, main.flageditbox, 0, 1);
  20. end
  Reply With Quote