-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
a very early approach to write a QuickDialog wrapper for Rubymotion
- Loading branch information
0 parents
commit 80d9878
Showing
7 changed files
with
300 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.repl_history | ||
build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
$:.unshift("/Library/RubyMotion/lib") | ||
require 'motion/project' | ||
require 'motion-cocoapods' | ||
|
||
Motion::Project::App.setup do |app| | ||
# Use `rake config' to see complete project settings. | ||
app.name = 'rmdialog' | ||
## Using cocoapods, coming soon! | ||
# app.pods do | ||
# dependency 'QuickDialog' | ||
# end | ||
|
||
app.vendor_project('vendor/QuickDialog', :xcode, | ||
:target => 'QuickDialog', | ||
:headers_dir => 'quickdialog') | ||
app.frameworks += ['MapKit', 'CoreLocation'] | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
module RMDialog | ||
def self.create(hash={}, &block) | ||
root = Root.new(hash, &block).root | ||
end | ||
|
||
class Root | ||
attr_reader :root | ||
# create a root QRootElement | ||
def initialize(h={}, &block) | ||
@root = QRootElement.alloc.init | ||
@root.grouped = h[:grouped] if h[:grouped] | ||
@root.title = h[:title] if h[:grouped] | ||
instance_eval(&block) | ||
end | ||
|
||
# create a QSection | ||
def section(title = nil, &blck) | ||
section = RMDSection.new(title, &blck).section | ||
@root.addSection(section) | ||
section | ||
end | ||
|
||
# create a QSelectSection | ||
def selection(h={indexes: nil}, &blck) | ||
section = QSelectSection.alloc.initWithItems(h[:items], selectedIndexes:h[:selected], title:h[:title]) | ||
section.multipleAllowed = h[:multi] if h[:multi] | ||
@root.addSection(section) | ||
section.instance_eval(&blck) if block_given? | ||
section | ||
end | ||
|
||
# create an QDynamicDataSection | ||
def dynamic_section(h={}, &blck) | ||
dyn_section = QDynamicDataSection.new | ||
dyn_section.title = h[:title] | ||
dyn_section.emptyMessage = h[:msg] if h[:msg] | ||
blck[dyn_section] if block_given? | ||
@root.addSection(dyn_section) | ||
dyn_section | ||
end | ||
end | ||
|
||
|
||
class RMDBadge < QBadgeElement | ||
def background_color(color) | ||
self.badgeColor = color | ||
end | ||
|
||
def color(color) | ||
self.badgeTextColor = color | ||
end | ||
end | ||
|
||
# QEntryElement wrapper example | ||
class RMDEntry < QEntryElement | ||
def key_type(type) | ||
self.keyboardType = type | ||
end | ||
|
||
def key_appearance(appearance) | ||
self.keyboardAppearance = appearance | ||
end | ||
end | ||
|
||
# QSection Wrapper | ||
class RMDSection | ||
attr_reader :section | ||
def initialize(title, &block) | ||
@section = title.nil? ? QSection.alloc.init : QSection.alloc.initWithTitle(title[:name]) | ||
instance_eval(&block) | ||
end | ||
|
||
def radio(h={}) | ||
radio = case h[:items] | ||
when Hash | ||
QRadioElement.alloc.initWithDict(h[:items], selected:h[:selected], title:h[:title]) | ||
when Array | ||
QRadioElement.alloc.initWithItems(h[:items], selected:h[:selected], title:h[:title]) | ||
when String | ||
QRadioElement.alloc.initWithKey(h[:items]) | ||
else | ||
QRadioElement.alloc.init | ||
end | ||
radio.controllerAction = h[:action] if h[:action] | ||
@section.addElement(radio) | ||
radio | ||
end | ||
|
||
def button(h={}, &blck) | ||
button = QButtonElement.alloc.initWithTitle(h[:title]) | ||
button.controllerAction = h[:action] if h[:action] | ||
button.onSelected = blck if block_given? | ||
@section.addElement(button) | ||
button | ||
end | ||
|
||
def float(h={}) | ||
slider = QFloatElement.alloc.initWithTitle(h[:title], value:h[:value]) | ||
slider.key = h[:key] | ||
@section.addElement(slider) | ||
slider | ||
end | ||
|
||
def decimal(h={}) | ||
slider = QDecimalElement.alloc.initWithTitle(h[:title], value:h[:value]) | ||
slider.key = h[:key] | ||
slider.fractionDigits = h[:fraction] | ||
@section.addElement(slider) | ||
slider | ||
end | ||
|
||
def label(h={}) | ||
label = QLabelElement.alloc.initWithTitle(h[:title], Value:h[:value]) | ||
@section.addElement(label) | ||
label | ||
end | ||
|
||
def segment(h={}) # "Option 1", @"Option 2", @"Option 3" | ||
element = QSegmentedElement.alloc.initWithItems(h[:items], selected:h[:selected], title:h[:title]) | ||
@section.addElement(element) | ||
element | ||
end | ||
|
||
def picker(h={}, &blck) | ||
picker = QPickerElement.alloc.initWithTitle(h[:title], items:h[:items], value:h[:value]) | ||
picker.onValueChanged = blck if block_given? | ||
@section.addElement(picker) | ||
picker | ||
end | ||
|
||
def time(h={}) | ||
timer = QDateTimeInlineElement.alloc.initWithTitle(h[:title], date:h[:date]) | ||
timer.key = h[:key] if h[:key] | ||
timer.mode = h[:mode] if h[:mode] | ||
@section.addElement(timer) | ||
timer | ||
end | ||
|
||
def badge(h={}, &blck) | ||
badge = RMDBadge.alloc.initWithTitle(h[:title]||"", Value:h[:value].to_s||"0") | ||
@section.addElement(badge) | ||
badge.instance_eval(&blck) if block_given? | ||
badge | ||
end | ||
|
||
def entry(h={title:"", value:"", placeholder:"", secure:false}, &blck) | ||
entry = RMDEntry.alloc.initWithTitle(h[:title], Value:h[:value], Placeholder:h[:placeholder]) | ||
entry.secureTextEntry = h[:secure] | ||
@section.addElement(entry) | ||
entry.instance_eval(&blck) if block_given? | ||
entry | ||
end | ||
|
||
def boolean(hash={}) | ||
bool = QBooleanElement.alloc.initWithTitle(hash[:title], BoolValue:hash[:value]||false) | ||
@section.addElement bool | ||
bool | ||
end | ||
end | ||
end | ||
|
||
class RMDialogController < QuickDialogController | ||
def action(sender) | ||
NSLog("Radio %@", sender.selected) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class AppDelegate | ||
def application(application, didFinishLaunchingWithOptions:launch_opts) | ||
@window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds) | ||
rmdialog_controller = RMDialogViewController.alloc.init | ||
nav = UINavigationController.alloc.initWithRootViewController(rmdialog_controller) | ||
@window.rootViewController = nav | ||
@window.makeKeyAndVisible | ||
true | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
class RMDialogViewController < UIViewController | ||
def loadView | ||
super | ||
end | ||
|
||
def viewDidLoad | ||
super | ||
self.view.backgroundColor = UIColor.whiteColor | ||
self.create_dialog | ||
end | ||
|
||
|
||
def create_dialog | ||
root = RMDialog.create(title:"Rubymotion Dialog", grouped:true) do | ||
# First Section with Name | ||
section(name: "Example Section") do | ||
|
||
label title:"Hello", value:"World" | ||
|
||
boolean title:"Music", value:true | ||
|
||
boolean title:"Video" | ||
|
||
float title:"Float Element", key:"slider", value:0.5 | ||
|
||
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:'dance:' | ||
end | ||
|
||
#second Section | ||
section(name:"Second Section") do | ||
component = [*1..12] | ||
component2 = ["A", "B"] | ||
|
||
picker items:[component, component2], value:"3 B", title:"Key" do | ||
NSLog("Selected indexes %@", ) | ||
end | ||
|
||
segment items:["Option 1", "Option 2", "Option 3"], selected:1, title:"Radio" | ||
end.footer = "More controls will be added." | ||
|
||
# Section without a name | ||
section do | ||
label title:"Crazy", value:"Shit" | ||
|
||
elems = {"Ferrari"=>"FerrariObj", "McLaren"=>"McLarenObj", "Mercedes"=>"MercedesObj"} | ||
radio items:elems, selected:0, title:"Hash", action:'action:' | ||
|
||
# button | ||
button title:"login" do | ||
alert = UIAlertView.alloc.initWithTitle("I Alert you", | ||
message:"Do you want to be alerted?", | ||
delegate: self, | ||
cancelButtonTitle: "OK", | ||
otherButtonTitles:nil) | ||
alert.show | ||
end | ||
|
||
|
||
badge title: "With a badge", value: 10 do | ||
background_color UIColor.redColor | ||
color UIColor.whiteColor | ||
end | ||
|
||
entry title:"Name", placeholder:"HELLO" | ||
|
||
entry title:"Password", placeholder:"YES", secure:true do | ||
key_type UIKeyboardTypeNumberPad | ||
key_appearance UIKeyboardAppearanceAlert | ||
end | ||
end | ||
|
||
# section Section | ||
selection items:["Football", "Soccer", "Formula 1"], title:"Simple select" | ||
|
||
# Dynamic Sections | ||
dynamic_section title:"Default: loading", msg:"This is empty" | ||
|
||
dynamic_section title:"Normal: with elements" do |sec| | ||
sec.bind = "iterate:something" | ||
sec.elementTemplate = {"type" => "QLabelElement", "title" => "Something here" } | ||
end | ||
end | ||
|
||
root.bindToObject({"empty" => [], "something" => ["first", "second"]}) | ||
|
||
navigation = RMDialogController.controllerWithNavigationForRoot(root) | ||
self.presentModalViewController(navigation, animated:false) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
describe "Application 'rmdialog'" do | ||
before do | ||
@app = UIApplication.sharedApplication | ||
end | ||
|
||
it "has one window" do | ||
@app.windows.size.should == 1 | ||
end | ||
end |
Submodule QuickDialog
added at
ada483