Skip to content

Commit

Permalink
Refactor ViewMono to include AppBar, title, subtitle, and various U…
Browse files Browse the repository at this point in the history
…I elements

- Added properties for title, subtitle, title widget, and visibility of title buttons.
- Introduced `Gtk.Stack` and `Gtk.ScrolledWindow` properties.
- Implemented margin handling for the view child.
- Enhanced `add_child` method to support different child types.
- Updated constructor and static construct block to initialize new components and layout.
  • Loading branch information
lainsce committed Aug 31, 2024
1 parent 0d106ca commit 5162fd7
Showing 1 changed file with 192 additions and 6 deletions.
198 changes: 192 additions & 6 deletions lib/Widgets/ViewMono.vala
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

/*
* Copyright (c) 2022 Fyra Labs
* Copyright (c) 2024 Fyra Labs
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand All @@ -19,11 +18,198 @@
*/

/**
* A ViewMono is a view that is a single-column layout.
*
* @since 1.0
* A ViewMono is a component containing its own AppBar, title, subtitle, and elements.
*/
public class He.ViewMono : He.View {
public class He.ViewMono : He.Bin, Gtk.Buildable {
private He.AppBar titlebar = new He.AppBar ();
private Gtk.Box box = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);

/**
* The title of the sidebar.
*/
public string title {
get {
return titlebar.viewtitle_label;
}
set {
if (value != "" && titlewidget == null) {
titlebar.viewtitle_label = value;
} else {
titlebar.viewtitle_label = null;
}
}
}

/**
* The title widget of the sidebar.
*/
public Gtk.Widget? titlewidget {
get {
return titlebar.viewtitle_widget;
}
set {
if (value != null) {
titlebar.viewtitle_widget = value;
} else {
titlebar.viewtitle_widget = null;
}
}
}

/**
* The title of the sidebar.
*/
public string subtitle {
get {
return titlebar.viewsubtitle_label;
}
set {
if (value != "") {
titlebar.viewsubtitle_label = value;
} else {
titlebar.viewsubtitle_label = null;
}
}
}

private bool _show_right_title_buttons;
/**
* Whether the ViewMono should show the buttons.
*/
public bool show_right_title_buttons {
get {
return _show_right_title_buttons;
}
set {
_show_right_title_buttons = value;

titlebar.show_right_title_buttons = _show_right_title_buttons;
}
}

private bool _show_left_title_buttons;
/**
* Whether the ViewMono should show the buttons.
*/
public bool show_left_title_buttons {
get {
return _show_left_title_buttons;
}
set {
_show_left_title_buttons = value;

titlebar.show_left_title_buttons = _show_left_title_buttons;
}
}

private bool _show_back;
/**
* Whether the back button should be shown.
*/
public bool show_back {
get {
return _show_back;
}
set {
_show_back = value;

titlebar.show_back = _show_back;
}
}

private Gtk.Stack _stack;
/**
* The stack that the ViewMono's AppBar is attached to.
*/
public Gtk.Stack stack {
get {
return _stack;
}

set {
_stack = value;
titlebar.stack = _stack;
}
}

private Gtk.ScrolledWindow _scroller;
/**
* The stack that the ViewMono's AppBar is attached to.
*/
public Gtk.ScrolledWindow scroller {
get {
return _scroller;
}

set {
_scroller = value;
titlebar.scroller = _scroller;
}
}

/**
* Whether the view child has margins or is full-bleed.
*/
public bool has_margins {
get {
return box.margin_top > 0 ||
box.margin_bottom > 0 ||
box.margin_start > 0 ||
box.margin_end > 0;
}
set {
box.margin_bottom = value ? 12 : 0;
box.margin_end = value ? 18 : 0;
box.margin_start = value ? 18 : 0;
}
}

/**
* Create a new ViewMono.
* @param title The title of the ViewMono.
* @param subtitle The subtitle of the ViewMono.
*/
public ViewMono (string title, string subtitle) {
base ();
this.title = title;
this.subtitle = subtitle;
}

/**
* 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.
*
* @since 1.0
*/
public new void add_child (Gtk.Builder builder, GLib.Object child, string? type) {
if (type == "titlebar-button") {
titlebar.append ((Gtk.Widget) child);
} else if (type == "titlebar-menu") {
titlebar.append_menu ((Gtk.Widget) child);
} else if (type == "titlebar-toggle") {
titlebar.append_toggle ((Gtk.Widget) child);
} else {
box.append ((Gtk.Widget) child);
}
}

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

construct {
this.hexpand = false;
this.hexpand_set = true;
has_margins = true;

box.orientation = Gtk.Orientation.VERTICAL;

var main_box = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);
main_box.hexpand = true;
main_box.append (titlebar);
main_box.append (box);

main_box.set_parent (this);

this.add_css_class ("main-view");
}
}

0 comments on commit 5162fd7

Please sign in to comment.