auto resize menu width

master
Eduardo Bart 13 years ago
parent b8150d160e
commit 1c4bbfb7f3

@ -36,4 +36,9 @@ cache into framebuffers
implement glbuffer for CoordsBuffer
use indices in CoordsBuffer
create a Timer class
move UICheckBox to lua
move UIWindow to lua
rework UI image style
class UIImage and UIText
add UI border
fix style inheretance using a style translator

@ -47,7 +47,17 @@ end
function createWidget(style, parent)
local className = g_ui.getStyleClass(style)
if className == "" then
error('could not find style ' .. style)
return
end
local class = _G[className]
if not class then
error('could not find widget class ' .. class)
return
end
local widget = class.create()
if parent then
parent:addChild(widget)

@ -15,6 +15,6 @@ Module
importStyle 'styles/listboxes.otui'
importStyle 'styles/items.otui'
importStyle 'styles/creatures.otui'
importStyle 'styles/comboboxes.otui'
importStyle 'styles/popupmenus.otui'
importStyle 'styles/comboboxes.otui'
return true

@ -1,3 +1,7 @@
ComboBoxPopupMenuSeparator < PopupMenuSeparator
ComboBoxPopupMenuButton < PopupMenuButton
ComboBoxPopupMenu < PopupMenu
ComboBox < UIComboBox
font: verdana-11px-antialised
color: #aaaaaa

@ -34,7 +34,7 @@ PopupMenuSeparator < UIWidget
phantom: true
PopupMenu < UIPopupMenu
width: 100
width: 50
border-image:
source: /core_styles/images/menubox.png
border: 3

@ -27,7 +27,7 @@ function UIComboBox:addOption(text, data)
end
function UIComboBox:onMousePress(mousePos, mouseButton)
local menu = createWidget('PopupMenu', self)
local menu = createWidget(self:getStyleName() .. 'PopupMenu', self)
for i,v in ipairs(self.options) do
menu:addOption(v.text, function() self:setCurrentOption(v.text) end)
end

@ -23,6 +23,8 @@ function UIPopupMenu:addOption(optionName, optionCallback)
self:destroy()
end
optionWidget:setText(optionName)
local width = optionWidget:getTextSize().width + optionWidget:getMarginLeft() + optionWidget:getMarginRight() + 6
self:setWidth(math.max(self:getWidth(), width))
end
function UIPopupMenu:addSeparator()

Loading…
Cancel
Save