diff options
author | Marvin W <git@larma.de> | 2020-03-14 00:24:41 +0100 |
---|---|---|
committer | Marvin W <git@larma.de> | 2020-03-14 00:50:54 +0100 |
commit | d55f6691c68757d2c8f7a361c20ace8dac61da5c (patch) | |
tree | 7877aabb3e6a2c7acf746546226d54b10d5db637 /main/src/ui/util/sizing_bin.vala | |
parent | 25751c88ced9d312aef22135ee2f68c2edb71b7e (diff) | |
download | dino-d55f6691c68757d2c8f7a361c20ace8dac61da5c.tar.gz dino-d55f6691c68757d2c8f7a361c20ace8dac61da5c.zip |
Scale files and images to the available space
Diffstat (limited to 'main/src/ui/util/sizing_bin.vala')
-rw-r--r-- | main/src/ui/util/sizing_bin.vala | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/main/src/ui/util/sizing_bin.vala b/main/src/ui/util/sizing_bin.vala new file mode 100644 index 00000000..b81ff7e3 --- /dev/null +++ b/main/src/ui/util/sizing_bin.vala @@ -0,0 +1,35 @@ +using Gtk; + +namespace Dino.Ui { +class SizingBin : Bin { + public int min_width { get; set; default = -1; } + public int target_width { get; set; default = -1; } + public int max_width { get; set; default = -1; } + public int min_height { get; set; default = -1; } + public int target_height { get; set; default = -1; } + public int max_height { get; set; default = -1; } + + public override void size_allocate(Allocation allocation) { + if (max_height != -1) allocation.height = int.min(allocation.height, max_height); + if (max_width != -1) allocation.width = int.min(allocation.width, max_width); + base.size_allocate(allocation); + } + + public override void get_preferred_width(out int minimum_width, out int natural_width) { + base.get_preferred_width(out minimum_width, out natural_width); + if (min_width != -1) minimum_width = int.max(minimum_width, min_width); + if (max_width != -1) natural_width = int.min(natural_width, max_width); + if (target_width != -1) natural_width = int.max(natural_width, target_width); + natural_width = int.max(natural_width, minimum_width); + } + + public override void get_preferred_height_for_width(int width, out int minimum_height, out int natural_height) { + base.get_preferred_height_for_width(width, out minimum_height, out natural_height); + if (min_height != -1) minimum_height = int.max(minimum_height, min_height); + if (max_height != -1) natural_height = int.min(natural_height, max_height); + if (target_height != -1) natural_height = int.max(natural_height, target_height); + natural_height = int.max(natural_height, minimum_height); + } + +} +}
\ No newline at end of file |