Today's Menu  Portugal
journal and plan nutrition
U7ParamEditControlbarView.m
Go to the documentation of this file.
1 //
2 // U7ParamEditControlbarView.m
3 // TodaysMenu
4 //
5 // Created by Don Zeek on 1/1/17.
6 // Copyright © 2017 net.dzeek.y2015.ios.portfolio. All rights reserved.
7 //
8 
12 #import "TotalEditStateEnum.h"
13 
14 @implementation U7ParamEditControlbarView
15 {
16  // ControlbarStateEnum controlbarState;
17  UIButton *controlbarRightButton;
18  // Y3GradientButton *parameterEditButton;
19  // Y3GradientButton *parameterRemoveButton;
20  // Y3GradientButton *parameterAcceptButton;
21  UIButton *controlbarLeftButton;
23  // CGRect parameterAcceptFrame;
25  CGSize buttonSize;
26 
27  id<U7ParamEditControlDelegate> delegate;
28 }
29 
30 - (instancetype) initWithDelegate:(id<U7ParamEditControlDelegate>) dele
31 {
32  self = [super init];
33  if (self) {
34  delegate = dele;
35  [self setClipsToBounds:YES];
36  NSLog(@"ParamEditControlbar.initWithDelegate: finish init");
37  }
38  return self;
39 }
40 
41 #pragma mark - Z6ContainedView
42 
44 {
45  return buttonSize.height + 2;
46 }
47 - (void) appear:(CGRect)bound
48 {
49  float viewWidth = bound.size.width;
50  NSLog(@"ParamEditControlBar.appear: bound: %3.2f/%3.2f %3.2f/%3.2f",
51  bound.origin.x, bound.origin.y, bound.size.width, bound.size.height);
52 
53  buttonSize = CGSizeMake(viewWidth * 0.50 - 4.0, 40.0);
54  [self fillViewOnAppearance:self.bounds];
55 }
56 
57 - (void) reconfigure
58 {
59  CGRect delegateBound = CGRectMake(0, 0, [delegate viewWidth], 300);
60  [self fillViewOnAppearance:delegateBound];
61 }
62 - (void) fillViewOnAppearance: (CGRect) parentBound
63 {
64  self.userInteractionEnabled = YES;
65  float viewWidth = parentBound.size.width;
66  // [self setBackgroundColor:[UIColor orangeColor]];
67  NSLog(@"ParamEditControlBar.fillViewForDelegate: viewWidth: %3.2f", viewWidth);
68  buttonSize = CGSizeMake(viewWidth * 0.5, 40.0);
69 
71  [controlbarRightButton removeFromSuperview];
73  }
75  [controlbarLeftButton removeFromSuperview];
77  }
78 
79  controlbarRightButtonFrame = CGRectMake(viewWidth - buttonSize.width - 2,
80  0,
81  buttonSize.width,
82  buttonSize.height);
83  controlbarLeftButtonFrame = CGRectMake(2.0,
84  0,
85  buttonSize.width - 10,
86  buttonSize.height);
87 
88  switch ([delegate getTotalEditState]) {
89  case INITIAL_STATE:
90  {
91  controlbarRightButton = [[UIButton alloc] initWithFrame:controlbarRightButtonFrame];
92  [controlbarRightButton setTitle:@"add parameter" forState:UIControlStateNormal];
93  [controlbarRightButton addTarget:self action:@selector(clickPlusButton) forControlEvents:UIControlEventTouchUpInside];
94  [self addSubview:controlbarRightButton];
95  }
96  break;
97  case PICK_COMPONENT:
98  {
99  controlbarRightButton = [[UIButton alloc] initWithFrame:controlbarRightButtonFrame];
100  [controlbarRightButton setTitle:@"Edit parmtr" forState:UIControlStateNormal];
101  [controlbarRightButton addTarget:self action:@selector(clickEditButton) forControlEvents:UIControlEventTouchUpInside];
102  [self addSubview:controlbarRightButton];
103 
104  controlbarLeftButton = [[UIButton alloc] initWithFrame:controlbarLeftButtonFrame];
105  [controlbarLeftButton setTitle:@"cancel" forState:UIControlStateNormal];
106  [controlbarLeftButton addTarget:delegate action:@selector(clickCancelButton) forControlEvents:UIControlEventTouchUpInside];
107  [self addSubview:controlbarLeftButton];
108  }
109  break;
110  case PICK_QUANTITY:
111  {
112  controlbarRightButton = [[UIButton alloc] initWithFrame:controlbarRightButtonFrame];
113  [controlbarRightButton setTitle:@"accept" forState:UIControlStateNormal];
114  [controlbarRightButton addTarget:self action:@selector(clickAcceptButton) forControlEvents:UIControlEventTouchUpInside];
115  [self addSubview:controlbarRightButton];
116 
117  controlbarLeftButton = [[UIButton alloc] initWithFrame:controlbarLeftButtonFrame];
118  [controlbarLeftButton setTitle:@"cancel" forState:UIControlStateNormal];
119  [controlbarLeftButton addTarget:delegate action:@selector(clickCancelButton) forControlEvents:UIControlEventTouchUpInside];
120  [self addSubview:controlbarLeftButton];
121 
122  }
123  break;
124  default:
125  {
126  NSLog(@"ParamEditControlBar.fillViewOnAppearance: SHOULD NOT BE HERE");
127  }
128  }
129 
130 }
131 
133 {
134  NSLog(@"ParamEditControlBar: clickPlusButton");
135  [delegate configureToState:PICK_COMPONENT];
136 }
138 {
139  NSLog(@"ParamEditControlBar: clickEditButton");
140  [delegate configureToState:PICK_QUANTITY];
141 }
143 {
144  NSLog(@"ParamEditControlBar: clickAcceptButton");
145  [delegate clickAcceptButton];
146 }
147 //- (void) showWithinEdit
148 //{
149 // [controlbarRightButton setHidden:YES];
150 // // [parameterEditButton setHidden:NO];
151 // [controlbarLeftButton setHidden:NO];
152 //}
153 - (void) showRemoveOption: (Boolean) flag
154 {
155  if (flag) {
156  controlbarLeftButtonFrame = CGRectMake(2.0,
157  0,
158  buttonSize.width - 10,
159  buttonSize.height);
160 
161  controlbarLeftButton = [[UIButton alloc] initWithFrame:controlbarLeftButtonFrame];
162  [controlbarLeftButton setTitle:@"remove" forState:UIControlStateNormal];
163  [controlbarLeftButton addTarget:delegate action:@selector(clickRemoveButton) forControlEvents:UIControlEventTouchUpInside];
164  [self addSubview:controlbarLeftButton];
165  } else {
166  [controlbarLeftButton removeFromSuperview];
167  }
168 
169 }
170 - (void) showEditButton: (Boolean) flag
171 {
172  NSLog(@"ParameterEditControlbar.showEditButton: NO-OP");
173 }
174 //- (void) showReadyToConfirm
175 //{
176 // // [parameterAcceptButton setHidden:YES];
177 // [controlbarLeftButton setHidden:YES];
178 // [controlbarRightButton setHidden:NO];
179 //}
180 //
181 //- (void) showPickOptions
182 //{
183 // // [parameterAcceptButton setHidden:NO];
184 // [controlbarLeftButton setHidden:NO];
185 // // [parameterEditButton setHidden:YES];
186 //}
187 //
188 //- (void) showAddSelectionButton: (Boolean) flag
189 //{
190 // Boolean hiddenFlag = !flag;
191 // [controlbarRightButton setHidden:hiddenFlag];
192 //}
197 //- (void) showRemoveHidden
198 //{
199 // // [parameterRemoveButton setHidden:YES];
200 //}
205 //- (void) showParameterSelect
206 //{
207 // NSLog(@"ParamEditControlbar.showParameterSelect");
208 //}
209 
210 /*
211 // Only override drawRect: if you perform custom drawing.
212 // An empty implementation adversely affects performance during animation.
213 - (void)drawRect:(CGRect)rect {
214  // Drawing code
215 }
216 */
217 
218 @end
UIButton * controlbarRightButton
UIButton * controlbarLeftButton
void fillViewOnAppearance:(CGRect parentBound)
id< U7ParamEditControlDelegate > delegate
CGSize buttonSize
CGRect controlbarLeftButtonFrame
CGRect controlbarRightButtonFrame