Make header narrower, move right_icon into header.

This commit is contained in:
Michael Hudson-Doyle 2019-09-25 13:29:44 +12:00
parent d8d5b2e265
commit a96c5c8805
5 changed files with 40 additions and 67 deletions

View File

@ -36,6 +36,7 @@ COLORS = [
]
STYLES = [
('frame_header_fringe', 'orange', 'bg'),
('frame_header', 'fg', 'orange'),
('frame_footer', 'fg', 'brand'),
('body', 'fg', 'bg'),

View File

@ -490,7 +490,6 @@ class FilesystemView(BaseView):
if not todos:
return None
rows = [
TableRow([Text("")]),
TableRow([
Text("To continue you need to:"),
Text(todos[0]),
@ -498,6 +497,7 @@ class FilesystemView(BaseView):
]
for todo in todos[1:]:
rows.append(TableRow([Text(""), Text(todo)]))
rows.append(TableRow([Text("")]))
return TablePile(rows)
def _build_buttons(self):

View File

@ -16,8 +16,9 @@
import logging
from urwid import (
int_scale,
SolidFill,
Text,
ProgressBar,
)
from subiquitycore.ui.container import (
@ -25,83 +26,54 @@ from subiquitycore.ui.container import (
Pile,
WidgetWrap,
)
from subiquitycore.ui.utils import Padding, Color
from subiquitycore.ui.utils import Color
from subiquitycore.ui.width import widget_width
log = logging.getLogger('subiquitycore.ui.anchors')
class Header(WidgetWrap):
""" Header Widget
This widget uses the style key `frame_header`
:param str title: Title of Header
:returns: Header()
"""
def __init__(self, title):
if isinstance(title, str):
title = Text(title)
title = Padding.center_79(title, min_width=76)
super().__init__(Color.frame_header(
Pile(
[Text(""), title, Text("")])))
class StepsProgressBar(ProgressBar):
def get_text(self):
return "{} / {}".format(self.current, self.done)
class MyColumns(Columns):
class HeaderColumns(Columns):
# The idea is to render output like this:
#
# message [ help ]
# [ lpad ][ middle ][ rpad ][ right ]
# [ pad ][ message ][ btn ][ pad ]
#
# The constraints are:
#
# 1. lpad + rpad + right + message = maxcol
# 1. pad + message + btn + pad = maxcol
#
# 2. lpad and rpad are at least 1
# 2. pad is at least 1
#
# 3. right is fixed
# 3. btn is fixed
#
# 4. if possible, lpad = rpad + right and middle is 79% of maxcol
# or 76, whichever is greater.
# 4. message + btn is 79% of maxcol or 76, whichever is greater.
def column_widths(self, size, focus=False):
maxcol = size[0]
right = widget_width(self.contents[3][0])
btn = widget_width(self.contents[2][0])
center = max(79*maxcol//100, 76)
lpad = (maxcol - center)//2
rpad = lpad - right
if rpad < 1:
rpad = 1
middle = maxcol - (lpad + rpad + right)
return [lpad, middle, rpad, right]
center = max(int_scale(79, 101, maxcol + 1), 76)
message = center - btn
pad = (maxcol - center)//2
return [pad, message, btn, pad]
class Footer(WidgetWrap):
""" Footer widget
class Header(WidgetWrap):
""" Header Widget """
Style key: `frame_footer`
"""
def __init__(self, message, right_icon, current, complete):
if isinstance(message, str):
message = Text(message)
progress_bar = Padding.center_60(
StepsProgressBar(normal='progress_incomplete',
complete='progress_complete',
current=current, done=complete))
status = [
progress_bar,
Padding.line_break(""),
MyColumns([Text(""), message, Text(""), right_icon]),
]
super().__init__(Color.frame_footer(Pile(status)))
def __init__(self, title, right_icon):
if isinstance(title, str):
title = Text(title)
title = HeaderColumns([
Text(""),
title,
right_icon,
Text(""),
])
super().__init__(
Pile([
(1, Color.frame_header_fringe(
SolidFill("\N{lower half block}"))),
Color.frame_header(title),
(1, Color.frame_header_fringe(
SolidFill("\N{upper half block}"))),
]))

View File

@ -37,7 +37,7 @@ class SubiquityCoreUI(WidgetWrap):
right_icon = Text("")
def __init__(self):
self.header = Header("")
self.header = Header("", self.right_icon)
self.pile = Pile([
('pack', self.header),
ListBox([Text("")]),
@ -48,7 +48,7 @@ class SubiquityCoreUI(WidgetWrap):
self.pile.contents[i] = (w, self.pile.contents[i][1])
def set_header(self, title=None):
self._assign_contents(0, Header(title))
self._assign_contents(0, Header(title, self.right_icon))
def set_footer(self, message):
pass

View File

@ -153,6 +153,7 @@ STYLE_NAMES = set([
'done_button',
'frame_footer',
'frame_header',
'frame_header_fringe',
'info_error',
'info_minor',
'info_primary',
@ -245,11 +246,10 @@ def screen(rows, buttons=None, focus_buttons=True, excerpt=None,
excerpt_rows = []
if excerpt is not None:
excerpt_rows = [
('pack', Text("")),
('pack', Text(excerpt)),
('pack', Text("")),
]
body = [
('pack', Text("")),
rows,
('pack', Text("")),
]
@ -260,7 +260,7 @@ def screen(rows, buttons=None, focus_buttons=True, excerpt=None,
])
pile = Pile(excerpt_rows + body)
if focus_buttons:
pile.focus_position = len(excerpt_rows) + 3
pile.focus_position = len(excerpt_rows) + 2
return Padding.center_79(pile, min_width=76)