Skip to content

Commit

Permalink
AbstractInstallerView: DRY more layout (#782)
Browse files Browse the repository at this point in the history
  • Loading branch information
danirabbit authored Jun 5, 2024
1 parent 8ecb72c commit 457ba21
Show file tree
Hide file tree
Showing 12 changed files with 99 additions and 127 deletions.
39 changes: 24 additions & 15 deletions src/Views/AbstractInstallerView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public abstract class AbstractInstallerView : Gtk.Box {

public signal void cancel ();

protected Gtk.Grid content_area;
protected Gtk.Box title_area;
protected Gtk.Box content_area;
protected Gtk.Box action_box_start;
protected Gtk.Box action_box_end;

Expand All @@ -29,13 +30,20 @@ public abstract class AbstractInstallerView : Gtk.Box {
}

construct {
content_area = new Gtk.Grid () {
column_spacing = 12,
row_spacing = 12,
title_area = new Gtk.Box (VERTICAL, 12) {
valign = CENTER
};
title_area.get_style_context ().add_class (Granite.STYLE_CLASS_H2_LABEL);

content_area = new Gtk.Box (VERTICAL, 24);

var box = new Gtk.Box (HORIZONTAL, 12) {
homogeneous = true,
hexpand = true,
vexpand = true,
orientation = Gtk.Orientation.VERTICAL
};
box.add (title_area);
box.add (content_area);

action_box_end = new Gtk.Box (HORIZONTAL, 6) {
halign = END,
Expand All @@ -47,10 +55,7 @@ public abstract class AbstractInstallerView : Gtk.Box {
homogeneous = true
};

var action_area = new Gtk.Box (HORIZONTAL, 12) {
margin_start = 10,
margin_end = 10
};
var action_area = new Gtk.Box (HORIZONTAL, 12);
action_area.add (action_box_start);
action_area.get_style_context ().add_class ("button-box");

Expand All @@ -72,11 +77,15 @@ public abstract class AbstractInstallerView : Gtk.Box {
action_box_end.add (cancel_button);
}

orientation = VERTICAL;
spacing = 24;
margin_top = 12;
margin_bottom = 12;
add (content_area);
add (action_area);
var main_box = new Gtk.Box (VERTICAL, 24) {
margin_top = 12,
margin_end = 12,
margin_bottom = 12,
margin_start = 12
};
main_box.add (box);
main_box.add (action_area);

add (main_box);
}
}
16 changes: 7 additions & 9 deletions src/Views/CheckView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ public class Installer.CheckView : AbstractInstallerView {
var title_label = new Gtk.Label (_("Before Installing")) {
valign = Gtk.Align.START
};
title_label.get_style_context ().add_class (Granite.STYLE_CLASS_H2_LABEL);

var beta_view = new CheckView (
_("Pre-Release Version"),
Expand All @@ -71,16 +70,15 @@ public class Installer.CheckView : AbstractInstallerView {
);
specs_view.attach (get_comparison_grid (), 1, 2);

message_box = new Gtk.Box (Gtk.Orientation.VERTICAL, 32) {
valign = Gtk.Align.CENTER
message_box = new Gtk.Box (VERTICAL, 32) {
valign = CENTER,
vexpand = true
};

content_area.column_homogeneous = true;
content_area.margin_start = content_area.margin_end = 12;
content_area.valign = Gtk.Align.CENTER;
content_area.attach (image, 0, 0);
content_area.attach (title_label, 0, 1);
content_area.attach (message_box, 1, 0, 1, 2);
title_area.add (image);
title_area.add (title_label);

content_area.add (message_box);

var ignore_button = new Gtk.Button.with_label (_("Install Anyway"));
ignore_button.get_style_context ().add_class (Gtk.STYLE_CLASS_DESTRUCTIVE_ACTION);
Expand Down
27 changes: 8 additions & 19 deletions src/Views/DiskView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,11 @@ public class Installer.DiskView : AbstractInstallerView {

var image_overlay = new Gtk.Overlay () {
child = install_image,
valign = END
halign = CENTER
};
image_overlay.add_overlay (install_badge);

var install_label = new Gtk.Label (_("Select a Drive")) {
valign = Gtk.Align.START
};
install_label.get_style_context ().add_class (Granite.STYLE_CLASS_H2_LABEL);
var install_label = new Gtk.Label (_("Select a Drive"));

var install_desc_label = new Gtk.Label (
_("This will erase all data on the selected drive. If you have not backed your data up, you can cancel the installation and use Demo Mode.")
Expand Down Expand Up @@ -89,20 +86,12 @@ public class Installer.DiskView : AbstractInstallerView {
load_stack.add (load_box);
load_stack.add_named (disk_scrolled, "disk");

var title_grid = new Gtk.Grid () {
halign = Gtk.Align.CENTER,
valign = Gtk.Align.CENTER,
row_spacing = 12
};
title_grid.attach (image_overlay, 0, 0);
title_grid.attach (install_label, 0, 1);

content_area.margin_start = content_area.margin_end = 12;
content_area.column_homogeneous = true;
content_area.valign = Gtk.Align.CENTER;
content_area.attach (title_grid, 0, 0, 1, 2);
content_area.attach (install_desc_label, 1, 0);
content_area.attach (load_stack, 1, 1);
title_area.add (image_overlay);
title_area.add (install_label);

content_area.valign = CENTER;
content_area.add (install_desc_label);
content_area.add (load_stack);

next_button = new Gtk.Button.with_label (_("Next")) {
// Make sure we can skip this view in Test Mode
Expand Down
21 changes: 8 additions & 13 deletions src/Views/DriversView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,10 @@

construct {
var image = new Gtk.Image.from_icon_name ("application-x-firmware", Gtk.IconSize.INVALID) {
pixel_size = 128,
valign = Gtk.Align.END
pixel_size = 128
};

var title_label = new Gtk.Label (_("Additional Drivers")) {
valign = Gtk.Align.START
};
title_label.get_style_context ().add_class (Granite.STYLE_CLASS_H2_LABEL);
var title_label = new Gtk.Label (_("Additional Drivers"));

var description_label = new Gtk.Label (_("Broadcom® Wi-Fi adapters, NVIDIA® graphics, and some virtual machines may not function properly without additional drivers. Most devices do not require additional drivers.")) {
max_width_chars = 1, // Make Gtk wrap, but not expand the window
Expand Down Expand Up @@ -63,20 +59,19 @@
};

var message_box = new Gtk.Box (VERTICAL, 32) {
valign = CENTER
valign = CENTER,
vexpand = true
};
message_box.add (description_label);
message_box.add (warning_row);
message_box.add (internet_row);
message_box.add (install_later_row);
message_box.add (drivers_check);

content_area.column_homogeneous = true;
content_area.margin_start = content_area.margin_end = 12;
content_area.valign = Gtk.Align.CENTER;
content_area.attach (image, 0, 0);
content_area.attach (title_label, 0, 1);
content_area.attach (message_box, 1, 0, 1, 2);
title_area.add (image);
title_area.add (title_label);

content_area.add (message_box);

var back_button = new Gtk.Button.with_label (_("Back"));
back_button.clicked.connect (() => ((Hdy.Deck) get_parent ()).navigate (BACK));
Expand Down
16 changes: 5 additions & 11 deletions src/Views/EncryptView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,11 @@ public class EncryptView : AbstractInstallerView {
var overlay = new Gtk.Overlay () {
child = image,
halign = CENTER,
valign = END,
width_request = 60
};
overlay.add_overlay (overlay_image);

var title_label = new Gtk.Label (_("Enable Drive Encryption")) {
valign = Gtk.Align.START
};
title_label.get_style_context ().add_class (Granite.STYLE_CLASS_H2_LABEL);
var title_label = new Gtk.Label (_("Enable Drive Encryption"));

var details_label = new Gtk.Label (_("Encrypt this device's drive if required for added protection, but be sure you understand:")) {
hexpand = true,
Expand Down Expand Up @@ -141,12 +137,10 @@ public class EncryptView : AbstractInstallerView {
stack.add (description_box);
stack.add (password_box);

content_area.column_homogeneous = true;
content_area.margin_end = 12;
content_area.margin_start = 12;
content_area.attach (overlay, 0, 0);
content_area.attach (title_label, 0, 1);
content_area.attach (stack, 1, 0, 1, 2);
title_area.add (overlay);
title_area.add (title_label);

content_area.add (stack);

var back_button = new Gtk.Button.with_label (_("Back"));

Expand Down
17 changes: 6 additions & 11 deletions src/Views/ErrorView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,10 @@ public class ErrorView : AbstractInstallerView {

construct {
var image = new Gtk.Image.from_icon_name ("dialog-error", Gtk.IconSize.DIALOG) {
pixel_size = 128,
valign = Gtk.Align.END
pixel_size = 128
};

var title_label = new Gtk.Label (_("Could Not Install")) {
valign = Gtk.Align.START
};
title_label.get_style_context ().add_class (Granite.STYLE_CLASS_H2_LABEL);
var title_label = new Gtk.Label (_("Could Not Install"));

var description_label = new Gtk.Label (_("Installing %s failed, possibly due to a hardware error. The device may not restart properly. You can try the following:").printf (Utils.get_pretty_name ())) {
margin_bottom = 12,
Expand Down Expand Up @@ -112,11 +108,10 @@ public class ErrorView : AbstractInstallerView {
grid.attach (terminal_button, 0, 4, 2);
grid.attach (terminal_revealer, 0, 5, 2);

content_area.column_homogeneous = true;
content_area.margin_start = content_area.margin_end = 12;
content_area.attach (image, 0, 0);
content_area.attach (title_label, 0, 1);
content_area.attach (grid, 1, 0, 1, 2);
title_area.add (image);
title_area.add (title_label);

content_area.add (grid);

var restart_button = new Gtk.Button.with_label (_("Restart Device"));

Expand Down
11 changes: 4 additions & 7 deletions src/Views/KeyboardLayoutView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public class KeyboardLayoutView : AbstractInstallerView {
var title_label = new Gtk.Label (_("Select Keyboard Layout")) {
valign = Gtk.Align.START
};
title_label.get_style_context ().add_class (Granite.STYLE_CLASS_H2_LABEL);

input_variant_widget = new VariantWidget ();

Expand All @@ -45,12 +44,10 @@ public class KeyboardLayoutView : AbstractInstallerView {
stack_box.add (input_variant_widget);
stack_box.add (keyboard_test_entry);

content_area.column_homogeneous = true;
content_area.margin_end = 12;
content_area.margin_start = 12;
content_area.attach (image, 0, 0);
content_area.attach (title_label, 0, 1);
content_area.attach (stack_box, 1, 0, 1, 2);
title_area.add (image);
title_area.add (title_label);

content_area.add (stack_box);

var back_button = new Gtk.Button.with_label (_("Back"));

Expand Down
11 changes: 4 additions & 7 deletions src/Views/LanguageView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public class Installer.LanguageView : AbstractInstallerView {

select_stack = new Gtk.Stack ();
select_stack.valign = Gtk.Align.START;
select_stack.get_style_context ().add_class (Granite.STYLE_CLASS_H2_LABEL);
select_stack.transition_type = Gtk.StackTransitionType.CROSSFADE;
select_stack.add (select_label);

Expand Down Expand Up @@ -165,12 +164,10 @@ public class Installer.LanguageView : AbstractInstallerView {
lang_variant_widget.main_listbox.row_selected.disconnect (row_selected);
});

content_area.column_homogeneous = true;
content_area.margin_end = 10;
content_area.margin_start = 10;
content_area.attach (image, 0, 0, 1, 1);
content_area.attach (select_stack, 0, 1, 1, 1);
content_area.attach (lang_variant_widget, 1, 0, 1, 2);
title_area.add (image);
title_area.add (select_stack);

content_area.add (lang_variant_widget);

timeout ();
}
Expand Down
12 changes: 7 additions & 5 deletions src/Views/PartitioningView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ public class Installer.PartitioningView : AbstractInstallerView {
luks = new Gee.ArrayList<InstallerDaemon.LuksCredentials?> ();

var title_label = new Gtk.Label (_("Select Partitions"));
title_label.get_style_context ().add_class (Granite.STYLE_CLASS_H2_LABEL);

var format_row = new DescriptionRow (
_("Selecting “Format” will erase <i>all</i> data on the selected partition."),
Expand Down Expand Up @@ -101,7 +100,8 @@ public class Installer.PartitioningView : AbstractInstallerView {
var disk_scroller = new Gtk.ScrolledWindow (null, null) {
child = disk_list,
hexpand = true,
hscrollbar_policy = NEVER
hscrollbar_policy = NEVER,
propagate_natural_height = true
};

var load_spinner = new Gtk.Spinner () {
Expand All @@ -128,9 +128,11 @@ public class Installer.PartitioningView : AbstractInstallerView {
load_stack.add_named (load_box, "loading");
load_stack.add_named (disk_scroller, "disk");

content_area.attach (title_label, 0, 0);
content_area.attach (description_box, 0, 1);
content_area.attach (load_stack, 0, 2);
title_area.add (title_label);

content_area.valign = CENTER;
content_area.add (description_box);
content_area.add (load_stack);

load_disks.begin ();

Expand Down
13 changes: 10 additions & 3 deletions src/Views/ProgressView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

public class ProgressView : AbstractInstallerView {
public class ProgressView : Gtk.Box {
public signal void on_success ();
public signal void on_error ();

Expand Down Expand Up @@ -87,13 +87,20 @@ public class ProgressView : AbstractInstallerView {
hexpand = true
};

content_area.margin_end = 12;
content_area.margin_start = 12;
var content_area = new Gtk.Grid () {
margin_top = 12,
margin_end = 12,
margin_bottom = 12,
margin_start = 12,
row_spacing = 12
};
content_area.attach (logo_stack, 0, 0, 2);
content_area.attach (progressbar_label, 0, 1);
content_area.attach (terminal_button, 1, 1);
content_area.attach (progressbar, 0, 2, 2);

add (content_area);

terminal_button.toggled.connect (() => {
if (terminal_button.active) {
terminal_button.tooltip_text = _("Hide log");
Expand Down
Loading

0 comments on commit 457ba21

Please sign in to comment.