Skip to content

Commit

Permalink
Fix alignment in hierarchical views
Browse files Browse the repository at this point in the history
Leverage GtkTreeExpander's ability to handle indentation
both for tags in the sidebar and tasks in the task list.
Create a children_count property for the Tag class so
that the expander can bind to it.

This fixes GitHub issue #1042
  • Loading branch information
gycsaba96 authored and diegogangl committed Apr 16, 2024
1 parent 13870dd commit 23a9868
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 47 deletions.
10 changes: 10 additions & 0 deletions GTG/core/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ def __eq__(self, other) -> bool:
return self.id == other.id


@GObject.Property(type=int)
def children_count(self) -> str:
"""Read only property."""

return len(self.children)


@GObject.Property(type=str)
def name(self) -> str:
"""Read only property."""
Expand Down Expand Up @@ -362,6 +369,7 @@ def add(self, item: Any, parent_id: UUID = None) -> None:
self.model.append(item)

self.emit('added', item)
if parent_id: self.lookup[parent_id].notify('children_count')


def parent(self, item_id: UUID, parent_id: UUID) -> None:
Expand All @@ -370,6 +378,7 @@ def parent(self, item_id: UUID, parent_id: UUID) -> None:
item = self.lookup[item_id]
pos = self.model.find(item)
self.model.remove(pos[1])
if parent_id: self.lookup[parent_id].notify('children_count')



Expand All @@ -378,3 +387,4 @@ def unparent(self, item_id: UUID, parent_id: UUID) -> None:
super().unparent(item_id, parent_id)
item = self.lookup[item_id]
self.model.append(item)
if parent_id: self.lookup[parent_id].notify('children_count')
22 changes: 4 additions & 18 deletions GTG/gtk/browser/sidebar.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,8 @@ def tags_setup_cb(self, factory, listitem, user_data=None) -> None:

expander.set_margin_end(6)
expander.add_css_class('arrow-only-expander')
expander.set_indent_for_icon(True)
expander.set_indent_for_depth(True)
icon.set_margin_end(6)
color.set_margin_end(6)
color.set_size_request(16, 16)
Expand Down Expand Up @@ -375,31 +377,15 @@ def tags_bind_cb(self, signallistitem, listitem, user_data=None) -> None:
item.bind_property('task_count_open', open_count_label, 'label', BIND_FLAGS),
item.bind_property('task_count_actionable', actionable_count_label, 'label', BIND_FLAGS),
item.bind_property('task_count_closed', closed_count_label, 'label', BIND_FLAGS),

item.bind_property('children_count',expander,'hide-expander',BIND_FLAGS, lambda _,x: x==0),
]

self.browser.bind_property('is_pane_open', open_count_label, 'visible', BIND_FLAGS)
self.browser.bind_property('is_pane_actionable', actionable_count_label, 'visible', BIND_FLAGS)
self.browser.bind_property('is_pane_closed', closed_count_label, 'visible', BIND_FLAGS)


if item.parent:
parent = item
depth = 0

while parent.parent:
depth += 1
parent = parent.parent

box.set_margin_start((18 * depth) + 16)
else:
box.set_margin_start(18)

if not item.children:
expander.set_visible(False)
else:
expander.set_visible(True)


def tags_unbind_cb(self, signallistitem, listitem, user_data=None) -> None:
"""Clean up bindings made in tags_bind_cb"""
for binding in listitem.bindings:
Expand Down
27 changes: 3 additions & 24 deletions GTG/gtk/browser/task_pane.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ def __init__(self, config, is_actionable=False):
self.expander = Gtk.TreeExpander()
self.expander.set_margin_end(6)
self.expander.add_css_class('arrow-only-expander')
self.expander.set_indent_for_icon(True)
self.expander.set_indent_for_depth(True)

self.check = Gtk.CheckButton()
self.check.set_margin_end(6)
Expand All @@ -60,30 +62,6 @@ def set_has_children(self, value) -> bool:

if self.is_actionable:
value = False

self.expander.set_visible(value)

if value:
widget = self.expander
else:
widget = self.check

check_width = 21
margin = 6

indent = margin if value else (check_width + margin)

if self.task.parent and not self.is_actionable:
parent = self.task
depth = 0

while parent.parent:
depth += 1
parent = parent.parent

widget.set_margin_start(indent + (21 * depth))
else:
widget.set_margin_start(indent)


@GObject.Property(type=bool, default=True)
Expand Down Expand Up @@ -533,6 +511,7 @@ def show_start(binding, value, user_data=None):

listitem.bindings = [
item.bind_property('has_children', box, 'has_children', BIND_FLAGS),
item.bind_property('has_children', expander, 'hide-expander', BIND_FLAGS,lambda _,x: not x),

item.bind_property('title', label, 'label', BIND_FLAGS),
item.bind_property('excerpt', box, 'tooltip-text', BIND_FLAGS),
Expand Down
6 changes: 1 addition & 5 deletions GTG/gtk/data/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,6 @@ textview check {
border-spacing: 0;
}

.arrow-only-expander indent {
-gtk-icon-size: 0px;
}

.closed-task {
opacity: 0.5;
}
}

0 comments on commit 23a9868

Please sign in to comment.