Improve UI

This commit is contained in:
BorysLevytskyi
2023-05-11 11:48:22 +02:00
parent fc403a26b6
commit 3ff599bb98
4 changed files with 37 additions and 28 deletions

View File

@@ -1,7 +1,6 @@
import {numberParser} from './numberParser';
import { ExpressionElement as ExpressionElement } from './expression-interfaces'; import { ExpressionElement as ExpressionElement } from './expression-interfaces';
import { NumberBase } from '../core/formatter'; import { NumberBase } from '../core/formatter';
import { INT32_MAX_VALUE, INT32_MIN_VALUE, INT64_MAX_VALUE, INT64_MIN_VALUE, UINT64_MAX_VALUE } from '../core/const'; import { INT64_MAX_VALUE, INT64_MIN_VALUE, UINT64_MAX_VALUE } from '../core/const';
import { Integer, JsNumber, isInteger, asInteger } from '../core/Integer'; import { Integer, JsNumber, isInteger, asInteger } from '../core/Integer';
var globalId : number = 1; var globalId : number = 1;

View File

@@ -26,8 +26,9 @@ export default class BitwiseResultView extends React.Component<BitwiseResultView
render() { render() {
let model : BitwiseResultViewModel | null = null let model : BitwiseResultViewModel | null = null
const isListOfNumbers = this.props.expression instanceof ListOfNumbers; const allowSignChange = this.props.expression instanceof ListOfNumbers;
try try
{ {
@@ -38,7 +39,12 @@ export default class BitwiseResultView extends React.Component<BitwiseResultView
return <div className='error'>Error: {text}</div> return <div className='error'>Error: {text}</div>
} }
var rows = this.getRows(model!, isListOfNumbers); const showInfoColumn : boolean = model.items
.map(i => willInfoColumnBeVisible(i.expressionElement, model!.maxNumberOfBits, allowSignChange))
.filter(p => p == true)
.length > 0;
var rows = this.getRows(model!, showInfoColumn, allowSignChange);
return <table className="expression"> return <table className="expression">
<tbody> <tbody>
@@ -47,31 +53,31 @@ export default class BitwiseResultView extends React.Component<BitwiseResultView
</table> </table>
} }
getRows(model: BitwiseResultViewModel, allowSignChange : boolean): JSX.Element[] { getRows(model: BitwiseResultViewModel, showInfoColumn : boolean, allowSignChange : boolean): JSX.Element[] {
this.maxSeenLengthNumberOfBits = Math.max(model.maxNumberOfBits, this.maxSeenLengthNumberOfBits); this.maxSeenLengthNumberOfBits = Math.max(model.maxNumberOfBits, this.maxSeenLengthNumberOfBits);
return model.items.map((itm, i) => return model.items.map((itm, i) =>
<ExpressionRow <ExpressionElementTableRow
key={i} key={i}
sign={itm.sign} sign={itm.sign}
css={itm.css} css={itm.css}
bitSize={itm.maxBitSize} bitSize={itm.maxBitSize}
allowFlipBits={itm.allowFlipBits} allowFlipBits={itm.allowFlipBits}
allowSignChange={allowSignChange} allowSignChange={allowSignChange}
expressionItem={itm.expression} expressionItem={itm.expressionElement}
emphasizeBytes={this.props.emphasizeBytes} emphasizeBytes={this.props.emphasizeBytes}
maxNumberOfBits={this.maxSeenLengthNumberOfBits} maxNumberOfBits={this.maxSeenLengthNumberOfBits}
showInfoColumn={showInfoColumn}
onBitFlipped={() => this.onBitFlipped()} />); onBitFlipped={() => this.onBitFlipped()} />);
} }
onBitFlipped() { onBitFlipped() {
this.forceUpdate(); this.forceUpdate();
//this.setState({d:new Date()});
} }
} }
type ExpressionRowProps = { type ExpressionElementRowProps = {
sign: string, sign: string,
css: string, css: string,
bitSize: number, bitSize: number,
@@ -80,14 +86,15 @@ type ExpressionRowProps = {
allowFlipBits: boolean, allowFlipBits: boolean,
allowSignChange: boolean, allowSignChange: boolean,
expressionItem: ExpressionElement, expressionItem: ExpressionElement,
onBitFlipped: any onBitFlipped: any,
showInfoColumn: boolean
} }
class ExpressionRow extends React.Component<ExpressionRowProps> { class ExpressionElementTableRow extends React.Component<ExpressionElementRowProps> {
infoWasShown: boolean = false; infoWasShown: boolean = false;
constructor(props: ExpressionRowProps) { constructor(props: ExpressionElementRowProps) {
super(props); super(props);
this.state = { operand: null }; this.state = { operand: null };
} }
@@ -110,8 +117,8 @@ class ExpressionRow extends React.Component<ExpressionRowProps> {
onFlipBit={args => this.flipBit(args)} /> onFlipBit={args => this.flipBit(args)} />
</td> </td>
<td className="other">{this.getAlternative()}</td> <td className="other">{this.getAlternative()}</td>
<td className="info accent1" data-test-name='ignore'>{this.getInfo(maxNumberOfBits)}</td> <td className="info accent1" data-test-name='ignore'>{this.props.showInfoColumn ? this.getInfo(maxNumberOfBits) : null}</td>
</tr>;; </tr>;
} }
getLabel(): string { getLabel(): string {
@@ -170,12 +177,7 @@ class ExpressionRow extends React.Component<ExpressionRowProps> {
getInfo(maxNumberOfBits:number) { getInfo(maxNumberOfBits:number) {
const op = this.props.expressionItem.getUnderlyingOperand(); const op = this.props.expressionItem.getUnderlyingOperand();
const allBitsDisplayed = op.value.maxBitSize != 32 || op.value.maxBitSize <= maxNumberOfBits;
const { allowSignChange } = this.props; const { allowSignChange } = this.props;
const hasLabel = op.label.length > 0;
if(!allBitsDisplayed && !hasLabel && !this.infoWasShown)
return null;
this.infoWasShown = true; this.infoWasShown = true;
@@ -194,14 +196,22 @@ class ExpressionRow extends React.Component<ExpressionRowProps> {
children.push(<span title={title} style={{cursor:"help"}}>{text.trim()}</span>); children.push(<span title={title} style={{cursor:"help"}}>{text.trim()}</span>);
if(allBitsDisplayed) if(this.props.maxNumberOfBits >= op.value.maxBitSize)
{ {
if(allowSignChange) if(allowSignChange)
children.push(<button className='accent1' title={signedTitle} onClick={() => this.onChangeSign()}>{signedStr}</button>); children.push(<button className='accent1' title={signedTitle} onClick={() => this.onChangeSign()}>{signedStr}</button>);
else if(!op.value.signed) else if(!op.value.signed)
children.push(<span className='accent1'> {signedStr}</span>) children.push(<span className='accent1'> {signedStr}</span>)
} }
return <React.Fragment>{children}</React.Fragment> return <React.Fragment>{children}</React.Fragment>
} }
}
function willInfoColumnBeVisible(expr: ExpressionElement, maxNumberOfBits: number, allowSignChange : boolean) {
const op = expr.getUnderlyingOperand();
const allBitsDisplayed = op.value.maxBitSize != 32 || op.value.maxBitSize <= maxNumberOfBits;
const hasLabel = op.label.length > 0;
return allBitsDisplayed || hasLabel;
} }

View File

@@ -11,7 +11,7 @@ type Config = {
type ExpressionRowModel = { type ExpressionRowModel = {
sign: string; sign: string;
css: string; css: string;
expression: ExpressionElement; expressionElement: ExpressionElement;
allowFlipBits: boolean; allowFlipBits: boolean;
label: string; label: string;
maxBitSize: number; maxBitSize: number;
@@ -84,7 +84,7 @@ export default class BitwiseResultViewModel {
this.items.push({ this.items.push({
sign:'', sign:'',
css: '', css: '',
expression: expr, expressionElement: expr,
allowFlipBits: this.allowFlipBits, allowFlipBits: this.allowFlipBits,
label: '', label: '',
maxBitSize: expr.value.maxBitSize, maxBitSize: expr.value.maxBitSize,
@@ -102,7 +102,7 @@ export default class BitwiseResultViewModel {
sign: expr.operator, sign: expr.operator,
css: '', css: '',
label: this.getLabel(resultNumber), label: this.getLabel(resultNumber),
expression: expr.operand, expressionElement: expr.operand,
allowFlipBits: this.allowFlipBits, allowFlipBits: this.allowFlipBits,
maxBitSize: resultNumber.value.maxBitSize maxBitSize: resultNumber.value.maxBitSize
}); });
@@ -115,7 +115,7 @@ export default class BitwiseResultViewModel {
this.items.push({ this.items.push({
sign: expr.operator + formatter.numberToString(child.value, child.base), sign: expr.operator + formatter.numberToString(child.value, child.base),
css: 'expression-result', css: 'expression-result',
expression: resultExpr, expressionElement: resultExpr,
allowFlipBits: false, allowFlipBits: false,
label: '', label: '',
maxBitSize: resultExpr.value.maxBitSize maxBitSize: resultExpr.value.maxBitSize
@@ -128,7 +128,7 @@ export default class BitwiseResultViewModel {
this.items.push({ this.items.push({
sign:'=', sign:'=',
css: 'expression-result', css: 'expression-result',
expression: expr, expressionElement: expr,
allowFlipBits: false, allowFlipBits: false,
label: '', label: '',
maxBitSize: expr.value.maxBitSize maxBitSize: expr.value.maxBitSize

View File

@@ -3,7 +3,7 @@ import Operator from './Operator'
import ListOfNumbers from './ListOfNumbers'; import ListOfNumbers from './ListOfNumbers';
import BitwiseOperation from './BitwiseOperation'; import BitwiseOperation from './BitwiseOperation';
import { Expression, ExpressionElement } from './expression-interfaces'; import { Expression, ExpressionElement } from './expression-interfaces';
import { numberParser, numberRegexString } from './numberParser'; import { numberParser } from './numberParser';
export { default as Operand } from './Operand'; export { default as Operand } from './Operand';
export { default as Operator } from './Operator'; export { default as Operator } from './Operator';