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

DiskBar: add constraint guide #816

Merged
merged 9 commits into from
Oct 13, 2024
43 changes: 33 additions & 10 deletions src/Widgets/DiskBar.vala
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ public class Installer.DiskBar: Gtk.Box {
public Gee.ArrayList<PartitionBlock> partitions { get; construct; }
public uint64 size { get; construct; }

private Gtk.ConstraintGuide guide;

public PartitionContainer (uint64 size, Gee.ArrayList<PartitionBlock> partitions) {
Object (
partitions: partitions,
Expand All @@ -81,6 +83,28 @@ public class Installer.DiskBar: Gtk.Box {
}

construct {
guide = new Gtk.ConstraintGuide () {
max_width = 300,
min_width = 300,
nat_width = 600
};

var layout_manager = ((Gtk.ConstraintLayout) get_layout_manager ());
layout_manager.add_guide (guide);

layout_manager.add_constraint (
new Gtk.Constraint (
guide,
HEIGHT,
EQ,
this,
HEIGHT,
1.0,
0.0,
Gtk.ConstraintStrength.REQUIRED
)
);

uint64 used = 0;
var disk_sectors = size / 512;
foreach (var partition in partitions) {
Expand All @@ -100,17 +124,16 @@ public class Installer.DiskBar: Gtk.Box {
var unused_bar = new Block ();
unused_bar.add_css_class ("unused");

append_partition (unused_bar, unused / size);
append_partition (unused_bar, (double) unused / size);
}

var layout_manager = ((Gtk.ConstraintLayout) get_layout_manager ());
// Position last child at end
layout_manager.add_constraint (
new Gtk.Constraint (
get_last_child (),
null,
END,
EQ,
this,
get_last_child (),
END,
1.0,
0.0,
Expand All @@ -136,7 +159,7 @@ public class Installer.DiskBar: Gtk.Box {
widget,
HEIGHT,
EQ,
this,
guide,
HEIGHT,
1.0,
0.0,
Expand All @@ -150,7 +173,7 @@ public class Installer.DiskBar: Gtk.Box {
widget,
WIDTH,
EQ,
this,
guide,
WIDTH,
percentage,
0,
Expand All @@ -163,10 +186,10 @@ public class Installer.DiskBar: Gtk.Box {
// Position at start
layout_manager.add_constraint (
new Gtk.Constraint (
widget,
null,
START,
EQ,
this,
widget,
START,
1.0,
0.0,
Expand All @@ -182,8 +205,8 @@ public class Installer.DiskBar: Gtk.Box {
EQ,
previous_child,
END,
1.0,
0.0,
1,
0,
Gtk.ConstraintStrength.REQUIRED
)
);
Expand Down