Skip to content

Commit

Permalink
Add back button and stack support to BottomSheet, enhance ViewMono, a…
Browse files Browse the repository at this point in the history
…nd fix ContentBlockImage measure method

- Replaced `He.ViewSubTitle` with `Gtk.Label` for `title_label` in `BottomSheet`.
- Added `back_button` to `BottomSheet` for stack navigation.
- Introduced `sheet_stack` property in `BottomSheet` to handle stack-type content.
- Adjusted `handle_wh` margins based on `show_handle` visibility in `BottomSheet`.
- Enhanced `ViewMono` with methods to add titlebar buttons, menus, and toggles.
- Fixed `measure` method in `ContentBlockImage` to handle out parameters correctly.
- Simplified `default_scheme_variant` property in `Application` model.
  • Loading branch information
lainsce committed Sep 2, 2024
1 parent 5162fd7 commit 1b13e10
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 13 deletions.
8 changes: 3 additions & 5 deletions lib/Models/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,7 @@ public class He.Application : Gtk.Application {
* A scheme variant to use for the application. If not set, the user's preferred scheme will be used.
* This is especially useful for applications with their own color needs, such as media applications using the Content variant.
*/
private SchemeVariant? _default_scheme_variant = null;
public SchemeVariant? default_scheme_variant {
get { return _default_scheme_variant; }
set { _default_scheme_variant = value; update_style_manager (); }
}
public SchemeVariant? default_scheme_variant = null;

private void update_style_manager () {
if (default_accent_color != null && override_accent_color) {
Expand All @@ -91,8 +87,10 @@ public class He.Application : Gtk.Application {

if (default_scheme_variant != null) {
style_manager.scheme_variant = default_scheme_variant;
update_style_manager ();
} else {
style_manager.scheme_variant = desktop.ensor_scheme.to_variant ();
update_style_manager ();
}

if (override_dark_style) {
Expand Down
56 changes: 52 additions & 4 deletions lib/Widgets/BottomSheet.vala
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class He.BottomSheet : Gtk.Widget {
private Gtk.Widget dimming;
private Gtk.Widget handle;
private Gtk.Box sheet_bin;
private He.ViewSubTitle title_label;
private Gtk.Label title_label;
private He.SpringAnimation show_animation;
private Gtk.WindowHandle handle_wh;
private GLib.TimeoutSource? resize_timeout;
Expand All @@ -46,6 +46,11 @@ public class He.BottomSheet : Gtk.Widget {
private int target_height = 0;
private int update_interval = 16; // Default for 60Hz

/**
* The back button in case of a stack-type content.
*/
public He.Button back_button;

/**
* The sheet to display (the content).
*/
Expand All @@ -63,6 +68,28 @@ public class He.BottomSheet : Gtk.Widget {
}
}

/**
* The sheet (as a stack) to display (the content).
*/
private Gtk.Stack? _sheet_stack;
public Gtk.Stack? sheet_stack {
get { return _sheet_stack; }
set {
if (sheet_stack == value)
return;

_sheet_stack = value;

sheet_stack.unparent (); // Avoiding stacked children
sheet_bin.append (sheet_stack);
if (value != null) {
back_button.set_visible (true);
} else {
back_button.set_visible (false);
}
}
}

/**
* The action button to use.
*/
Expand Down Expand Up @@ -148,6 +175,12 @@ public class He.BottomSheet : Gtk.Widget {

_show_handle = value;
handle.visible = value;

if (value) {
handle_wh.margin_top = 0;
} else {
handle_wh.margin_top = 24;
}
}
}

Expand Down Expand Up @@ -193,10 +226,11 @@ public class He.BottomSheet : Gtk.Widget {
gesture_drag.drag_update.connect (on_drag_update);
gesture_drag.drag_end.connect (on_drag_end);

title_label = new He.ViewSubTitle ();
title_label.valign = Gtk.Align.END;
title_label.halign = Gtk.Align.START;
title_label = new Gtk.Label ("");
title_label.valign = Gtk.Align.START;
title_label.halign = Gtk.Align.CENTER;
title_label.hexpand = true;
title_label.add_css_class ("view-subtitle");

var close_button = new He.Button ("window-close-symbolic", "");
close_button.is_disclosure = true;
Expand All @@ -206,7 +240,21 @@ public class He.BottomSheet : Gtk.Widget {
show_sheet = false;
});

back_button = new He.Button ("pan-start-symbolic", "");
back_button.is_disclosure = true;
back_button.set_visible (false);
back_button.valign = Gtk.Align.START;
back_button.halign = Gtk.Align.START;
back_button.clicked.connect (() => {
var selected_page = sheet_stack.pages.get_selection ();
sheet_stack.pages.select_item (int.max (((int) selected_page.get_nth (0) - 1), 0), true);
});
if (sheet_stack.pages.is_selected (0)) {
back_button.set_visible (false);
}

var title_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
title_box.append (back_button);
title_box.append (title_label);
title_box.append (close_button);

Expand Down
7 changes: 4 additions & 3 deletions lib/Widgets/ContentBlockImage.vala
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,15 @@ public class He.ContentBlockImage : He.Bin, Gtk.Buildable {
Object (file: file);
}

public override void measure (Gtk.Orientation orientation, int for_size, out int min, out int nat, out int min_b, out int nat_b) {
public override void measure (Gtk.Orientation orientation, int for_size, out int min, out int nat, out int min_b = null, out int nat_b = null) {
double min_width, min_height, nat_width, nat_height;
double default_size;

/* for_size = 0 below is treated as -1, but we want to return zeros. */
if (paintable == null || for_size == 0) {
min = 0;
nat = 0;
min_b = nat_b = -1;
return;
}

Expand All @@ -126,6 +127,7 @@ public class He.ContentBlockImage : He.Bin, Gtk.Buildable {
);
min = (int) Math.ceil (min_width);
nat = (int) Math.ceil (nat_width);
min_b = nat_b = -1;
} else {
paintable.compute_concrete_size (
0,
Expand All @@ -137,9 +139,8 @@ public class He.ContentBlockImage : He.Bin, Gtk.Buildable {
);
min = (int) Math.ceil (min_height);
nat = (int) Math.ceil (nat_height);
min_b = nat_b = -1;
}

min_b = nat_b = -1;
}

public override void snapshot (Gtk.Snapshot snapshot) {
Expand Down
38 changes: 37 additions & 1 deletion lib/Widgets/ViewMono.vala
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public class He.ViewMono : He.Bin, Gtk.Buildable {
}

/**
* Add a child to the sidebar, should only be used in the context of a UI or Blueprint file. There should be no need to use this method in code.
* Add a child to the view, should only be used in the context of a UI or Blueprint file. There should be no need to use this method in code.
*
* @since 1.0
*/
Expand All @@ -192,6 +192,42 @@ public class He.ViewMono : He.Bin, Gtk.Buildable {
}
}

/**
* Add a titlebar button to the view's appbar.
*
* @since 1.0
*/
public new void add_titlebar_button (Gtk.Button child) {
titlebar.append (child);
}

/**
* Add a titlebar menu to the view's appbar.
*
* @since 1.0
*/
public new void add_titlebar_menu (Gtk.MenuButton child) {
titlebar.append_menu (child);
}

/**
* Add a titlebar toggle to the view's appbar.
*
* @since 1.0
*/
public new void add_titlebar_toggle (Gtk.ToggleButton child) {
titlebar.append_toggle (child);
}

/**
* Add a child to the view.
*
* @since 1.0
*/
public new void append (Gtk.Widget child) {
box.append (child);
}

static construct {
set_layout_manager_type (typeof (Gtk.BoxLayout));
}
Expand Down

0 comments on commit 1b13e10

Please sign in to comment.