Skip to content

Commit 5ee0001

Browse files
author
Reinissance
committed
tabInputsImproved
1 parent 5a8f713 commit 5ee0001

File tree

1 file changed

+47
-30
lines changed

1 file changed

+47
-30
lines changed

src/gui/Widget.m

Lines changed: 47 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -361,38 +361,55 @@ - (void)handleWidgetTap:(UITapGestureRecognizer *)gestureRecognizer {
361361
}
362362

363363
- (void) showInputDialogForWidget: (Widget*)w withNumberPad: (BOOL) pad {
364-
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil
365-
message:@"set value:"
366-
preferredStyle:UIAlertControllerStyleAlert];
367-
[alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
368-
if (pad) {
369-
textField.keyboardType = UIKeyboardTypeDecimalPad;
370-
}
371-
[textField becomeFirstResponder];
372-
}];
373-
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel"
374-
style:UIAlertActionStyleCancel
375-
handler:nil];
376-
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"Set"
377-
style:UIAlertActionStyleDefault
378-
handler:^(UIAlertAction * _Nonnull action) {
379-
UITextField *textField = alertController.textFields.firstObject;
380-
if (textField) {
381-
if (![textField.text isEqual: @""] && ![textField.text isEqual: @"-"]) {
382-
if (pad) {
383-
NSNumber *value = [NSNumber numberWithFloat:[[textField.text stringByReplacingOccurrencesOfString:@"," withString:@"."] floatValue]];
384-
[w receiveFloat:[value floatValue] fromSource:@"user"]; // source has no effect here
385-
}
386-
else {
387-
[w receiveSymbol:textField.text fromSource:@"user"]; // source has no effect here
364+
dispatch_async(dispatch_get_main_queue(), ^{ // make shure we dont affect audio
365+
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil
366+
message:@"set value:"
367+
preferredStyle:UIAlertControllerStyleAlert];
368+
[alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
369+
if (pad) {
370+
textField.keyboardType = UIKeyboardTypeDecimalPad;
371+
// add button to toggle positive/negative
372+
UIButton *minusBtn = [UIButton buttonWithType:UIButtonTypeCustom];
373+
[minusBtn addTarget:self action:@selector(toggleNegative:) forControlEvents:UIControlEventTouchUpInside];
374+
[minusBtn setTitle:@"-/+" forState:UIControlStateNormal];
375+
376+
textField.leftView = minusBtn;
377+
textField.leftViewMode = UITextFieldViewModeAlways;
378+
}
379+
textField.textAlignment = NSTextAlignmentCenter;
380+
[textField becomeFirstResponder];
381+
}];
382+
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel"
383+
style:UIAlertActionStyleCancel
384+
handler:nil];
385+
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"Set"
386+
style:UIAlertActionStyleDefault
387+
handler:^(UIAlertAction * _Nonnull action) {
388+
UITextField *textField = alertController.textFields.firstObject;
389+
if (textField) {
390+
if (![textField.text isEqual: @""] && ![textField.text isEqual: @"-"]) {
391+
if (pad) {
392+
float value = [[textField.text stringByReplacingOccurrencesOfString:@"," withString:@"."] floatValue];
393+
// reflect the widget's min/max range
394+
value = ((value >= w.minValue) && (value <= w.maxValue)) ? value : (value >= w.minValue) ? w.maxValue : w.minValue;
395+
[w receiveFloat:value fromSource:@"user"]; // source has no effect here
396+
}
397+
else {
398+
[w receiveSymbol:textField.text fromSource:@"user"]; // source has no effect here
399+
}
388400
}
389401
}
390-
}
391-
}];
392-
[alertController addAction:cancelAction];
393-
[alertController addAction:okAction];
394-
UIViewController *rootViewController = [UIApplication sharedApplication].keyWindow.rootViewController;
395-
[rootViewController presentViewController:alertController animated:YES completion:nil];
402+
}];
403+
[alertController addAction:cancelAction];
404+
[alertController addAction:okAction];
405+
UIViewController *rootViewController = [UIApplication sharedApplication].keyWindow.rootViewController;
406+
[rootViewController presentViewController:alertController animated:YES completion:nil];
407+
});
408+
}
409+
410+
- (void) toggleNegative: (UIButton*) btn {
411+
UITextField *tf = (UITextField*) [btn superview];
412+
tf.text = ([tf.text hasPrefix:@"-"]) ? [tf.text substringFromIndex:1] : [@"-" stringByAppendingString:tf.text];
396413
}
397414

398415
@end

0 commit comments

Comments
 (0)