mirror of
https://github.com/rr-/pq-cli.git
synced 2026-09-29 06:44:00 -06:00
ui: change paddings in game view
This commit is contained in:
@@ -33,12 +33,32 @@ class DataTable(NPile):
|
|||||||
(urwid.PACK, 1),
|
(urwid.PACK, 1),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self.resize_columns()
|
||||||
self._rows.append(widgets)
|
self._rows.append(widgets)
|
||||||
|
|
||||||
def delete_row(self, idx: int) -> None:
|
def delete_row(self, idx: int) -> None:
|
||||||
del self.contents[idx]
|
del self.contents[idx]
|
||||||
del self._rows[idx]
|
del self._rows[idx]
|
||||||
|
self.resize_columns()
|
||||||
|
|
||||||
def delete_rows(self, start_idx: int, end_idx: int) -> None:
|
def delete_rows(self, start_idx: int, end_idx: int) -> None:
|
||||||
del self.contents[start_idx:end_idx]
|
del self.contents[start_idx:end_idx]
|
||||||
del self._rows[start_idx:end_idx]
|
del self._rows[start_idx:end_idx]
|
||||||
|
self.resize_columns()
|
||||||
|
|
||||||
|
def resize_columns(self) -> None:
|
||||||
|
if not self._rows:
|
||||||
|
return
|
||||||
|
|
||||||
|
for i, sizing in enumerate(self._columns):
|
||||||
|
if isinstance(sizing, tuple) and sizing[0] == urwid.PACK:
|
||||||
|
width = max(
|
||||||
|
row_widgets[i].pack()[0] for row_widgets in self._rows
|
||||||
|
)
|
||||||
|
for item in self.contents:
|
||||||
|
columns = item[0]
|
||||||
|
columns.contents[i] = (
|
||||||
|
columns.contents[i][0],
|
||||||
|
(urwid.GIVEN, width, None),
|
||||||
|
)
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ class CharacterSheetView(DoubleLineBox):
|
|||||||
self.stat_texts = {stat: urwid.Text("") for stat in list(StatType)}
|
self.stat_texts = {stat: urwid.Text("") for stat in list(StatType)}
|
||||||
self.exp_bar = CustomProgressBar()
|
self.exp_bar = CustomProgressBar()
|
||||||
|
|
||||||
data_table = DataTable(columns=[(urwid.WEIGHT, 1), (urwid.WEIGHT, 1)])
|
data_table = DataTable(columns=[(urwid.WEIGHT, 1), (urwid.WEIGHT, 2)])
|
||||||
data_table.add_row(urwid.Text("Name"), urwid.Text(player.name))
|
data_table.add_row(urwid.Text("Name"), urwid.Text(player.name))
|
||||||
data_table.add_row(urwid.Text("Race"), urwid.Text(player.race.name))
|
data_table.add_row(urwid.Text("Race"), urwid.Text(player.race.name))
|
||||||
data_table.add_row(urwid.Text("Class"), urwid.Text(player.class_.name))
|
data_table.add_row(urwid.Text("Class"), urwid.Text(player.class_.name))
|
||||||
@@ -82,9 +82,7 @@ class SpellBookView(CustomLineBox):
|
|||||||
self.player.spell_book.connect("add", self.sync_spell_add)
|
self.player.spell_book.connect("add", self.sync_spell_add)
|
||||||
self.player.spell_book.connect("change", self.sync_spell_change)
|
self.player.spell_book.connect("change", self.sync_spell_change)
|
||||||
|
|
||||||
super().__init__(
|
super().__init__(ScrollBar(self.scrollable), title="Spell Book")
|
||||||
ScrollBar(self.scrollable, padding=1), title="Spell Book"
|
|
||||||
)
|
|
||||||
self.sync()
|
self.sync()
|
||||||
|
|
||||||
def sync(self) -> None:
|
def sync(self) -> None:
|
||||||
@@ -102,6 +100,7 @@ class SpellBookView(CustomLineBox):
|
|||||||
for row_widgets in self.data_table.data_rows:
|
for row_widgets in self.data_table.data_rows:
|
||||||
if row_widgets[0].text == spell.name:
|
if row_widgets[0].text == spell.name:
|
||||||
row_widgets[1].set_text(to_roman(spell.level))
|
row_widgets[1].set_text(to_roman(spell.level))
|
||||||
|
self.data_table.resize_columns()
|
||||||
|
|
||||||
|
|
||||||
class EquipmentView(CustomLineBox):
|
class EquipmentView(CustomLineBox):
|
||||||
@@ -139,7 +138,7 @@ class InventoryView(DoubleLineBox):
|
|||||||
def __init__(self, player: Player) -> None:
|
def __init__(self, player: Player) -> None:
|
||||||
self.player = player
|
self.player = player
|
||||||
|
|
||||||
self.gold_text = urwid.Text("")
|
self.gold_text = urwid.Text("", align=urwid.RIGHT)
|
||||||
self.data_table = DataTable(columns=[(urwid.WEIGHT, 3), (urwid.PACK,)])
|
self.data_table = DataTable(columns=[(urwid.WEIGHT, 3), (urwid.PACK,)])
|
||||||
self.data_table.add_row(urwid.Text("Gold"), self.gold_text)
|
self.data_table.add_row(urwid.Text("Gold"), self.gold_text)
|
||||||
self.scrollable = Scrollable(self.data_table)
|
self.scrollable = Scrollable(self.data_table)
|
||||||
@@ -155,7 +154,7 @@ class InventoryView(DoubleLineBox):
|
|||||||
)
|
)
|
||||||
|
|
||||||
super().__init__(
|
super().__init__(
|
||||||
top_widget=ScrollBar(self.scrollable, padding=1),
|
top_widget=ScrollBar(self.scrollable),
|
||||||
top_title="Inventory",
|
top_title="Inventory",
|
||||||
bottom_widget=self.encumbrance_bar,
|
bottom_widget=self.encumbrance_bar,
|
||||||
bottom_title="Encumbrance",
|
bottom_title="Encumbrance",
|
||||||
@@ -184,7 +183,8 @@ class InventoryView(DoubleLineBox):
|
|||||||
|
|
||||||
def sync_item_add(self, item: InventoryItem) -> None:
|
def sync_item_add(self, item: InventoryItem) -> None:
|
||||||
self.data_table.add_row(
|
self.data_table.add_row(
|
||||||
urwid.Text(item.name), urwid.Text(str(item.quantity))
|
urwid.Text(item.name),
|
||||||
|
urwid.Text(str(item.quantity), align=urwid.RIGHT),
|
||||||
)
|
)
|
||||||
self.scrollable.set_scrollpos(self.scrollable.rows_max() - 1)
|
self.scrollable.set_scrollpos(self.scrollable.rows_max() - 1)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user