-
-
Notifications
You must be signed in to change notification settings - Fork 723
Add units support (POINT, PIXEL, SPACE) #2578
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
Conversation
- add a size_with_unit struct - add a geometry_format_values struct - move dpi initialisation from renderer.cpp to bar.cpp - add a string to size_with_unit converter - add point support (with pt) - add pixel support (with px)
The old names didn't really capture the purpose of the structs and function. space_type -> spacing_type space_size -> spacing_val size_type -> extent_type geometry -> extent_val geometry_format_values -> percentage_with_offset
No longer needed. The convert<spacing_val> function in config.cpp already does all the work for us and always setting the type to pixel was wrong. In addition, line-size should not be of type spacing_val but extent_val.
We can't just blindly add the x difference to the width because for example the width should increase if x < width and the increase keeps x < width. Similarly, we can't just add the offset to the width.
Co-authored-by: Patrick Ziegler <p.ziegler96@gmail.com>
Co-authored-by: Patrick Ziegler <p.ziegler96@gmail.com>
Co-authored-by: Patrick Ziegler <p.ziegler96@gmail.com>
Co-authored-by: Patrick Ziegler <p.ziegler96@gmail.com>
Co-authored-by: Patrick Ziegler <p.ziegler96@gmail.com>
Codecov Report
@@ Coverage Diff @@
## master #2578 +/- ##
==========================================
+ Coverage 11.37% 11.80% +0.43%
==========================================
Files 153 153
Lines 11137 11248 +111
==========================================
+ Hits 1267 1328 +61
- Misses 9870 9920 +50
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
Negative spacing is never allowed and produces a config error.
Extents allow negative values in theory, but only a few use-cases accept
it.
Only the extent value used for the `%{O}` tag and the offset value in
percentage_with_offset can be negative. Everything else is capped below
at 0.
The final pixel value of percentage_with_offset also caps below at 0.
All changes preserve the existing semantics
Instead, we first check if the current tag is built, and only if it is, the spacing is prepended.
If there are two tags and the second one isn't built (module::build returns false), the space in between them is removed. For example in the mpd module: format-online = <toggle> <label-song> foo If mpd is not running, the mpd module will return false when trying to build the `<label-song>` tag. If we don't remove the space between `<toggle>` and `<label-song>`, we end up with two spaces between `<toggle>` and `foo`. This change is to match the old behavior where at least one trailing space character was removed from the builder.
|
Alright, this is finally done!! I want to thank again @Lomadriel and @frebib for doing a lot of heavy lifting for this feature. This will be very useful to a lot of users. |
What type of PR is this? (check all applicable)
Description
This basically just resolves the merge conflicts in #2394, which itself just fixed the conflicts from #1671.
In this PR, I will try to bring this feature across the finishline, as I already discussed with @frebib some months ago on IRC.
Thanks to @Lomadriel and @frebib for all their efforts on this feature.
Checklist
100foo)spacing_type::SPACE).%{O}tag.Check whether Modules with click actions become non-clickable when offset is used #1814 is fixed hereIt is not.tray-offset-*Related Issues & Documents
Addresses the following feature requests:
Closes #1651
Closes #951
Fixes the following bugs:
Fixes #1700
Fixes #1265
Makes the following PRs obsolete:
Closes #1671
Closes #2394
Documentation (check all applicable)
We need to document that the
%{O}tag now supportspxandptas units:Offset
%{O}Inserts a gap of the specified size (can also be negative).
The value specified can be any extent value.
The
format-offsetdocumentation should also be updated:We should also document the different supported formats for spacing and extends somewhere. Probably best to just add a section to the "Configuration" wiki page:
Sizes & Spacing
In many parts of the config, you can specify some kind of size (width, height, border) or spacing (margin, padding). These are very similar but all differ slightly. We differentiate between three types: spacing, extents, and "percentage with offset".
Spacing
Spacing can be specified as either a number of spaces (no unit), pixels (
px) or points (pt).For example:
Spaces are just added as whitespace characters, the size depends on the active font.
One point is 1/72th of an inch and is translated to a number of pixels according to the specified DPI.
Extent
Extent values are almost like spacing but don't support spaces, only pixels (no unit or
px) and points (pt).These are mainly used to described the size of something (and thus can't support spaces)
Percentage with Offset
A percentage with offset specifies the size of something using a relative percentage together with an extent value that is added to it.
For example:
This specifies a bar width of 90% minus 10 points. What exactly the percentage is relative to depends on the setting. For the bar width, it is relative to the width of the monitor.
Both the percentage value and the extent value can also be specified on their own:
We need to update the wiki to mention what kind of format is allowed in the following places:
Spacing
ramp-coreload-spacingin the CPU modulespacingin the FS modulepaddingandmodule-marginin the bar sectionExtent
format-offsetPercentage with offset
[global/wm])tray-offset-*