trying to get lists to work...?

materials
Bronwen 2021-07-26 23:15:05 -04:00
parent 83c70f59fb
commit 327b703201
1 changed files with 50 additions and 28 deletions

View File

@ -8,17 +8,18 @@ import {
QGridLayout, QGridLayout,
FocusPolicy, FocusPolicy,
WidgetEventTypes, WidgetEventTypes,
AlignmentFlag AlignmentFlag,
QListView,
QListWidget,
QListWidgetItem
} from '@nodegui/nodegui'; } from '@nodegui/nodegui';
import { Pawn } from '../Pawn.js'; import { Pawn } from '../Pawn.js';
import { View } from './View.js'; import { View } from './View.js';
// 40x30
const w = 40;
const h = 30;
export class GameView extends View { export class GameView extends View {
game: Game; game: Game;
title: QLabel; title: QLabel;
timeLabel: QLabel;
left: QWidget; left: QWidget;
right: QTabWidget; right: QTabWidget;
@ -28,26 +29,24 @@ export class GameView extends View {
this.title = new QLabel(); this.title = new QLabel();
this.left = new QWidget(); this.left = new QWidget();
this.right = new QTabWidget(); this.right = new QTabWidget();
this.timeLabel = new TimeWidget();
this.title.setText(this.game.name); this.title.setText(this.game.name);
this.left.setInlineStyle('border: 1px solid white;') this.left.setInlineStyle('border: 1px solid white;')
this.right.setInlineStyle('border: 1px solid white;') this.right.setInlineStyle('border: 1px solid white;')
// this.layout.addWidget(this.left, 1, 0, 29, 20); this.layout.addWidget(this.title, 0, 0);
// this.layout.addWidget(this.right, 1, 21, 29, 20); this.layout.addWidget(this.timeLabel, 0, 1);
this.layout.addWidget(this.left, 1, 0);
this.layout.addWidget(this.title, 0, 0, 1, w); this.layout.addWidget(this.right, 1, 1);
this.layout.addWidget(this.left, 1, 0, h - 1, w / 2); this.layout.setRowStretch(0, 0);
this.layout.addWidget(this.right, 1, w / 2, h - 1, w / 2); this.layout.setRowStretch(1, 1);
this.layout.setColumnStretch(0, 3);
const page1 = new QLabel(); this.layout.setColumnStretch(1, 2);
page1.setText('Page 1');
const page2 = new QLabel();
page2.setText('Page 2');
this.right.addTab(new PawnPageWidget(), new QIcon(), 'Pawns'); this.right.addTab(new PawnPageWidget(), new QIcon(), 'Pawns');
this.right.addTab(page2, new QIcon(), 'Inventory'); this.right.addTab(new InventoryWidget(), new QIcon(), 'Inventory')
} }
constructor(game: Game) { constructor(game: Game) {
@ -59,37 +58,60 @@ export class GameView extends View {
class PawnWidget extends QWidget { class PawnWidget extends QWidget {
constructor(pawn: Pawn) { constructor(pawn: Pawn) {
super(); super();
this.setLayout(new QGridLayout()); let layout: QGridLayout;
this.setInlineStyle(` this.setLayout(layout = new QGridLayout());
height: 64px; // this.setInlineStyle(`
background: cyan; // margin-bottom: 4px;
width: \'100%\'; // `);
margin-bottom: 4px;
`);
const nameLabel = new QLabel(); const nameLabel = new QLabel();
nameLabel.setText(pawn.name.first + ' ' + pawn.name.last); nameLabel.setText(pawn.name.first + ' ' + pawn.name.last);
nameLabel.setAlignment(AlignmentFlag.AlignLeft | AlignmentFlag.AlignTop); nameLabel.setAlignment(AlignmentFlag.AlignLeft | AlignmentFlag.AlignTop);
const activityLabel = new QLabel(); const activityLabel = new QLabel();
activityLabel.setText(pawn.status); activityLabel.setText(pawn.status);
activityLabel.setAlignment(AlignmentFlag.AlignRight | AlignmentFlag.AlignTop); activityLabel.setAlignment(AlignmentFlag.AlignRight | AlignmentFlag.AlignTop);
this.layout.addWidget(nameLabel, 0, 0, 1, 1); this.layout.addWidget(nameLabel, 0, 0, 1, 1);
this.layout.addWidget(activityLabel, 0, 1, 1, 1); this.layout.addWidget(activityLabel, 0, 1, 1, 1);
this.setFocusPolicy(FocusPolicy.ClickFocus); layout.setColumnStretch(0, 1);
layout.setColumnStretch(1, 1);
layout.setRowStretch(0, 1);
// this.setFocusPolicy(FocusPolicy.ClickFocus);
} }
} }
class PawnPageWidget extends QWidget { class PawnPageWidget extends QListWidget {
constructor() { constructor() {
super(); super();
this.setLayout(new FlexLayout()); // this.setLayout(new FlexLayout());
// this.setInlineStyle('width: 100%; height: 100%;'); this.setInlineStyle('background: purple;');
// this.layout.addWidget(new PawnWidget(Game.current.pawns[0]));
for(const pawn of Game.current.pawns) { for(const pawn of Game.current.pawns) {
// const label = new QLabel(); // const label = new QLabel();
// label.setText(pawn.name.first); // label.setText(pawn.name.first);
// this.layout.addWidget(label); // this.layout.addWidget(label);
this.layout.addWidget(new PawnWidget(pawn)); // this.layout.addWidget(new PawnWidget(pawn));
const item = new QListWidgetItem();
this.addItem(item);
this.setItemWidget(item, new PawnWidget(pawn));
} }
} }
}
class TimeWidget extends QLabel {
constructor() {
super();
this.setAlignment(AlignmentFlag.AlignRight | AlignmentFlag.AlignVCenter);
setInterval(() => {
this.setText(Game.current.clock.toString());
}, 100)
}
}
class InventoryWidget extends QWidget {
} }