twitter-archive / twui Goto Github PK
View Code? Open in Web Editor NEWA UI framework for Mac based on Core Animation
License: Other
A UI framework for Mac based on Core Animation
License: Other
Hello,
These are not really an issue but more How to questions:
Thanks for your help,
Regards,
Sometimes it's needed to change row selection, but have different control remain as first responder. Now it's problematic, especially since setting first responder may be asynchronous (if selected cell is not visible).
Ld /Volumes/Data/stoneros/Library/Developer/Xcode/DerivedData/Example-hafykyiiqnbqvifyltzchgxygaol/Build/Products/Debug/Example.app/Contents/MacOS/Example normal x86_64
cd /Volumes/Data/stoneros/Desktop/twitter-twui-a302717/ExampleProject
setenv MACOSX_DEPLOYMENT_TARGET 10.6
/Developer/usr/bin/clang -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.7.sdk -L/Volumes/Data/stoneros/Library/Developer/Xcode/DerivedData/Example-hafykyiiqnbqvifyltzchgxygaol/Build/Products/Debug -F/Volumes/Data/stoneros/Library/Developer/Xcode/DerivedData/Example-hafykyiiqnbqvifyltzchgxygaol/Build/Products/Debug -filelist /Volumes/Data/stoneros/Library/Developer/Xcode/DerivedData/Example-hafykyiiqnbqvifyltzchgxygaol/Build/Intermediates/Example.build/Debug/Example.build/Objects-normal/x86_64/Example.LinkFileList -mmacosx-version-min=10.6 -framework QuartzCore -framework ApplicationServices -framework Cocoa -o /Volumes/Data/stoneros/Library/Developer/Xcode/DerivedData/Example-hafykyiiqnbqvifyltzchgxygaol/Build/Products/Debug/Example.app/Contents/MacOS/Example
ld: warning: instance method 'setDrawRect:' in category from /Volumes/Data/stoneros/Library/Developer/Xcode/DerivedData/Example-hafykyiiqnbqvifyltzchgxygaol/Build/Intermediates/Example.build/Debug/Example.build/Objects-normal/x86_64/TUIView.o overrides method from class in /Volumes/Data/stoneros/Library/Developer/Xcode/DerivedData/Example-hafykyiiqnbqvifyltzchgxygaol/Build/Intermediates/Example.build/Debug/Example.build/Objects-normal/x86_64/TUIView.o
I've been using TUITableView, but i could not find an option to allow the selection of multiple cells (using Cmd/Shift+Mouse click).
Not sure if it's possible right now.
I'm trying to use TUIButton without external graphics, so I'm using setDrawRect: and calling the TUIButton's drawRect from within that, but I notice that the label is horribly placed, and the states aren't defined well. Is there a way to set custom Core Graphics "drawRects" for TUIButtons on different states? And how should I go about fixing the position of the label? I've looked through TUIButton's implementation, but I don't see how it draws incorrectly.
Next time you do a release, can you do the proper git-tag :)?
I think in TWUIColor it'd be useful to have methods such as - redComponent, -blueComponent, -greenComponent, etc. And rename -alpha to -alphaComponent
after call reloadData in TUITableView, the view gona be blank and some time all cell a missing until you click them while scrolling...is there any way to fix this problem?
I am trying to create a resize toggle animation on this simple custom TUIScrollView class that I have built. It is called TUILayout and supports horizontal layout as well as vertical, animated insertions and removals and has a more declarative way of supplying data to it's cells that I prefer over delegation. It recycles views similar to TUITableView. Anyway if you want to follow along, it's just one class and is here.
https://github.com/mrjjwright/TUILayout.
In the example code, the user clicks the blue button in the lower left and all the rows shrink smoothly to a size where the user can reorder and delete some rows (right click on a row in the example to see this in action), etc... and then the user toggle the rows back out to their original size by clicking the blue button again.
While doing this resize in setObjectHeight:animated
I first resize my model objects that represent the rows, recalculate and set the contentSize on the TUIScrollView, cycle in all the new views (say 10 more views will fit in the shrunk view so dequeueReusableView and addSubview gets called 10 times) and finally I animate the frames of all the views to their size and location in layoutSubviews.
The result is that the scrollview correctly shrinks to a size where the scrollbar no longer displays, the views that are on screen animate smoothly down to their reduced size, but the newly added subviews that can now fit in the visibleRect animate in much later as one block of subviews.
So all the newly added subviews lag behind the views that were on the screen and I can't figure out why the animation isn't all happening together. I have tried lots of different combos of things with no luck including CATransactions. I am wondering if it has to with how a CAScrollLayer works or if somebody can help me think through this. I won't leave this up for long if nobody is interesed as I know there is no core issue here with TUI.
The more general issue is how to smoothly handle resizing animations on scrollviews that recycles their views and I have looked at several other grids out there in iOS world and have got some inspiration but am looking for more.
Thanks!
John
I've been trying to get TUITextView to scroll properly like NSTextView, and I decided to start by switching TUITextRender to subclass TUIView... anyone want to point me on what I should do next? The entire architecture of TwUI is completely different than both UIKit and AppKit.
I've patched up some more of the event handling that UIControl does into TUIControl... as I don't have a git fork for TwUI, I'm going to just post the update here:
- (void)mouseDown:(NSEvent *)event {
if(!_controlFlags.disabled) {
[super mouseDown:event];
BOOL track = [self beginTrackingWithTouch:event withEvent:event];
if(track && !_controlFlags.tracking) {
[self _stateWillChange];
_controlFlags.tracking = 1;
[self _stateDidChange];
} else if(!track && _controlFlags.tracking) {
[self _stateWillChange];
_controlFlags.tracking = 0;
[self _stateDidChange];
}
if(_controlFlags.tracking) {
TUIControlEvents currentEvents = TUIControlEventTouchDown;
if([event clickCount] < 2)
currentEvents |= TUIControlEventTouchDownRepeat;
[self sendActionsForControlEvents:currentEvents];
[self setNeedsDisplay];
}
}
}
- (void)mouseDragged:(NSEvent *)event {
if(!_controlFlags.disabled) {
[super mouseDragged:event];
if(_controlFlags.tracking) {
BOOL track = [self continueTrackingWithTouch:event withEvent:event];
if(track && !_controlFlags.tracking) {
[self _stateWillChange];
_controlFlags.tracking = 1;
[self _stateDidChange];
} else if(!track && _controlFlags.tracking) {
[self _stateWillChange];
_controlFlags.tracking = 0;
[self _stateDidChange];
}
if(_controlFlags.tracking) {
TUIControlEvents currentEvents = (([self eventInside:event])?
TUIControlEventTouchDragInside :
TUIControlEventTouchDragOutside);
[self sendActionsForControlEvents:currentEvents];
[self setNeedsDisplay];
}
}
}
}
- (void)mouseUp:(NSEvent *)event {
if(!_controlFlags.disabled) {
[super mouseUp:event];
if(_controlFlags.tracking) {
[self endTrackingWithTouch:event withEvent:event];
TUIControlEvents currentEvents = (([self eventInside:event])?
TUIControlEventTouchUpInside :
TUIControlEventTouchUpOutside);
[self sendActionsForControlEvents:currentEvents];
[self setNeedsDisplay];
[self _stateWillChange];
_controlFlags.tracking = 0;
[self _stateDidChange];
}
}
}
// Support tracking cancelation.
- (void)willMoveToSuperview:(TUIView *)newSuperview {
if(!_controlFlags.disabled && _controlFlags.tracking) {
[self _stateWillChange];
_controlFlags.tracking = 0;
[self _stateDidChange];
[self cancelTrackingWithEvent:nil];
[self setNeedsDisplay];
}
}
- (void)willMoveToWindow:(TUINSWindow *)newWindow {
if(!_controlFlags.disabled && _controlFlags.tracking) {
[self _stateWillChange];
_controlFlags.tracking = 0;
[self _stateDidChange];
[self cancelTrackingWithEvent:nil];
[self setNeedsDisplay];
}
}
- (BOOL)beginTrackingWithTouch:(NSEvent *)touch withEvent:(NSEvent *)event {
// Override.
return YES;
}
- (BOOL)continueTrackingWithTouch:(NSEvent *)touch withEvent:(NSEvent *)event {
// Override.
return YES;
}
- (void)endTrackingWithTouch:(NSEvent *)touch withEvent:(NSEvent *)event {
// Override.
}
- (void)cancelTrackingWithEvent:(NSEvent *)event {
// Override.
}
When i add
self.tableView.transform = CGAffineTransformMakeRotation(M_PI * 0.5);
the tableview just scroll left and right when i scroll up and down,how to fix this?
Please help?
... instead it should return a TUIView
If you set a TUITableView as rootView, events are not caught properly, no scroll, no clicks...
Set a TUIView as rootView and TUITableView as a subview of the TUIView fix this issue.
Couldn't find any information in the source code to set the nextKeyView.
I am seeing several issues related to fast user switching and twui.
I have a mac book pro running lion. I am logged in as 'User A', I create 'User B' and ensure that 'fast user switching' is enabled. I am using the Example.app included in the source code in all scenarios.
App becomes unresponsive after switching to User B and then back to User A:
1.) As User A, launch Example.app, notice that everything is working fine (scrolling, clicks, etc)
2.) Fast user switch to User B
3.) Fast user switch back to User A
Expected:
Example.app continues to operate normally
Actual:
The app appears to no longer respond to clicks or scrolls. I believe that events are still being handled, its just that nothing is being rendered.
App goes "blank" after being restarted while "switched out":
1.) Login as User A
1.) Move Example.app to ~/Applications
2.) execute this command from the command line
sleep 10 ; ~/Applications/Example.app
3.) quickly switch to User B (before the 10 seconds elapses)
4.) as User B, wait for more than 10 seconds to allow the app to launch while switched out
5.) switch back to User B
Expected:
Example.app is running normall
Actual:
Example.app is running, but the screen is blank. Nothing is rendered, although events seem to be processed
This is not an issue, but a question about how to use the tableview.
Is it possible to force the redraw/refresh of a single row of a table view? (or a tuiview inside the cell)
I haven't been able to achieve it. I tried setting setNeedsDisplay/Layout to the cell. I also tried setNeedsDisp/Layout to the tableview, but it seems that calls are ignored.
I only got it to display again the new value when i call reloadData or when i resize the table View (it seems it forces a layout/redraw of the table).
I see preliminary support in place for a single-line text view, but it still needs to be implemented to scroll to the right when additional text is entered, as well as to the left when selecting, arrowing, or deleting.
In TUIScrollView ~line 950,
if(_pull.xPulling) {
_pull.xPulling = NO;
...
}
if(_pull.yPulling) {
_pull.yPulling = NO;
...
}
if(self.isPulling && _scrollViewFlags.didChangeContentInset){
...
}
self.isPulling is always false. Create a temporary variable to remember the state of isPulling can solve this problem.
Steven
The delegate method tableView:didSelectRowAtIndexPath:
is not called when navigating with the arrow keys.
I am getting a crash in the demo app when the keyboard is used to navigate the tableview.
These are the steps to reproduce it:
EDIT: After some more tests, it seems that in step 1 it's not needed to go to the end of the table.
just clicking a row in a section different to the first one, can cause the crash.
EDIT2: It seems that the problem happens only with current version in github. If i rollback to the previous version (without this commit ) it works fine.
It seems the problem is in the function - (void)selectRowAtIndexPath:(TUIFastIndexPath *)indexPath animated:(BOOL)animated scrollPosition:(TUITableViewScrollPosition)scrollPosition , and with the "oldIndexPath".
If i revert that function to the code before the commit, they keyboard works fine and it does not crash.
Removing a view hierarchy containing TUI content from a window and then subsequently re-adding the same view hierarchy (e.g., to toggle between two different top-level views or something) causes the TUI content to display nothing. It's actually there and still seems to get key events just fine, though.
Specifically, I've got:
Switching out the view noted above with another view, and then switching back by re-adding it causes the problem.
I've been poking around a bit, but I have no idea why this would happen.
In TUI/UIKit/TUICGAdditions.m:
void CGContextAddRoundRect(CGContextRef context, CGRect rect, CGFloat radius)
...
CGContextAddArc(context, rect.origin.x + radius, rect.origin.y + rect.size.height - radius, radius, M_PI / 4, M_PI / 2, 1);
The line above should be changed into the following:
CGContextAddArc(context, rect.origin.x + radius, rect.origin.y + rect.size.height - radius, radius, M_PI , M_PI / 2, 1);
Every time I move cursor into a TUITableViewCell's subview, TUIView will call cell's mouseExited. but cursor is still in cell. Is there any way to know when cursor exited the cell to another cell. Thanks!
I discovered a few little problems with TUIScrollView
during my brief testing. First of all, when you are scrolling horizontally, it continues to use bounce scroll in the vertical direction while you scroll (so if your scrolling direction isn't perfectly horizontal, it will bounce upwards a bit and disrupt inertial scrolling). This also means that there is no bounce scroll in the horizontal direction. As mentioned in the title, I think it would be useful to have an option to disable bounce scroll as well.
I want to implement a paged TUIScrollView photo viewer for flipping through photos iOS Photo app style. I have some example code from different iOS libs but was wanting input or making sure nobody else has done the same here.
Thanks!
I'm building a app totally based on TwUI, But I found that TUITextView doesn't respond to Input methods (such like Chinese Pinyin).When I type in it, the Input method's word select window doesn't show. there has a same problem in the Twitter for Mac's search field (new tweet window works fine.)
I'v tried using a TUIViewNSViewContainer to add a NSTextView in a TUIView. but app receive a EXC BAD ACCESS when I add the nsview container view, here is the code :
TUIView * root = [[TUIView alloc] init];
root.backgroundColor = [TUIColor colorWithWhite:0.9 alpha:1.0];
tuiContainer.rootView = root;
NSTextView * textView = [[NSTextView alloc] initWithFrame:root.bounds];
TUIViewNSViewContainer * nsViewCon = [[TUIViewNSViewContainer alloc] initWithNSView:textView];
[root addSubview:nsViewCon];
Does there have any solution to handle input method using Twui? Thanks~
Is there any twui api to add a breadcrumb navigation style in the title bar view?
Is there a reason that overriding drawRect with an empty implementation in an otherwise blank TUIView increases memory usage substantially? This is probably a total newb question and has to do with the way CALayer handles content but I am totally seeing a 40 meg difference in memory when I add a few hundred TUIViews to a scroll view that do and don't override drawRect, even with an empty implementation?
I might remove this question here in a little bit as as I do some further testing. Sorry to waste anybody's time but if somebody has a short answer that would be great.
When lineBreakMode is set for the renderer, it seems to behave differently when the frame allows drawing multiple lines of the text.
For a frame that can contain multiple lines, if the text renderer properties are set like this:
[textRedender setAlignment:TUITextAlignmentLeft lineBreakMode:TUILineBreakModeWordWrap];
Multiple lines are drawn, the last line is wrapped to the last word, and the ellipsis is not drawn as expected.
But it i change the properties to this:
[textRedender setAlignment:TUITextAlignmentLeft lineBreakMode:TUILineBreakModeWordWrap | TUILineBreakModeTailTruncation];
then the ellipsis is shown at the end, but only the first line is drawn. The rest of the lines are not drawn by the renderer.
EDIT: Added screenshot
The upper part has been drawn without TUILineBreakModeTailTruncation. It shows both lines. The lower part was drawn with that option added, and in this case, the second line is not drawn. The frame size is the same in both cases.
The right mouse click events are mostly used to show context menus based on underlying cell. Therefore I think the cell should also be selected when right clicking on the cell.
In the current implementation the cell is only selected when left clicking on the cell.
thanks for this great ui kit. I have a problem to add some row to the TUITableview. can I add a row without update the hole table? and is there any way to set the cell height dynamically?
Any idea how to do this? Thank you.
Getting the following message when using a TUIScrollView on Lion (10.7)
-_scrollPhase is deprecated for NSScrollWheel. Please use -momentumPhase.
Wouldn't it be far better to do something like:
TUIKit.h:
// Test for Lion support.
extern BOOL isAtleastLion(void);
// Set and get global screen scale factor.
extern float screenScale(void);
extern void setScreenScale(float);
TUIKit.m:
static BOOL initialized = NO;
static float screen_scale = 0.0;
static BOOL is_lion = NO;
BOOL isAtleastLion() {
if(!initialized) {
SInt32 major = 0;
SInt32 minor = 0;
Gestalt(gestaltSystemVersionMajor, &major);
Gestalt(gestaltSystemVersionMinor, &minor);
if((major == 10 && minor >= 7) || major >= 11) {
is_lion = YES;
} else is_lion = NO;
initialized = YES;
} return is_lion;
}
float screenScale() {
if(screen_scale <= CGFLOAT_MIN)
screen_scale = [[NSScreen mainScreen] userSpaceScaleFactor];
return screen_scale;
}
void setScreenScale(float scale) {
if((scale > CGFLOAT_MIN)) {
screen_scale = scale;
}
}
To abstract the screen scaling and OS detection away from the end developer?
What I did was move all TUIGraphics* functions into a new .h/.m TUIGraphics.m, and add those functions into TUIKit.h/.m. Then I proceeded to remove #import "TUIKit.h"'s and replaced them with #import "TUIGraphics.h" to make more sense.
I was wondering how to detect click on a hyperlinkTUIAttributedString created as below. The event mouseDown is not registering on the associated TUITextRenderer. Is there a better way to create links in TUITextRenderers?
Thanks!
John
+(id)hyperlinkFromString:(NSString*)inString withURL:(NSURL*)aURL
{
TUIAttributedString* attrString = [TUIAttributedString stringWithString:inString];
NSRange range = NSMakeRange(0, [attrString length]);
[attrString beginEditing];
[attrString addAttribute:NSLinkAttributeName value:[aURL absoluteString] range:range];
// make the text appear in blue
NSColor *blueColor = [TUIColor colorWithHexString:@"#3B5998"].nsColor;
[attrString addAttribute:NSForegroundColorAttributeName value:blueColor range:range];
[attrString endEditing];
return attrString;
}
I have been in the process of adding multiple selection support to the TUITableView and friends classes, and it seems that the cells do not maintain a consisten state, as far as selection is concerned. Setting the boolean ivar selected in UITableViewCell does not stay consistent throughout the drawing process, ie. in drawRect:. I had to test in drawRect: whether or not the indexPath was in the UITableView's list of selected index paths, an ugly hack.
The code is forked on my account; there may be a more elegant way for you to see it but I'm not familiar enough with git or GitHub to know how to do it.
I am using a TUIAttributted string, and i found a problem. When i set the lineheight, the Alignment/linebreak properties i previously defined are ignored, and the text is drawn using the default properties.
I located the problem in these functions:
In those methods, a new CTParagraphStyle object is created, but each method only sets the values for the values received, ignoring the values previously set.
The solution would be to recreate the CTParagrahStyleRef object with all the expected properties.
I could fix it, but my doubt is how to implement it .
The easiest way seemed to keep ivars for those values and recreate the CTParagraphStyle object, but currently, those methods belong to the NSMutableAttributedString (TUIAdditions) category, and categories cannot have ivars.
I can see other options:
any suggestion?
I'm writing a navigation controller based on twui,
and I'm trying to make a animation like iOS when the navigation controller push new view.
In the pushViewController: method, follow things will be done:
1.insert new view to index 0;
2.set new view's start frame;
3.animate old view and new view to destination frame.
here is a sample project:
https://github.com/Naituw/TUIViewAnimationDemo
when I click push button, old view's animation works fine,
but , the new view doesn't make any animation, it just jump to the destination frame.
Did I missed anything?
use Chinese Input Method
I input "ai" mean "爱",but when type second character,it's became "a", not "ai"
use English Input Method no problem.
I drew an icon on CGBitmapContextCreate with CoreGraphics and assigned it to a TUIImageView. That icon was designed to be clipped as RoundRect, but what I got was a round-rect-ed icon with black corners.
After a few tries, it would not work until the backgroundColor of TUIImageView was set to clear color.
It seems that the default backgroundColor was nil for both TUIImageView and TUIView(, correct me if I am wrong). Is this an issue?
EDIT: The code I posted previously really did not fix anything. It was a placebo :[
The question that remains is that the -reloadData call ends up jumbling up all the cells and in my use-case, the table view becomes really unusable. What am I missing here/what is going wrong? What needs to be fixed?
I need a UINavigationController like component for my app and was wondering if anybody has already built one they would like to share. If not I plan to take some inspiration from Chameleon and build one myself.
Thanks!
(My english is poor , but I'm trying hard to explain this. : ) )
I have a textRenderer in a TUITableViewCell , but it is abnormal when I use mouse drag to select text in it.
The background didn't change when I dragging.
I found TUITableViewCell has override selfs' mouseDragged: method for cell reordering function.
so I add [super mouseDragged:event]; in this method.
method seems like below now.
-(void)mouseDragged:(NSEvent *)event {
// notify our table view of the event
[super mouseDragged:event];
[self.tableView __mouseDraggedCell:self offset:_mouseOffset event:event];
}
Is that correct ?
Hey, thanks for developing twui. I recently found a issue about the selected cell problem.
How to reproduce:
Select a cell and drag it into another row. After release the mouse, the cell with the old indexpath is selected.
I have to add the following code inside TUITableView+Cell.m to reset the _selectedCellIndexPath.
if ([[self indexPathForCell:cell] isEqual:_selectedIndexPath]) {
[_selectedIndexPath release];
_selectedIndexPath = [targetIndexPath retain];
}
Did I do something wrong? Maybe I don't have to do this hack?
I am using a a TUITableView, with one header and several cells.
The header view has a TuiButton with a menu. First time the table view is loaded, the button displays the menu.
But i found a problem whenever i reload the data. If i reload the data, the button won't display the menu any more.
Debugging, i can see that the mousedown is catched, and that the call to the popUpMenuPositioningItem function is done.
But no menu is shown.
If just after that i resize the window, even a little bit, and then i click again in the button, the menu shows just fine.
I've done another test displaying a popup menu when mousedown is detected in the header view of the table, and the same happens. I need to resize the window after "reloadData" in order to be able to show the popup menu.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.