-
Notifications
You must be signed in to change notification settings - Fork 620
Add fixed positioning, and the ability to set and get a component size #332
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
ui.h
Outdated
@@ -97,6 +97,8 @@ _UI_EXTERN void uiControlHide(uiControl *); | |||
_UI_EXTERN int uiControlEnabled(uiControl *); | |||
_UI_EXTERN void uiControlEnable(uiControl *); | |||
_UI_EXTERN void uiControlDisable(uiControl *); | |||
_UI_EXTERN void uiSize(uiControl *control, int *width, int *height); | |||
_UI_EXTERN void uiSetSize(uiControl *control, int width, int height); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consistency, should these be names uiControlSize and uiControlSetSize, respectively?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not agree with making the size of a control a property of the control itself. Sizes should be controlled directly by uiFixed, just as positions are; this is important as it's how all the other containers work anyway. It will also remove the need for the pointless sizing signal logic in the Unix code.
darwin/fixed.m
Outdated
// 15 august 2015 | ||
#import "uipriv_darwin.h" | ||
|
||
// TODO hiding all stretchy controls still hugs trailing edge |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this TODO have anything to do with this file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. I copied box.m and then modified that since I was unfamiliar with the layout and I forgot to take that out.
.gitignore
Outdated
@@ -0,0 +1,2 @@ | |||
build |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove this file.
darwin/fixed.m
Outdated
|
||
// TODO hiding all stretchy controls still hugs trailing edge | ||
|
||
@interface fixedChild : NSObject |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the name uiprivFixedChild
.
darwin/fixed.m
Outdated
- (NSView *)view; | ||
@end | ||
|
||
@interface fixedView : NSView { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the name uiprivFixedView
.
darwin/fixed.m
Outdated
NSMutableArray *children; | ||
} | ||
- (id)initFixed:(uiFixed *)bb; | ||
- (bool)isFlipped; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to redeclare isFlipped
.
darwin/fixed.m
Outdated
- (id)initFixed:(uiFixed *)bb | ||
{ | ||
self = [super initWithFrame:NSZeroRect]; | ||
self.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Always use Objective-C method syntax, even for superclass property getters and setters.
Put this line in the if block.
libui uses Auto Layout; uiprivFixedView
should be controllable with Auto Layout, but its contents don't necessarily have to be. I have to figure out how this would work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think the autoresizingMask is strictly necessary, I think I just added that when trying to debug why the components weren't being sized correctly.
darwin/fixed.m
Outdated
self = [super initWithFrame:NSZeroRect]; | ||
self.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable; | ||
if (self != nil) { | ||
// the weird names vert and bb are to shut the compiler up about shadowing because implicit this/self is stupid |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to copy this comment over from the other files.
darwin/main.m
Outdated
@@ -10,6 +10,41 @@ | |||
static BOOL (^isRunning)(void); | |||
static BOOL stepsIsRunning; | |||
|
|||
@interface sizeWrapper : NSView { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is any of this necessary? You also are not properly initializing or uninitializing instances of these objects.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was weird to me also. When I used uiDarwinControlHandle and cast it to a NSView*, it complained about fixed not being a property. If I enclosed it in an interface that subclassed NSView, then it worked fine.
darwin/main.m
Outdated
{ | ||
CGSize s = CGSizeMake(width, height); | ||
[[[sizeWrapper alloc] addControl:control] setS:s]; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use newlines at the end of files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More review comments.
unix/fixed.c
Outdated
uiUnixControl c; | ||
GtkWidget *widget; | ||
GtkContainer *container; | ||
GtkFixed *fixed; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't use GtkFixed; it does not properly theme with CSS. GtkLayout would be better, but the ideal solution would be to have a custom GtkContainer subclass that does the barest minimum possible. Look at the version of package ui that immediately predated libui for details. (I can do this later too.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll look at that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I finally got more time to look at this. I assume you're talking about this: https://github.com/andlabs/ui/blob/de9d72299fb89a8b6cdc8963cd6b6ae708a81e80/container_unix.c
So you're overriding GtkContainer, but where do you actually set children size and location?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@andlabs How exactly would this work? I haven't done that much work with GTK.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line 62, which is a Go function. I forget what you call in there for each child control, but you can check the Go code.
@@ -35,6 +35,16 @@ void uiWindowsEnsureMoveWindowDuringResize(HWND hwnd, int x, int y, int width, i | |||
logLastError(L"error moving window"); | |||
} | |||
|
|||
void uiWindowsResizeWindow(HWND hwnd, int width, int height) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm pretty sure these two are provided in winutil.cpp anyway.
Will review the rest of the code later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was uiWindowsEnsureMoveWindowDuringResize
, but that moves and resizes the window. I added these functions because when you either move or resize a window, Windows doesn't give accurate values for the other two, so if you want it to move, it'll end up resizing also. Which is why I made these with the SWP_NOSIZE
and SWP_NOMOVE
flags.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missed a spot
darwin/fixed.m
Outdated
return self; | ||
} | ||
|
||
- (bool)isFlipped |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BOOL
, not bool
.
I've made most of the changes. As for having uiFixed control the sizing, I agree that it's a good idea, and it seems like it will work with my code so I'll change that. |
darwin/fixed.m
Outdated
@@ -165,7 +162,7 @@ static void uiFixedSyncEnableState(uiDarwinControl *c, int enabled) | |||
uiDarwinControlDefaultHugsBottom(uiFixed, view) | |||
uiDarwinControlDefaultChildEdgeHuggingChanged(uiFixed, view) | |||
|
|||
static void uiFixedChildVisibilityChanged(uiDarwinControl *c) | |||
static void uiuiprivFixedChildVisibilityChanged(uiDarwinControl *c) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One "ui" too much
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I pushed so that I could check the changes in my VM. I'll fix that.
Also I need to formalize some of the suggestions I made here into the contribution guidelines. Sorry if I came off as aggressive with any of them; these are just policies specific to libui to keep everything consistent! |
No it's all right. I'm all for keeping code quality and style consistent.
I've just never really worked with Objective C and C++ as much.
…On Wed, Apr 4, 2018, 4:54 PM Pietro Gagliardi ***@***.***> wrote:
Also I need to formalize some of the suggestions I made here into the
contribution guidelines. Sorry if I came off as aggressive with any of
them; these are just policies specific to libui to keep everything
consistent!
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#332 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AJW73GkGbP9k7060SpymJu4IVhgslmFzks5tlTL_gaJpZM4TF1cl>
.
|
Also for the |
Alright sizing should be moved to uiFixed now. |
Ok @andlabs I finally got a chance to implement a custom container, which I've added as |
@andlabs sorry for bothering you but is there anything else that I need to do? Thanks! |
@andlabs I know you're busy but what's the status on this? |
Hopefully this can get merged so the work on kusti8/proton-native#76 can continue! |
I was going to write a big long expalantion of why I didn't want to merge this PR in, but thinking about it now it's been too long and I forgot exactly what I was going to say at the time. Sorry. Here's the general gist of what my objections were:
Of course, these original comments seem invalid now anyway, because I only see the Fixed code in the PR, not the code for any of the support APIs. What happened? And then again, other UI toolkits have had fixed layouts alongside dynamic layouts for a while and haven't had major problems, so maybe I was just worrying too much. Perhaps a uiFixed is fine, though there's still a few things missing from libui that would allow one to be used "correctly". I'll consider this again during the development of Alpha 5, as I want to make some major changes to uiControl itself for that (some of which were requested here). |
That's alright. The original PR never included any yoga or anything like that for the exact purpose to keep libui light weight. I simply added an API for fixed position of objects. That API is used by me in JS which integrates with Yoga at that level, since yoga had a JS wrapper. Whever a change is seen by me, that is sent to yoga to recompute the coordinates and that moves everything. |
The ideal thing is there should be one place where you can hook into to spot control size changes. Alpha 5 will include that, since I'll be redoing uiControl entirely. This should probably also automatically mirror on an RTL system, but I have no idea where to start with that. I'll still review this PR and see if we can put this container in. |
Any updates? |
The work on Alpha 5 will allow this to be feasible without encouraging the kind of mistakes that cause other toolkits (including this one) to avoid including this. It'll have to wait one more version. |
This fixes #306 and allows me to get yoga working. So far, I've added this and the libui-node bindings as well as yoga to proton-native and it works very well.
I haven;t done any sort of work with GUI libraries really, so feel free to comment on my style. This shouldn't interfere with anything else, since all it does is add a new component. I also did this from the alpha3.5 tag because that is the latest that libui-node supported at the time. It is currently being worked on to work on the latest version.
Gustav