Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions src/codex32_gui/pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from dataclasses import dataclass
from typing import Literal

from gi.repository import Adw, Gio, GLib, Gtk
from gi.repository import Adw, Gio, GLib, Gtk, Pango

from codex32 import (
ConfirmationResult,
Expand Down Expand Up @@ -111,6 +111,7 @@ def _page(
) -> Adw.NavigationPage:
scroller = Gtk.ScrolledWindow(hscrollbar_policy=Gtk.PolicyType.NEVER, vexpand=True)
scroller.set_child(Adw.Clamp(maximum_size=700, child=content, margin_start=18, margin_end=18))
scroller.get_vadjustment().connect("changed", lambda shown: _grow(scroller, shown))
bars = Adw.ToolbarView()
bars.add_top_bar(Adw.HeaderBar())
bars.set_content(scroller)
Expand All @@ -121,6 +122,15 @@ def _page(
return page


def _grow(scroller: Gtk.ScrolledWindow, shown: Gtk.Adjustment) -> None:
"""Make the window taller, never past the screen, until the page needs no scrolling."""
window, short = scroller.get_root(), shown.get_upper() - shown.get_page_size()
if short > 0 and isinstance(window, Gtk.Window) and (surface := window.get_surface()) is not None:
width, height = window.get_default_size()
screen = window.get_display().get_monitor_at_surface(surface).get_geometry().height
window.set_default_size(width, min(height + int(short) + 1, screen))


def _column(*children: Gtk.Widget) -> Gtk.Box:
box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=14, margin_top=18, margin_bottom=18)
for child in children:
Expand Down Expand Up @@ -215,9 +225,11 @@ def _blank(flow: Gtk.FlowBox) -> None:


def _rows(title: str, values: Sequence[tuple[str, str]]) -> Adw.PreferencesGroup:
group = Adw.PreferencesGroup(title=title)
group = Adw.PreferencesGroup(title=title, css_classes=["compact"])
for label, value in values:
group.add(Adw.ActionRow(title=label, subtitle=value, subtitle_selectable=True, use_markup=False))
row = Adw.ActionRow(title=label, use_markup=False)
row.add_suffix(Gtk.Label(label=value, selectable=True, wrap=True, wrap_mode=Pango.WrapMode.WORD_CHAR))
group.add(row)
return group


Expand Down
5 changes: 5 additions & 0 deletions src/codex32_gui/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
border-radius: 12px;
padding: 14px;
}
.compact row > box.header {
min-height: 0;
padding-top: 0;
padding-bottom: 0;
}
.reading {
font-size: 0.9rem;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/test_gui_boundaries.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
}
)
CORE_ADAPTER = "codex32._bitcoin_core"
BUDGET = 2050
BUDGET = 2063


def _package() -> Path:
Expand Down
Loading