Skip to content
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

Create constant padding page layout option #5270

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

tmoerschell
Copy link
Contributor

Fixes #5268.
I'm not too sure what branch to base it on. It's currently on master, but it's possible to rebase it on release-1.2. I took it on as a sub-issue of #5269, as it required knowing all about the padding around the pages. It would be nice to be able to merge this one and then use it as a base for the zoom center fix.

@bhennion
Copy link
Contributor

I would not do this in the release branch. This is not fixing a bug: some previous dev went out of their way to get the behaviour we have. A simple grid, which is the result we get with this PR, is much simpler to implement than the current Layout/LayoutMapper implementation.

Overall, we should have a debate about what the best behaviour should be. This includes questions:

  1. what use cases lead to pages of different sizes?
  2. is being vertically/horizontally centered really the most natural thing in those situations?
  3. how should pages 200 to 210 be displayed if page 1 is a bit wider? Should the padding still be there even though we are very far from the problematic page?

Those questions should be answered before anything else, and of course 1. will influence the answers to 2. and 3..

As for possible usecases, I guess rotating pages is one. We should also keep in mind something like #3430 (should it ever be implemented).

@tmoerschell
Copy link
Contributor Author

Oh I'm sorry, I didn't know this was actually the wanted behavior. The current implementation looks kinda odd: it does include some padding to compensate for different page widths, but not enough to align the pages. I have now also checked the PR that introduced this code (#872), and it doesn't seem to mention a reason for this.

About the branch issue, I agree that it isn't a good idea to merge this into the release branch. But the PR I want to build upon afterwards was, and the changes aren't in the master branch. So I wonder: do those get merged into the master branch as well after some time? Why not right away?

The use case I have is inserting portrait A4 pages between 3:2 slides to take additional notes.
Adding some extra space to PDF pages or rotating them is certainly also something that could happen in the future.

I personally don't actually use the multi-column layout. I just came across it trying to fix another issue. I'm always writing something on a single page, so I rarely have multiple pages in my view anyways. I'd think what is happening between the pages is of little importance to most users. For me, it should just be as pretty as possible.

Anyways, I think there's mainly two options you could go about the layout:

  • Keep a constant padding between pages, disregarding alignment issues. A horizontal layout may have rows of different lengths and a vertical layout may have columns of different heights.
  • Put the pages into a simple grid, disregarding padding consistency within rows and columns.

One issue with the grid would certainly be that if one has a page that is a lot bigger than the others, it will cause big gaps between other pages. But who would ever do that?

I don't know what an infinite canvas would look like, or if there already is an idea about how to implement it. A simple version of that could be just pages with an arbitrarily large, automatically extending size. This could cause wildly different page sizes. I guess a solution to that could then be to crop/scale over-sized pages when zoomed out.

@bhennion
Copy link
Contributor

Oh I'm sorry, I didn't know this was actually the wanted behavior. The current implementation looks kinda odd

I agree it is kinda odd. To be clear, I don't think your changes are not a good idea, but I think we should investigate how it'll influence various use cases (if we can find someone actually using it).

So I wonder: do those get merged into the master branch as well after some time? Why not right away?

We can certainly merge the release branch into the master branch whenever we want. No problem there. You can create a PR for that, containing exactly 1 merge commit, so people can check it out and make sure nothing wrong happened in the process. Then we'll fast forward it onto the master branch.

I personally don't actually use the multi-column layout. I just came across it trying to fix another issue. I'm always writing something on a single page, so I rarely have multiple pages in my view anyways. I'd think what is happening between the pages is of little importance to most users. For me, it should just be as pretty as possible.

tmoerschell added a commit to tmoerschell/xournalpp that referenced this pull request Oct 27, 2023
tmoerschell added a commit to tmoerschell/xournalpp that referenced this pull request Oct 27, 2023
@tmoerschell tmoerschell mentioned this pull request Oct 27, 2023
2 tasks
@rolandlo
Copy link
Member

I agree it is kinda odd. To be clear, I don't think your changes are not a good idea, but I think we should investigate how it'll influence various use cases (if we can find someone actually using it).

I do use a 1-row or 2-row layout on my external monitor for displaying my solutions when correcting an exam. Usually the pages have all the same format though. Different page formats can appear when you have a document, where some pages are landscape and others are portrait. Another case may appear when the PDF was generated from (camera or scanned) images. There are also some books and journals where some of the first pages have a different format.

The solution proposed in this PR looks logical from the point of view that all layout settings are symmetrical with respect to vertical/horizontal. But the current layout method has its advantages, too.

tmoerschell added a commit to tmoerschell/xournalpp that referenced this pull request Oct 29, 2023
@tmoerschell tmoerschell marked this pull request as draft November 18, 2023 11:36
@tmoerschell
Copy link
Contributor Author

Ok, finally made some progress with this: I implemented constant padding layout.
It's the first time I touched something on the GUI / action database side. I hope I didn't miss too many things.

There are some parts of the code that I'm not too fond of (especially the repeated loops in Layout.cpp). I'm sure it must be possible to this in a better way, but couldn't find it.

Do also note that this is not fully functional yet: the visual part is good, but it is in some cases not possible to draw on the pages, for example, because most notably I haven't adapted Layout::getPageViewAt(x, y) yet.

@tmoerschell
Copy link
Contributor Author

Ok, everything is good now, except for getPaddingAbovePage() and getPaddingLeftOfPage(), which I plan to change in #5295 anyways, so I'd leave it for then.

Can't guarantee that I caught everything, but I will put it up for review again.

@tmoerschell tmoerschell marked this pull request as ready for review December 5, 2023 13:14
@tmoerschell tmoerschell changed the title Align pages horizontally and center them vertically Create constant padding page layout option Dec 5, 2023
@tmoerschell
Copy link
Contributor Author

Also a quick note that there is currently (on master and release branches) a real issue with documents containing multiple page sizes and layout in multiple columns: it is sometimes not possible to draw on the whole page area as shown in this screenshot.
image
This can be fixed by just the first commit (which makes me think the current behavior wasn't really intentional). Would it be worth it to put that one also on the release branch?

Copy link
Contributor Author

@tmoerschell tmoerschell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here are a the main issues I have with my code. I would appreciate feedback on this. It might also explain some of the oddities I wrote.

src/core/control/settings/Settings.cpp Outdated Show resolved Hide resolved
Comment on lines +87 to +91
enum LayoutType {
LAYOUT_TYPE_GRID = 0,
LAYOUT_TYPE_CONST_PADDING = 1,
};

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hesitated between creating a custom enumeration and defining the setting as a simple bool layoutConstPadding or something. I'm also not really sure the enum declaration is in the right place here

src/core/gui/Layout.h Outdated Show resolved Hide resolved
Comment on lines +288 to +294
struct PageLayoutDescription {
double paddingLeft = 0.0;
double paddingTop = 0.0;
double width = 0.0;
double height = 0.0;
std::optional<size_t> optionalPage = std::nullopt;
};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's a bit ugly to have that struct definition in the function implementation. Is there a better way?

Also we don't actually need width and height at the same time. We could replace it with a single variable size which would be one or the other, depending on the layout orientation. But that would make the understanding and the control flow a little more complicated, so I figured it's ok like this?


std::vector<PageLayoutDescription> pages; // access with r * rows + c
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be a lot easier to use a C-style 2-dimensional array, but I haven't found a good equivalent in C++. Suggestions?

Comment on lines +303 to +306
// Iterate over ALL possible rows and columns 3 times:
// We don't know which page, if any, is to be displayed in each row, column - ask the mapper object!
// Once we know the dimensions of all pages, define the paddings above and left of each page as required.
// Finally, assign page coordinates by propagating page paddings and sizes from the border.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This whole section (until line 445) is taking a lot of space. Also I'm not sure how good it is to iterate over every page 3 times. This is the shortest code I could come up with for this, but I'm 80% convinced there must be a better way I'm not aware of.

src/core/gui/Layout.cpp Show resolved Hide resolved
src/core/gui/Layout.cpp Outdated Show resolved Hide resolved
In particular:
 * Store all grid cell bounds for const padding
 * Add getGridPositionAt() and use it in updateVisibility()
@tmoerschell
Copy link
Contributor Author

I've improved some of the things I was unhappy with now, so I'd like to request a review from someone on this :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Page layout is unaligned and pages are not centered vertically
3 participants