Skip to content

Commit

Permalink
getter/setter of view work
Browse files Browse the repository at this point in the history
  • Loading branch information
jayphelps committed May 29, 2012
1 parent a12325a commit c5353b5
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 19 deletions.
14 changes: 13 additions & 1 deletion src/UIKit/UIViewController.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "UIViewController.h"

UIViewController::UIViewController() {
UIViewController::UIViewController() : _view(NULL) {
this->view.setContainer(this);
this->view.setter(&UIViewController::setView);
this->view.getter(&UIViewController::getView);
Expand All @@ -10,6 +10,18 @@ UIViewController::~UIViewController() {

}

UIView * UIViewController::getView() {
while (this->_view == NULL) {
this->loadView();
}

return this->_view;
}

void UIViewController::setView(UIView *view) {
this->_view = view;
}

void UIViewController::loadView() {
CGRect frame = CGRectMake(0, 0, 100, 200);

Expand Down
11 changes: 2 additions & 9 deletions src/UIKit/UIViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,8 @@ class UIViewController : public NSObject {

public:
property <UIViewController, UIView *> view;

UIView * getView() {
return this->_view;
}

void setView(UIView *view) {
printf("MANLY DICK!!\n");
this->_view = view;
}
UIView * getView();
void setView(UIView *);

UIViewController();
virtual ~UIViewController();
Expand Down
11 changes: 10 additions & 1 deletion src/UIKit/UIWindow.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
#include "UIWindow.h"

UIWindow::UIWindow() {
UIWindow::UIWindow() : _rootViewController(NULL) {
this->rootViewController.setContainer(this);
this->rootViewController.setter(&UIWindow::setRootViewController);
this->rootViewController.getter(&UIWindow::getRootViewController);
}

UIViewController * UIWindow::getRootViewController() {
return this->_rootViewController;
}

void UIWindow::setRootViewController(UIViewController *controller) {
this->addSubview(controller->view);
this->_rootViewController = controller;
}

UIWindow * UIWindow::initWithFrame(CGRect frame) {
this->_initWithFrame(frame);

Expand Down
10 changes: 2 additions & 8 deletions src/UIKit/UIWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,8 @@ class UIWindow : public UIView {

public:
property <UIWindow, UIViewController *> rootViewController;

UIViewController * getRootViewController() {
return this->_rootViewController;
}

void setRootViewController(UIViewController *controller) {
this->_rootViewController = controller;
}
UIViewController * getRootViewController();
void setRootViewController(UIViewController *);

UIWindow();
virtual UIWindow * initWithFrame(CGRect);
Expand Down
1 change: 1 addition & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class ExampleViewController : public UIViewController
*/
void loadView()
{
printf("AND BOOM");
CGRect frame = CGRectMake(0, 0, 100, 200);
UIView *mainView = (new UIView)->initWithFrame(frame);

Expand Down

0 comments on commit c5353b5

Please sign in to comment.