Skip to content

Commit

Permalink
Merge pull request #103 from Shallowmallow/BetterNumberStepper
Browse files Browse the repository at this point in the history
For Better number stepper that supports Floats ( SpinCtrlDouble)
  • Loading branch information
ianharrigan authored Jan 31, 2024
2 parents 3cc50cf + edf19e2 commit de8cc1f
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 0 deletions.
71 changes: 71 additions & 0 deletions src/hx/widgets/SpinCtrlDouble.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package hx.widgets;

import cpp.Pointer;
import wx.widgets.SpinCtrlDouble in WxSpinCtrlDouble;
import wx.widgets.WxString;

class SpinCtrlDouble extends Control {
public function new(parent:Window, text:String = null, style:Int = 0, id:Int = -1) {
if (_ref == null) {
_ref = WxSpinCtrlDouble.createInstance().reinterpret();
var str = WxString.fromUTF8(text);
spinCtrlDoubleRef.ptr.create(Window.toRaw(parent), id, str, Point.defaultPosition.ref, Size.defaultSize.ref, style);
}

super(parent, id);
}

public var value(get, set):Float;
private function get_value():Float {
return spinCtrlDoubleRef.ref.getValue();
}
private function set_value(value:Float):Float {
spinCtrlDoubleRef.ref.setValue(value);
return value;
}

public var min(get, set):Float;
private function get_min():Float {
return spinCtrlDoubleRef.ptr.getMin();
}
private function set_min(value:Float):Float {
spinCtrlDoubleRef.ptr.setRange(value, max);
return value;
}

public var max(get, set):Float;
private function get_max():Float {
return spinCtrlDoubleRef.ptr.getMax();
}
private function set_max(value:Float):Float {
spinCtrlDoubleRef.ptr.setRange(min, value);
return value;
}

public var digits(get, set):Int;
private function get_digits():Int {
return spinCtrlDoubleRef.ptr.getDigits();
}
private function set_digits(value:Int):Int {
spinCtrlDoubleRef.ptr.setDigits(value);
return value;
}

public var increment(get, set):Float;
private function get_increment():Float {
return spinCtrlDoubleRef.ptr.getIncrement();
}
private function set_increment(value:Float):Float {
spinCtrlDoubleRef.ptr.setIncrement(value);
return value;
}


//////////////////////////////////////////////////////////////////////////////////////////////////////////
// Helpers
//////////////////////////////////////////////////////////////////////////////////////////////////////////
private var spinCtrlDoubleRef(get, null):Pointer<WxSpinCtrlDouble>;
private function get_spinCtrlDoubleRef():Pointer<WxSpinCtrlDouble> {
return _ref.reinterpret();
}
}
1 change: 1 addition & 0 deletions src/wx/widgets/EventType.hx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class EventType {
public static var ICONIZE:Int = untyped __cpp__("wxEVT_ICONIZE");
public static var PG_CHANGED:Int = untyped __cpp__("wxEVT_PG_CHANGED");
public static var SPINCTRL:Int = untyped __cpp__("wxEVT_SPINCTRL");
public static var SPINCTRLDOUBLE:Int = untyped __cpp__("wxEVT_SPINCTRLDOUBLE");
public static var CALENDAR_SEL_CHANGED:Int = untyped __cpp__("wxEVT_CALENDAR_SEL_CHANGED");
public static var TREE_SEL_CHANGED:Int = untyped __cpp__("wxEVT_TREE_SEL_CHANGED");

Expand Down
32 changes: 32 additions & 0 deletions src/wx/widgets/SpinCtrlDouble.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package wx.widgets;

import cpp.Pointer;
import cpp.RawPointer;

@:include("wx/spinctrl.h")
@:unreflective
@:native("wxSpinCtrlDouble")
@:structAccess
extern class SpinCtrlDouble extends Control {

//////////////////////////////////////////////////////////////////////////////////////////////////////////
// creation functions
//////////////////////////////////////////////////////////////////////////////////////////////////////////
@:native("new wxSpinCtrlDouble") private static function _new():RawPointer<SpinCtrlDouble>;
public static inline function createInstance():Pointer<SpinCtrlDouble> {
return Pointer.fromRaw(_new());
}

@:native("Create") @:overload(function(parent:RawPointer<Window>, id:Int, value:WxString, point:Point, size:Size, style:Int):Bool {})
@:native("Create") override public function create(parent:RawPointer<Window>, id:Int, point:Point, size:Size, style:Int):Bool;

@:native("GetValue") public function getValue():Float;
@:native("SetValue") public function setValue(value:Float):Void;
@:native("GetMin") public function getMin():Float;
@:native("GetMax") public function getMax():Float;
@:native("SetRange") public function setRange(value:Float, value:Float):Void;
@:native("GetDigits") public function getDigits():Int;
@:native("SetDigits") public function setDigits(value:Int):Void;
@:native("GetIncrement") public function getIncrement():Float;
@:native("SetIncrement") public function setIncrement(value:Float):Void;
}

0 comments on commit de8cc1f

Please sign in to comment.