Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added block call back for radio, boolean, button and float

  • Loading branch information...
commit 1cc6bae17c5b1b2928c0b93772e8cdbbb930bf8c 1 parent 3aa814a
@seanlilmateus authored
View
2  README.md
@@ -59,6 +59,8 @@ I'll welcome any contribution, so feel free to extend, correct any code in this
- QLoadingElement
- more ...
- Element Customization design
+- Accessibility
+- VoiceOver
## Thanks
I'd just like to thank [escoz](https://github.com/escoz) and all [QuickDialog](https://github.com/escoz/QuickDialog) contributors for the great library
View
109 app/RMDialog/rmdialog.rb
@@ -62,6 +62,87 @@ def key_appearance(appearance)
end
end
+ class RMQBooleanElement < QBooleanElement
+ def block=(value); @block = value; end
+ def switched(bool_switch)
+ @block[bool_switch.isOn] #isOn
+ super
+ end
+ end
+
+ class RMQRadioElement < QRadioElement
+ attr_accessor :block
+ def setSelected(a_selected)
+ @block[self.items[a_selected]] if @block
+ super
+ end
+ end
+
+ class RMQFloatElement < QLabelElement
+ attr_accessor :float_value, :block
+
+ def initWithTitle(title, Value:value)
+ if super(title, nil)
+ @float_value = value
+ end
+ self
+ end
+
+ def initWithValue(value)
+ if init
+ @float_value = value
+ end
+ self
+ end
+
+ def fetchValueIntoObject(obj)
+ return if self.key.nil?
+ obj.setValue(@float_value, forKey:self.key)
+ end
+
+ def calculateSliderWidth(view, cell:cell)
+ return view.contentSize.width - 40 if self.title.nil?
+ view.contentSize.width - cell.textLabel.text.sizeWithFont(UIFont.boldSystemFontOfSize(17)).width - 50
+ end
+
+ def value_changed(slider)
+ @block[slider.value]
+ @float_value = slider.value
+ end
+
+ def getCellForTableView(tableView, controller:controller)
+ cell = super
+ slider = UISlider.alloc.initWithFrame CGRectMake(0, 0, self.calculateSliderWidth(tableView, cell:cell), 20)
+ slider.addTarget(self, action:'value_changed:', forControlEvents:UIControlEventValueChanged)
+ slider.autoresizingMask = UIViewAutoresizingFlexibleWidth
+ slider.value = @float_value
+ cell.accessoryView = slider
+ cell
+ end
+ end
+
+ class RMQSegmentedElement < QSegmentedElement
+ def block=(value); @block = value; end
+ def handle_segmented(control)
+ handleSegmentedControlValueChanged(control)
+ @block[self.items[self.selected]]
+ end
+
+ def getCellForTableView(tableView, controller:controller)
+ super
+ cell = QTableViewCell.alloc.init
+ cell.backgroundView = UIView.alloc.initWithFrame CGRectMake(0, 0, 0, 0)
+ cell.backgroundColor = UIColor.clearColor
+ control = UISegmentedControl.alloc.initWithItems(self.items)
+ control.addTarget(self, action:'handle_segmented:', forControlEvents:UIControlEventValueChanged)
+ control.frame = CGRectMake(9, 0, 302, 46);
+ control.segmentedControlStyle = UISegmentedControlStyleBar
+ control.selectedSegmentIndex = self.selected
+
+ cell.addSubview(control)
+ cell
+ end
+ end
# QSection Wrapper
class RMDSection
attr_reader :section
@@ -71,18 +152,19 @@ def init(title, &block)
@section
end
- def radio(h={})
+ def radio(h={}, &blck)
ele = case h[:items]
when Hash
- QRadioElement.alloc.initWithDict(h[:items], selected:h[:selected], title:h[:title])
+ RMQRadioElement.alloc.initWithDict(h[:items], selected:h[:selected], title:h[:title])
when Array
- QRadioElement.alloc.initWithItems(h[:items], selected:h[:selected], title:h[:title])
+ RMQRadioElement.alloc.initWithItems(h[:items], selected:h[:selected], title:h[:title])
when String
- QRadioElement.alloc.initWithKey(h[:items])
+ RMQRadioElement.alloc.initWithKey(h[:items])
else
- QRadioElement.alloc.init
+ RMQRadioElement.alloc.init
end
- ele.controllerAction = h[:action] if h[:action]
+
+ ele.block = blck if block_given?
section.addElement(ele)
ele
end
@@ -94,8 +176,9 @@ def button(h={}, &blck)
ele
end
- def float(h={})
- ele = QFloatElement.alloc.initWithTitle(h[:title], value:h[:value])
+ def float(h={}, &blck)
+ ele = RMQFloatElement.alloc.initWithTitle(h[:title], Value:h[:value])
+ ele.block = blck if block_given?
ele.key = h[:key]
section.addElement(ele)
ele
@@ -115,8 +198,9 @@ def label(h={})
ele
end
- def segment(h={}) # "Option 1", @"Option 2", @"Option 3"
- ele = QSegmentedElement.alloc.initWithItems(h[:items], selected:h[:selected], title:h[:title])
+ def segment(h={}, &blck) # "Option 1", @"Option 2", @"Option 3"
+ ele = RMQSegmentedElement.alloc.initWithItems(h[:items], selected:h[:selected], title:h[:title])
+ ele.block = blck if block_given?
section.addElement(ele)
ele
end
@@ -151,8 +235,9 @@ def entry(h={title:"", value:"", placeholder:"", secure:false}, &blck)
ele
end
- def boolean(hash={})
- ele = QBooleanElement.alloc.initWithTitle(hash[:title], BoolValue:hash[:value]||false)
+ def boolean(hash={}, &blck)
+ ele = RMQBooleanElement.alloc.initWithTitle(hash[:title], BoolValue:hash[:value]||false)
+ ele.block = blck if block_given?
section.addElement(ele)
ele
end
View
23 app/controller/RMDialogViewController.rb
@@ -18,18 +18,26 @@ def create_dialog
section(name: "Example Section") do
label title:"Hello", value:"World"
- boolean title:"Music", value:true
+ boolean title:"Music", value:true do |state|
+ puts state
+ end
- boolean title:"Video"
+ boolean title:"Video" do |state|
+ puts state
+ end
- float title:"Float Element", key:"slider", value:0.5
+ float title:"Float Element", key:"slider", value:0.5 do |value|
+ puts value
+ end
decimal title:"decimal Element", key:"slider", value:0.5, fraction:2
time title:"Time element", date: NSDate.date, key:"date1", mode: UIDatePickerModeTime
elems = ["Ferrari", "McLaren", "Lotus"]
- radio items: elems, selected:0, title:"Array", action:'action:'
+ radio({items: elems, selected:0, title:"Array"}) do |state|
+ puts state
+ end
end
#second Section
@@ -38,7 +46,9 @@ def create_dialog
component2 = ["A", "B"]
picker items:[component, component2], value:"3 B", title:"Key"
- segment items:["Option 1", "Option 2", "Option 3"], selected:1, title:"Radio"
+ segment items:["Option 1", "Option 2", "Option 3"], selected:1, title:"Radio" do |selected|
+ puts selected
+ end
end.footer = "More controls will be added."
@@ -47,7 +57,8 @@ def create_dialog
label title:"Crazy", value:"Shit"
elems = {"Ferrari"=>"FerrariObj", "McLaren"=>"McLarenObj", "Mercedes"=>"MercedesObj"}
- radio items:elems, selected:0, title:"Hash", action:'action:'
+
+ radio( items:elems, selected:0, title:"Hash")
# button
button title:"open Apple.com" do
Please sign in to comment.
Something went wrong with that request. Please try again.