CommonCtrl.NumericUpDown

Represents a Windows spin box (also known as an up-down control) that displays numeric values.

Title Represents a Windows spin box (also known as an up-down control) that displays numeric values.
Author(s) LiXizhi
Date  
File script/ide/NumericUpDown.lua

Description

A NumericUpDown control contains a single numeric value that can be incremented or decremented by clicking the up or down buttons of the control. The user can also enter in a value, unless the ReadOnly property is set to true. The numeric display can be formatted by setting valueformat properties. To specify the allowable range of values for the control, set the Minimum and Maximum properties. Set the Increment value to specify the value to be incremented or decremented to the Value property when the user clicks the up or down arrow buttons. You can increase the speed and Acceleration that the control moves through numbers when the user mouse wheels over the spin box.

When the UpButton or DownButton methods are called, either in code or by the click of the up or down buttons, the new value is validated and the control is updated with the new value in the appropriate format. Specifically, if the UserEdit property is set to true, the ParseEditText method is called prior to validating or updating the value. The value is then verified to be between the Minimum and Maximum values, and the UpdateEditText method is called.

TIP Sample Code

NPL.load("(gl)script/ide/NumericUpDown.lua");
local ctl = CommonCtrl.NumericUpDown:new{
   name = "NumericUpDown1",
   alignment = "_lt",
   left = 0,
   top = 0,
   width = 150,
   height = 20,
   parent = nil,
   value = 50, -- current value
   valueformat = "%.1f",
   min = 0,
   max = 100,
   min_step = 1, 
};
ctl:Show();
-- one can also call UpdateUI manually after setting the value property. 
-- ctl:UpdateUI();

Member Functions

NumericUpDown:new

mouse down position NumericUpDown.lastMouseDown = {x = 0, y=0} NumericUpDown.lastMousePos = {x = 0, y=0} whether any mouse button is down IsMouseDown = false;

syntax

function NumericUpDown:new (o)

parameters

o  

NumericUpDown:UpdateUI

Update UI according to the current value, min, and max. But it does not fire onchage event

syntax

function NumericUpDown:UpdateUI()

NumericUpDown:ValidateData

ensure value is in proper range and steps

syntax

function NumericUpDown:ValidateData()

NumericUpDown:SetValue

set value, validate it and update UI

  • param bFireEvent : if true, onchange is event is fired if value is changed.

syntax

function NumericUpDown:SetValue(value, bFireEvent)

parameters

value  
bFireEvent if true, onchange is event is fired if value is changed.

NumericUpDown:GetValue

return the correct value

syntax

function NumericUpDown:GetValue(value)

parameters

value  

NumericUpDown:UpdateData

update date according to a given mouse position.

  • param mouse :_dy: pixel relative to the mouse down position

syntax

function NumericUpDown:UpdateData(mouse_dx, mouse_dy)

parameters

mouse _dy: pixel relative to the mouse down position
dx  
mouse _dy: pixel relative to the mouse down position
dy  

NumericUpDown:OnChange

called when the check button is pressed.

syntax

function NumericUpDown:OnChange()
Topic revision: r1 - 2008-02-29 - LiXizhi
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2022 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback