From 6a67571360785285217e8b4983d2fa0d04cd40e4 Mon Sep 17 00:00:00 2001 From: Kilian Hofmann Date: Wed, 23 Mar 2016 12:36:10 +0100 Subject: [PATCH] clang format, interaction updates. --- .clang-format | 65 +++++++++ FMC Planner 2.xcodeproj/project.pbxproj | 24 ++-- FMC Planner 2/Base.lproj/Main.storyboard | 14 +- FMC Planner 2/ViewControllerKeyboard.m | 6 +- FMC Planner 2/ViewControllerScreen.m | 170 ++++++++++++----------- 5 files changed, 177 insertions(+), 102 deletions(-) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..40eb739 --- /dev/null +++ b/.clang-format @@ -0,0 +1,65 @@ +--- +Language: Cpp +# BasedOnStyle: LLVM +AccessModifierOffset: -2 +AlignAfterOpenBracket: true +AlignEscapedNewlinesLeft: false +AlignOperands: true +AlignTrailingComments: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortBlocksOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: false +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +AllowShortFunctionsOnASingleLine: All +AlwaysBreakAfterDefinitionReturnType: false +AlwaysBreakTemplateDeclarations: false +AlwaysBreakBeforeMultilineStrings: false +BreakBeforeBinaryOperators: None +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: false +BinPackParameters: true +BinPackArguments: true +ColumnLimit: 80 +ConstructorInitializerAllOnOneLineOrOnePerLine: false +ConstructorInitializerIndentWidth: 4 +DerivePointerAlignment: false +ExperimentalAutoDetectBinPacking: false +IndentCaseLabels: false +IndentWrappedFunctionNames: false +IndentFunctionDeclarationAfterType: false +MaxEmptyLinesToKeep: 1 +KeepEmptyLinesAtTheStartOfBlocks: true +NamespaceIndentation: None +ObjCBlockIndentWidth: 4 +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 300 +PenaltyBreakString: 1000 +PenaltyBreakFirstLessLess: 120 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 60 +PointerAlignment: Right +SpacesBeforeTrailingComments: 1 +Cpp11BracedListStyle: true +Standard: Cpp11 +IndentWidth: 4 +TabWidth: 8 +UseTab: Never +BreakBeforeBraces: Attach +SpacesInParentheses: false +SpacesInSquareBrackets: false +SpacesInAngles: false +SpaceInEmptyParentheses: false +SpacesInCStyleCastParentheses: false +SpaceAfterCStyleCast: false +SpacesInContainerLiterals: true +SpaceBeforeAssignmentOperators: true +ContinuationIndentWidth: 4 +CommentPragmas: '^ IWYU pragma:' +ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ] +SpaceBeforeParens: ControlStatements +DisableFormat: false +... + diff --git a/FMC Planner 2.xcodeproj/project.pbxproj b/FMC Planner 2.xcodeproj/project.pbxproj index d0e6430..57408dd 100644 --- a/FMC Planner 2.xcodeproj/project.pbxproj +++ b/FMC Planner 2.xcodeproj/project.pbxproj @@ -18,9 +18,9 @@ E22EE9EA1C9DB7B4001F5BC0 /* FMC_Planner_2Tests.m in Sources */ = {isa = PBXBuildFile; fileRef = E22EE9E91C9DB7B4001F5BC0 /* FMC_Planner_2Tests.m */; }; E22EE9F51C9DB7B4001F5BC0 /* FMC_Planner_2UITests.m in Sources */ = {isa = PBXBuildFile; fileRef = E22EE9F41C9DB7B4001F5BC0 /* FMC_Planner_2UITests.m */; }; E28E106D1C9FF93D006E2C6B /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E28E106C1C9FF93D006E2C6B /* QuartzCore.framework */; }; - E28E10711CA01EC9006E2C6B /* Menu.plist in Resources */ = {isa = PBXBuildFile; fileRef = E28E10701CA01EC9006E2C6B /* Menu.plist */; }; - E28E10731CA0375F006E2C6B /* Route.plist in Resources */ = {isa = PBXBuildFile; fileRef = E28E10721CA0375F006E2C6B /* Route.plist */; }; - E28E10751CA037F2006E2C6B /* Perf Init.plist in Resources */ = {isa = PBXBuildFile; fileRef = E28E10741CA037F2006E2C6B /* Perf Init.plist */; }; + E28E10711CA01EC9006E2C6B /* MENU.plist in Resources */ = {isa = PBXBuildFile; fileRef = E28E10701CA01EC9006E2C6B /* MENU.plist */; }; + E28E10731CA0375F006E2C6B /* ROUTE.plist in Resources */ = {isa = PBXBuildFile; fileRef = E28E10721CA0375F006E2C6B /* ROUTE.plist */; }; + E28E10751CA037F2006E2C6B /* PERF INIT.plist in Resources */ = {isa = PBXBuildFile; fileRef = E28E10741CA037F2006E2C6B /* PERF INIT.plist */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -62,9 +62,9 @@ E22EE9F41C9DB7B4001F5BC0 /* FMC_Planner_2UITests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FMC_Planner_2UITests.m; sourceTree = ""; }; E22EE9F61C9DB7B4001F5BC0 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; E28E106C1C9FF93D006E2C6B /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; }; - E28E10701CA01EC9006E2C6B /* Menu.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Menu.plist; sourceTree = ""; }; - E28E10721CA0375F006E2C6B /* Route.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Route.plist; sourceTree = ""; }; - E28E10741CA037F2006E2C6B /* Perf Init.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Perf Init.plist"; sourceTree = ""; }; + E28E10701CA01EC9006E2C6B /* MENU.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = MENU.plist; sourceTree = ""; }; + E28E10721CA0375F006E2C6B /* ROUTE.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = ROUTE.plist; sourceTree = ""; }; + E28E10741CA037F2006E2C6B /* PERF INIT.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "PERF INIT.plist"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -172,9 +172,9 @@ E28E106F1CA01EA1006E2C6B /* Screens */ = { isa = PBXGroup; children = ( - E28E10701CA01EC9006E2C6B /* Menu.plist */, - E28E10721CA0375F006E2C6B /* Route.plist */, - E28E10741CA037F2006E2C6B /* Perf Init.plist */, + E28E10701CA01EC9006E2C6B /* MENU.plist */, + E28E10721CA0375F006E2C6B /* ROUTE.plist */, + E28E10741CA037F2006E2C6B /* PERF INIT.plist */, ); name = Screens; sourceTree = ""; @@ -285,11 +285,11 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( - E28E10751CA037F2006E2C6B /* Perf Init.plist in Resources */, + E28E10751CA037F2006E2C6B /* PERF INIT.plist in Resources */, E22EE9DF1C9DB7B3001F5BC0 /* LaunchScreen.storyboard in Resources */, - E28E10711CA01EC9006E2C6B /* Menu.plist in Resources */, + E28E10711CA01EC9006E2C6B /* MENU.plist in Resources */, E22EE9DC1C9DB7B3001F5BC0 /* Assets.xcassets in Resources */, - E28E10731CA0375F006E2C6B /* Route.plist in Resources */, + E28E10731CA0375F006E2C6B /* ROUTE.plist in Resources */, E22EE9DA1C9DB7B3001F5BC0 /* Main.storyboard in Resources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/FMC Planner 2/Base.lproj/Main.storyboard b/FMC Planner 2/Base.lproj/Main.storyboard index 5a1a78e..04e4afb 100644 --- a/FMC Planner 2/Base.lproj/Main.storyboard +++ b/FMC Planner 2/Base.lproj/Main.storyboard @@ -1,8 +1,8 @@ - + - + @@ -21,8 +21,8 @@ - - + + @@ -37,11 +37,11 @@ + - @@ -446,6 +446,10 @@ + + + + diff --git a/FMC Planner 2/ViewControllerKeyboard.m b/FMC Planner 2/ViewControllerKeyboard.m index 6fb7066..0500aaa 100644 --- a/FMC Planner 2/ViewControllerKeyboard.m +++ b/FMC Planner 2/ViewControllerKeyboard.m @@ -53,11 +53,11 @@ } else if ([sender.restorationIdentifier isEqualToString:@"Delete"]) { _main.screen.Scratchpad.text = @"DELETE"; } else if ([sender.restorationIdentifier isEqualToString:@"Top"]) { - [_main.screen loadScreen:@"Menu"]; + [_main.screen loadScreen:@"MENU"]; } else if ([sender.restorationIdentifier isEqualToString:@"Mid"]) { - [_main.screen loadScreen:@"Perf Init"]; + [_main.screen loadScreen:@"PERF INIT"]; } else if ([sender.restorationIdentifier isEqualToString:@"Bot"]) { - [_main.screen loadScreen:@"Route"]; + [_main.screen loadScreen:@"ROUTE"]; } else { _main.screen.Scratchpad.text = [_main.screen.Scratchpad.text stringByAppendingString:sender.titleLabel.text]; diff --git a/FMC Planner 2/ViewControllerScreen.m b/FMC Planner 2/ViewControllerScreen.m index 8ce983d..4a69628 100644 --- a/FMC Planner 2/ViewControllerScreen.m +++ b/FMC Planner 2/ViewControllerScreen.m @@ -11,119 +11,125 @@ @implementation ViewControllerScreen - (void)viewDidLoad { - [super viewDidLoad]; + [super viewDidLoad]; - // Do any additional setup after loading the view. - // Init Start Page - [self clearScreen]; - _Header.text = @"START"; - _Scratchpad.text = @""; + // Do any additional setup after loading the view. + // Init Start Page + [self clearScreen]; + _Header.text = @"START"; + _Scratchpad.text = @""; - // Tap gesture shit - for (UILabel *label in _LSK) { - label.adjustsFontSizeToFitWidth = YES; - label.userInteractionEnabled = YES; - UITapGestureRecognizer *reg = - [[UITapGestureRecognizer alloc] initWithTarget:self - action:@selector(enterLSK:)]; - [reg setNumberOfTapsRequired:1]; - [reg setNumberOfTouchesRequired:1]; - [label addGestureRecognizer:reg]; - } + // Tap gesture shit + for (UILabel *label in _LSK) { + label.adjustsFontSizeToFitWidth = YES; + UITapGestureRecognizer *reg = [[UITapGestureRecognizer alloc] + initWithTarget:self + action:@selector(enterLSK:)]; + [reg setNumberOfTapsRequired:1]; + [reg setNumberOfTouchesRequired:1]; + [label addGestureRecognizer:reg]; + } } - (void)viewDidAppear:(BOOL)animated { - [super viewDidAppear:YES]; - [self loadScreen:@"Menu"]; + [super viewDidAppear:YES]; + [self loadScreen:@"MENU"]; } - (void)viewDidLayoutSubviews { - _FrameHeight.constant = self.view.frame.size.height / 14.5; - // Size and LineBreak + _FrameHeight.constant = self.view.frame.size.height / 14.5; + // Size and LineBreak - _Header.font = [self findAdaptiveFontForUILabelSize:_Header.frame.size - withMinimumSize:5 - withMod:0.7]; - _Header.adjustsFontSizeToFitWidth = YES; - _Scratchpad.font = [self findAdaptiveFontForUILabelSize:_Scratchpad.frame.size + _Header.font = [self findAdaptiveFontForUILabelSize:_Header.frame.size + withMinimumSize:5 + withMod:0.7]; + _Header.adjustsFontSizeToFitWidth = YES; + _Scratchpad.font = + [self findAdaptiveFontForUILabelSize:_Scratchpad.frame.size + withMinimumSize:5 + withMod:0.7]; + _Scratchpad.adjustsFontSizeToFitWidth = YES; + for (UILabel *label in _LSK) { + label.font = [self findAdaptiveFontForUILabelSize:_Header.frame.size withMinimumSize:5 - withMod:0.7]; - _Scratchpad.adjustsFontSizeToFitWidth = YES; - for (UILabel *label in _LSK) { - label.font = [self findAdaptiveFontForUILabelSize:_Header.frame.size - withMinimumSize:5 - withMod:0.6]; - } + withMod:0.6]; + } } - (void)clearScreen { - for (UILabel *label in _LSK) { - label.text = @""; - } - _Scratchpad.text = @""; - _Header.text = @""; + for (UILabel *label in _LSK) { + label.text = @""; + } + _Scratchpad.text = @""; + _Header.text = @""; } - (void)enterLSK:(UITapGestureRecognizer *)tapReg { - if ([_Scratchpad.text isEqualToString:@"DELETE"]) { - ((UILabel *)tapReg.view).text = @""; - } else { - ((UILabel *)tapReg.view).text = _Scratchpad.text; - } - _Scratchpad.text = @""; + if ([_Scratchpad.text isEqualToString:@"DELETE"]) { + ((UILabel *)tapReg.view).text = @""; + } else { + ((UILabel *)tapReg.view).text = _Scratchpad.text; + } + _Scratchpad.text = @""; } - (UIFont *)findAdaptiveFontForUILabelSize:(CGSize)labelSize withMinimumSize:(NSInteger)minSize withMod:(float)mod { - UIFont *tempFont = nil; - NSString *testString = - @"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; + UIFont *tempFont = nil; + NSString *testString = + @"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; - NSInteger tempMin = minSize / mod; - NSInteger tempMax = 256; - NSInteger mid = 0; - NSInteger difference = 0; + NSInteger tempMin = minSize / mod; + NSInteger tempMax = 256; + NSInteger mid = 0; + NSInteger difference = 0; - while (tempMin <= tempMax) { - mid = tempMin + (tempMax - tempMin) / 2; - tempFont = [UIFont systemFontOfSize:mid]; - difference = - labelSize.height / mod - - [testString - sizeWithAttributes:[NSDictionary - dictionaryWithObject:tempFont - forKey:NSFontAttributeName]] - .height; + while (tempMin <= tempMax) { + mid = tempMin + (tempMax - tempMin) / 2; + tempFont = [UIFont systemFontOfSize:mid]; + difference = + labelSize.height / mod - + [testString + sizeWithAttributes: + [NSDictionary dictionaryWithObject:tempFont + forKey:NSFontAttributeName]] + .height; - if (mid == tempMin || mid == tempMax) { - if (difference < 0) { - return [UIFont systemFontOfSize:(mid - 1)]; - } + if (mid == tempMin || mid == tempMax) { + if (difference < 0) { + return [UIFont systemFontOfSize:(mid - 1)]; + } - return [UIFont systemFontOfSize:mid]; + return [UIFont systemFontOfSize:mid]; + } + + if (difference < 0) { + tempMax = mid - 1; + } else if (difference > 0) { + tempMin = mid + 1; + } else { + return [UIFont systemFontOfSize:mid]; + } } - if (difference < 0) { - tempMax = mid - 1; - } else if (difference > 0) { - tempMin = mid + 1; - } else { - return [UIFont systemFontOfSize:mid]; - } - } - - return [UIFont systemFontOfSize:mid]; + return [UIFont systemFontOfSize:mid]; } - (void)loadScreen:(NSString *)screenName { - _Header.text = screenName; - NSArray *screen = [[NSArray alloc] - initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:screenName + _Header.text = screenName; + NSArray *screen = + [[NSArray alloc] initWithContentsOfFile:[[NSBundle mainBundle] + pathForResource:screenName ofType:@"plist"]]; - for (int i = 0; i < _Desc.count; i++) { - ((UILabel *)_Desc[i]).text = [NSString stringWithFormat:@"%@\n", screen[i]]; - } + for (int i = 0; i < _Desc.count; i++) { + ((UILabel *)_Desc[i]).text = + [NSString stringWithFormat:@"%@\n", screen[i]]; + if (![screen[i] isEqualToString:@""] || + [_Header.text isEqualToString:@"ROUTE"]) { + ((UILabel *)_LSK[i]).userInteractionEnabled = YES; + } + } } @end