Combobox Parent Width
#92
This allows you to set the width of a comboox to match the parent size.
This then lets you set the combo box for all the configs in the bot to have a scroll bar and width match the parent to see longer names
This then lets you set the combo box for all the configs in the bot to have a scroll bar and width match the parent to see longer names
function UIComboBox.create()
local combobox = UIComboBox.internalCreate()
combobox:setFocusable(false)
combobox.options = {}
combobox.currentIndex = -1
combobox.mouseScroll = true
combobox.menuScroll = false
combobox.menuHeight = 100
combobox.menuScrollStep = 0
+ combobox.parentWidth = false
+ combobox.removeMargin = false
return combobox
end
- remove | + add
function UIComboBox:onMousePress(mousePos, mouseButton)
local menu
if self.menuScroll then
menu = g_ui.createWidget(self:getStyleName() .. 'PopupScrollMenu')
menu:setHeight(self.menuHeight)
if self.menuScrollStep > 0 then
menu:setScrollbarStep(self.menuScrollStep)
end
else
menu = g_ui.createWidget(self:getStyleName() .. 'PopupMenu')
end
menu:setId(self:getId() .. 'PopupMenu')
for i,v in ipairs(self.options) do
menu:addOption(v.text, function() self:setCurrentOption(v.text) end)
end
+ if self.parentWidth and self:getParent() then
+ local par = self:getParent()
+ menu:setWidth(par:getWidth() - (self.removeMargin and (par:getMarginLeft() - par:getMarginRight()) or 4))
+ else
+ menu:setWidth(self:getWidth())
+ end
- menu:setWidth(self:getWidth())
menu:display({ x = self:getX(), y = self:getY() + 2 + self:getHeight() })
connect(menu, { onDestroy = function() self:setOn(false) end })
self:setOn(true)
return true
end
- remove | + add
MiniWindowContents
ComboBox
id: config
+ &menuScroll: true
+ &menuHeight: 450
+ &menuScrollStep: 100
+ &parentWidth: true
+ &removeMargin: true
anchors.top: parent.top
anchors.left: parent.left
anchors.right: parent.right
margin-top: 2
margin-left: 2
margin-right: 75
text-offset: 3 0
- remove | + add
ComboBox
id: list
anchors.top: parent.top
anchors.left: parent.left
text-offset: 3 0
width: 130
+ &menuScroll: true
+ &menuHeight: 450
+ &menuScrollStep: 100
+ &parentWidth: true
- remove | + add
25 Apr 2022