Skip to content

Commit

Permalink
Get that row of extra keys working
Browse files Browse the repository at this point in the history
  • Loading branch information
Theodore Dubois committed Sep 23, 2018
1 parent 7b4e98a commit 515b742
Show file tree
Hide file tree
Showing 11 changed files with 437 additions and 42 deletions.
6 changes: 6 additions & 0 deletions app/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
}
}
18 changes: 18 additions & 0 deletions app/BarButton.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// AccessoryButton.h
// iSH
//
// Created by Theodore Dubois on 9/22/18.
//

#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

IB_DESIGNABLE @interface BarButton : UIButton

@property IBInspectable UIColor *highlightedBackgroundColor;

@end

NS_ASSUME_NONNULL_END
42 changes: 42 additions & 0 deletions app/BarButton.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// AccessoryButton.m
// iSH
//
// Created by Theodore Dubois on 9/22/18.
//

#import "BarButton.h"

@interface BarButton ()
@property UIColor *defaultColor;
@end

@implementation BarButton

- (void)awakeFromNib {
[super awakeFromNib];
self.layer.cornerRadius = 5;
self.layer.shadowOffset = CGSizeMake(0, 1);
self.layer.shadowOpacity = 0.4;
self.layer.shadowRadius = 0;
self.defaultColor = self.backgroundColor;
}

- (void)chooseBackground {
if (self.selected || self.highlighted) {
self.backgroundColor = self.highlightedBackgroundColor;
} else {
self.backgroundColor = self.defaultColor;
}
}

- (void)setHighlighted:(BOOL)highlighted {
[super setHighlighted:highlighted];
[self chooseBackground];
}
- (void)setSelected:(BOOL)selected {
[super setSelected:selected];
[self chooseBackground];
}

@end
18 changes: 18 additions & 0 deletions app/BarViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// BarViewController.h
// iSH
//
// Created by Theodore Dubois on 9/23/18.
//

#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

@interface BarViewController : UIViewController

@property (weak) IBOutlet UIButton *controlKey;

@end

NS_ASSUME_NONNULL_END
94 changes: 94 additions & 0 deletions app/BarViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
//
// BarViewController.m
// iSH
//
// Created by Theodore Dubois on 9/23/18.
//

#import "BarViewController.h"

@interface BarViewController ()

@property (weak, nonatomic) IBOutlet UIStackView *bar;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *barTop;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *barBottom;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *barLeading;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *barTrailing;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *barButtonWidth;
@property (weak, nonatomic) IBOutlet UIButton *hideKeyboardButton;

@end

@implementation BarViewController

- (void)viewDidLoad {
[super viewDidLoad];

if (UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad) {
[self.bar removeArrangedSubview:self.hideKeyboardButton];
[self.hideKeyboardButton removeFromSuperview];
}
if (UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPhone) {
self.view.frame = CGRectMake(0, 0, 100, 48);
} else {
self.view.frame = CGRectMake(0, 0, 100, 55);
}
}

- (void)viewWillLayoutSubviews {
CGSize screen = UIScreen.mainScreen.bounds.size;
CGSize bar = self.view.bounds.size;
// set sizing parameters on bar
// numbers stolen from iVim and modified somewhat
if (UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPhone) {
// phone
[self setBarHorizontalPadding:6 verticalPadding:6 buttonWidth:32];
} else if (bar.width == screen.width || bar.width == screen.height) {
// full-screen ipad
[self setBarHorizontalPadding:15 verticalPadding:8 buttonWidth:43];
} else if (bar.width <= 320) {
// slide over
[self setBarHorizontalPadding:8 verticalPadding:8 buttonWidth:26];
} else {
// split view
[self setBarHorizontalPadding:10 verticalPadding:8 buttonWidth:36];
}
[UIView performWithoutAnimation:^{
[self.view layoutIfNeeded];
}];
}

- (void)setBarHorizontalPadding:(CGFloat)horizontal verticalPadding:(CGFloat)vertical buttonWidth:(CGFloat)buttonWidth {
self.barLeading.constant = self.barTrailing.constant = horizontal;
self.barTop.constant = self.barBottom.constant = vertical;
self.barButtonWidth.constant = buttonWidth;
}

- (IBAction)pressEscape:(id)sender {
[self pressKey:@"\x1b"];
}
- (IBAction)pressTab:(id)sender {
[self pressKey:@"\t"];
}
- (void)pressKey:(NSString *)key {
[UIApplication.sharedApplication sendAction:@selector(insertText:) to:nil from:key forEvent:nil];
}

- (IBAction)pressControl:(id)sender {
self.controlKey.selected = !self.controlKey.selected;
}

@end

@interface BarView : UIView
@property IBOutlet UIViewController *barViewController;
@end
@implementation BarView

- (void)layoutSubviews {
// this is broken for some reason otherwise
[self.barViewController viewWillLayoutSubviews];
[super layoutSubviews];
}

@end
Loading

0 comments on commit 515b742

Please sign in to comment.