-
Notifications
You must be signed in to change notification settings - Fork 648
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
Add paddings to Stack and create Layout function #19
Conversation
Padding and spacing is something I've been thinking about, yes. First, I wanted to make some changes to Label about vertical text alignment, then I was thinking of just having padding on/off, choosing reasonable pixel values for the given platform. As for Layout: I actually wanted to recreate GtkGrid (more info) but as a subpackage, since Stack and Grid provide the necessary functionality. However, this looks useful as it is, so I would just need to go through your function (though I might drop it in a subpackage). I could have both facilities with a subpackage =P I'll go through everything once I resume work on the project (probably later today or tomorrow or in the next few days) |
reminder to self: should nil in the stack/grid constructors also insert a space? |
All right. I'll use this space to think about padding and margins. I'm not sure if I can take your implementation of it as is since this will be done on a platform dependent level but. Windows
The killer here is "7 dialog units of margin on all sides". I'm going to guess that the dialog unit conversion will have to be done on the window, and then copied down to each individual control. Not a problem on the backend side (this is what hte implementation does, so =P ), but will require more parameter shuffilng than I just did. GTK+
Notice that GNOME suggests 6-pixel increments. MAC OS X The Human Interface Guidelines say "Use the proper spacing between controls. When controls are spaced evenly in a window, the window is more attractive and easier for users to use. The layout guides in Interface Builder show you the recommended spacing between controls and between UI elements and window edges." In other words, since we're not using Interface Builder, we're screwed. If the spacing has /never/ changed and /will never change/, then we don't really have a problem, but... There is Auto Layout, but again, the values to use are hidden from view; I would need to create Auto Layout constraints for everything and that'll be too much work to duplicate work I'm already doing! The Auto Layout guide does hint that the standard spacing between controls is 12 pixels. I'm currently waiting in IRC for more information. |
Thanks, I had been looking for that Windows guidelines for a while. I could only find their Metro style guide. I'll try adding system-dependent margins and padding as a start, and later give a shot at grouping controls. I think this is might be doable in a transparent fashion for the library user. |
All right, so. I tried starting to write in all the prerequisite work to use the above information. I realized that this would require yet another massive change to the whole sizing and layout system. And since the proper positioning of labels is already invasive enough as it is... I'm strongly leaning toward scrapping the whole sizing system and redoing that all from scratch. Stack and Grid themselves would need only minimal change. but the actual backend sizing stuff will disappear. But I'm not exactly sure as to what... Package ui works in quadrant IV coordinates, but some calculations become extremely difficult on Mac OS X without requiring a bidirectional control tree since Mac OS X uses quadrant I coordinates. Right now I compensate by passing a On the Windows side, I have a giant mess and the need to manually compute dialog box coordinates (or just treat everything as a dialog box) and text widths. But other than that, there are no issues. Windows uses quadrant IV coordinates. On GTK+ I don't have any real issues. Labels have full control over their horizontal and vertical position, so I can just have labels position themselves properly. GTK+ uses qudrant IV coordinates. I'll probably need to model all this in pseudocode. Your Layout() function is surprisingly smaller than I thought it would be, though I see you actually touch the Stacks directly. I could possibly just have that put in as is, but I'll do that after the margin/padding change. |
What do you think of this? initial pseudocode fefc060#diff-777c16bc56e4fc4518379caa1f5f7200 |
Looks sound to me, I have only two comments to make:
I added a bounty to the stack overflow question, let's see if we can get that sorted out. |
For nested layouts, the intended result will be that the first deepest control of the sub-layout on the right is the neighbor of the first deepest control of the sub-layout on the left. I'm not sure how this will work in recursive calls, but it's worth trying. I'll make that clearer in the final code. Actually, doResize() now is the last step in the resizing. I'll rename it to commitResize(). As I mentioned earlier, fine-tuning the allocated space has to be done on the transformed coordinates to make things easier when aligning label baselines with their neighboring controls on OS X (I tried to do these calculations on nontransformed coordinates this morning and just got confused). Thanks for adding the bounty. |
I've pushed margin and padding code now. I unfortunately wasn't able to use your code (I wrote this offline) but it handles separate margin and padding in both directions. Turn it on for an entire window with w.SetSpaced(true) (I could change that name) I would add the equivalent Grid code, but I can't seem to figure out if the margin/padding is different from what it is in Stack. What do you think?
If you resend the Layout pull request I can merge that. |
Add a Layout function for higher-level layouts. I might put this in a subrepository. Thanks @boppreh
I wrote a test and it seems the Grid spacing is the same, but I'm still not sure about the test program... what do you think anyway? Also, what do you think of the system-provided padding values? (Compared to your first screenshot...) |
Wait, I didn't finish fixing The problem now is that for the |
Oh sorry :( It shouldn't be too hard to fix... |
Yeah, not that big of a problem to fix, but right now I think the project is not building because of this. |
What build issue are you getting? |
The |
Done. Thanks for all the waiting and trouble ^^' What exactly do you think of what I have now visually, though (in comparison to the values you used to make your original screenshot)? Just curious |
Those were just random values, no specific reason for them. I'm in Ubuntu now and the spacing looks good. I'll try Windows later today. I just found weird that the background of the test application is black in Ubuntu. I don't know what color it should be, but I'm sure it's not black. I can open a new Issue if you prefer. |
Ah, I thought that would happen eventually. Will fix, especially now that the KDE bug has been fixed. |
…his breaks the Ubuntu GTK+ 3 themes (Ambianace and Radiance) with their correct renderer (see #19 (comment)), and the KDE bug has now been fixed.
Update: the rewrite gets rid of the black background issue on Ubuntu. I'm not sure what caused it, but my custom GTK+ container doesn't trip anything, so... |
I tried to make an intuitive function to quickly create good-looking layouts. I liked the result, but I understand if you don't want to increase the API size right now, so this is only a suggestion. Anyway, the padding/margin code may be useful by itself.
This change is twofold:
padding
andmarginBorder
toStack
that work as expected. I'm open to name suggestions here.Layout
that creates a stack with automatic orientation, padding and border.Layout
works by giving only the topmost stacks a margin, and settings its orientation to "vertical". All nested stacks inside it are oriented perpendicular to its parent and have only padding, not margin. As a bonus, anynil
value is converted to a stretchy space.So for example, this code:
Creates this layout:
I personally liked the results and will be using the function, merging or not. I'm also considering making a
Stretch
function, so you can writeui.Layout(button1, ui.Stretch(button2), button3)
but right now I can't think of an elegant implementation because the stretching information is on the parent.