Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » Look and Chameleon Technology » FEATURE_REQUEST: SliderCtrl to have WhenClick
Re: FEATURE_REQUEST: SliderCtrl to have WhenClick [message #23482 is a reply to message #23454] Thu, 22 October 2009 15:58 Go to previous messageGo to previous message
mrjt is currently offline  mrjt
Messages: 705
Registered: March 2007
Location: London
Contributor
I can't comment on why Ctrl don't have more default actions, but everything you want can be done easily using a composite control:
class KeySlider : public Ctrl
{
	typedef KeySlider CLASSNAME;
private:
	struct ClickSlider : public SliderCtrl {
		Callback WhenClick;
		virtual void LeftUp(Point p, dword keyflags) {
			SliderCtrl::LeftUp(p, keyflags);	
			WhenClick();
		}
	};
	ClickSlider ctrl;
	Label label;
	Vector<Value> keys;

	void UpdateSlider();
	void Click() const							 { WhenClick(); }
	virtual void Updated()						 { label.SetLabel(AsString(GetData())); }
public:
	Callback WhenClick;
	
	KeySlider();
	
	virtual void LeftUp(Point p, dword keyflags) { Click(); }

	KeySlider &Add(Value v)	{ keys.Add(v); UpdateSlider(); return *this; }
	void Remove(int i)	{ keys.Remove(i); UpdateSlider(); }
	int  GetCount() const;
	
	void SetLabelWidth(int cx);
	
	virtual Value GetData() const { return keys.GetCount() ? keys[(int)~ctrl] : Value(); }
	virtual void SetData(const Value& data);
};

KeySlider::KeySlider()
{
	Transparent(true);
	SetLabelWidth(32);
	UpdateSlider();
	ctrl.WhenClick = THISBACK(Click);
	ctrl <<= THISBACK(UpdateAction);
}

void KeySlider::SetLabelWidth(int cx)
{
	Ctrl::Add(ctrl.VSizePosZ().HSizePosZ(0, cx+2));
	Ctrl::Add(label.VSizePosZ().RightPosZ(0, cx));
}

void KeySlider::UpdateSlider()
{
	ctrl.Enable(keys.GetCount());	
	if (!keys.GetCount())
		return;
	ctrl.MinMax(0, keys.GetCount()-1);
	if (IsNull(~ctrl))
		ctrl <<= 0;
	Updated();
}

void KeySlider::SetData(const Value& data)
{
	int ix = FindIndex(keys, data);
	if (ix >= 0)
		ctrl <<= ix;
}

Because it uses key values you can do things like:
slider.Add("A").Add("B").Add("C").Add("D").Add("E").Add("F").Add("G");


And when I want to add WhenClick or WhenKey events to Ctrls I usually just use a simple template that overloads the event handling function.
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: Spinner controls a bit off?
Next Topic: Chameleon again
Goto Forum:
  


Current Time: Tue May 07 05:00:32 CEST 2024

Total time taken to generate the page: 0.01907 seconds