auto resize menu width
This commit is contained in:
		
							parent
							
								
									b8150d160e
								
							
						
					
					
						commit
						1c4bbfb7f3
					
				
							
								
								
									
										7
									
								
								TODO
								
								
								
								
							
							
						
						
									
										7
									
								
								TODO
								
								
								
								
							| 
						 | 
					@ -36,4 +36,9 @@ cache into framebuffers
 | 
				
			||||||
implement glbuffer for CoordsBuffer
 | 
					implement glbuffer for CoordsBuffer
 | 
				
			||||||
use indices in 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)
 | 
					function createWidget(style, parent)
 | 
				
			||||||
  local className = g_ui.getStyleClass(style)
 | 
					  local className = g_ui.getStyleClass(style)
 | 
				
			||||||
 | 
					  if className == "" then
 | 
				
			||||||
 | 
					    error('could not find style ' .. style)
 | 
				
			||||||
 | 
					    return
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  local class = _G[className]
 | 
					  local class = _G[className]
 | 
				
			||||||
 | 
					  if not class then
 | 
				
			||||||
 | 
					    error('could not find widget class ' .. class)
 | 
				
			||||||
 | 
					    return
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  local widget = class.create()
 | 
					  local widget = class.create()
 | 
				
			||||||
  if parent then
 | 
					  if parent then
 | 
				
			||||||
    parent:addChild(widget)
 | 
					    parent:addChild(widget)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -15,6 +15,6 @@ Module
 | 
				
			||||||
    importStyle 'styles/listboxes.otui'
 | 
					    importStyle 'styles/listboxes.otui'
 | 
				
			||||||
    importStyle 'styles/items.otui'
 | 
					    importStyle 'styles/items.otui'
 | 
				
			||||||
    importStyle 'styles/creatures.otui'
 | 
					    importStyle 'styles/creatures.otui'
 | 
				
			||||||
    importStyle 'styles/comboboxes.otui'
 | 
					 | 
				
			||||||
    importStyle 'styles/popupmenus.otui'
 | 
					    importStyle 'styles/popupmenus.otui'
 | 
				
			||||||
 | 
					    importStyle 'styles/comboboxes.otui'
 | 
				
			||||||
    return true
 | 
					    return true
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,3 +1,7 @@
 | 
				
			||||||
 | 
					ComboBoxPopupMenuSeparator < PopupMenuSeparator
 | 
				
			||||||
 | 
					ComboBoxPopupMenuButton < PopupMenuButton
 | 
				
			||||||
 | 
					ComboBoxPopupMenu < PopupMenu
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ComboBox < UIComboBox
 | 
					ComboBox < UIComboBox
 | 
				
			||||||
  font: verdana-11px-antialised
 | 
					  font: verdana-11px-antialised
 | 
				
			||||||
  color: #aaaaaa
 | 
					  color: #aaaaaa
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -34,7 +34,7 @@ PopupMenuSeparator < UIWidget
 | 
				
			||||||
  phantom: true
 | 
					  phantom: true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
PopupMenu < UIPopupMenu
 | 
					PopupMenu < UIPopupMenu
 | 
				
			||||||
  width: 100
 | 
					  width: 50
 | 
				
			||||||
  border-image:
 | 
					  border-image:
 | 
				
			||||||
    source: /core_styles/images/menubox.png
 | 
					    source: /core_styles/images/menubox.png
 | 
				
			||||||
    border: 3
 | 
					    border: 3
 | 
				
			||||||
| 
						 | 
					@ -27,7 +27,7 @@ function UIComboBox:addOption(text, data)
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function UIComboBox:onMousePress(mousePos, mouseButton)
 | 
					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
 | 
					  for i,v in ipairs(self.options) do
 | 
				
			||||||
    menu:addOption(v.text, function() self:setCurrentOption(v.text) end)
 | 
					    menu:addOption(v.text, function() self:setCurrentOption(v.text) end)
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -23,6 +23,8 @@ function UIPopupMenu:addOption(optionName, optionCallback)
 | 
				
			||||||
    self:destroy()
 | 
					    self:destroy()
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
  optionWidget:setText(optionName)
 | 
					  optionWidget:setText(optionName)
 | 
				
			||||||
 | 
					  local width = optionWidget:getTextSize().width + optionWidget:getMarginLeft() + optionWidget:getMarginRight() + 6
 | 
				
			||||||
 | 
					  self:setWidth(math.max(self:getWidth(), width))
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function UIPopupMenu:addSeparator()
 | 
					function UIPopupMenu:addSeparator()
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue