SILICON
Loading...
Searching...
No Matches
sislVisualizer.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <optional>
4#include <string>
5#include <vector>
6
7#include <QWidget>
8
9#include <sisl/sisl.hpp>
10#include <ui/lifetime.hpp>
11
12class QGraphicsScene;
13class QGraphicsView;
14class QLabel;
15class QPushButton;
16
17namespace SILICON::ui {
18
19// Grouped palette colors to avoid redundant palette() queries across layout functions
21 QColor ink;
22 QColor base;
23 QColor accent;
24 QColor shaded;
26 QColor mid;
27
28 explicit ThemeColors(const QPalette& pal);
29};
30
31class SislVisualizer : public QWidget {
32public:
33 explicit SislVisualizer(QWidget* parent = nullptr);
34 void setDescription(sisl::IsaDescription description);
35 void zoom(bool in);
36
37private:
38 void changeEvent(QEvent* event) override;
39 void setupUI();
40
41 // High-level views
42 void showOverview();
43 void showFormat(const std::optional<std::string>& formatName);
44
45 // Overview Drawing Helpers
46 void drawOverviewTitle();
47 void drawAllFormatBoxes(const ThemeColors& theme, qreal& y);
48 void drawStandaloneInstructionsBox(const ThemeColors& theme, qreal& y);
49 void drawAllEnums(const ThemeColors& theme, qreal& y);
50
51 // Format View Drawing Helpers
52 void drawFormatHeader(const std::string& formatName, const ThemeColors& theme, qreal& y);
53 void drawInstructionsForFormat(const std::optional<std::string>& formatName, const ThemeColors& theme, qreal& y);
54 void drawAliases(const sisl::InstructionDescription& inst, const ThemeColors& theme, qreal& y);
55
56 // Bit Layout Drawing Engine
57 void drawLayout(const std::vector<sisl::FieldDescription>& fields,
58 std::size_t width,
59 const std::vector<sisl::FixedFieldDescription>& fixedFields,
60 qreal y,
61 const ThemeColors& theme);
62
63 void drawFieldSlices(const std::vector<sisl::FieldDescription>& fields,
64 std::size_t width,
65 const std::vector<sisl::FixedFieldDescription>& fixedFields,
66 qreal top,
67 const ThemeColors& theme,
68 std::vector<bool>& occupied,
69 std::vector<bool>& indexes);
70
71 void drawUnoccupiedSlices(std::size_t width,
72 qreal top,
73 const ThemeColors& theme,
74 std::vector<bool>& occupied,
75 std::vector<bool>& indexes);
76
77 void drawAxisIndices(std::size_t width, qreal y, const ThemeColors& theme, const std::vector<bool>& indexes);
78
79 // View management
80 void resetScene(bool showHint);
81 void finalizeScene();
82
83 // State
84 sisl::IsaDescription description;
85 QGraphicsScene* scene = nullptr;
86 QGraphicsView* view = nullptr;
87 QPushButton* backButton = nullptr;
88 QLabel* hintLabel = nullptr;
89 bool overview = true;
90 std::optional<std::string> currentFormat;
92};
93
94} // namespace SILICON::ui
void changeEvent(QEvent *event) override
void drawAllEnums(const ThemeColors &theme, qreal &y)
void showFormat(const std::optional< std::string > &formatName)
void drawAxisIndices(std::size_t width, qreal y, const ThemeColors &theme, const std::vector< bool > &indexes)
void drawUnoccupiedSlices(std::size_t width, qreal top, const ThemeColors &theme, std::vector< bool > &occupied, std::vector< bool > &indexes)
void drawInstructionsForFormat(const std::optional< std::string > &formatName, const ThemeColors &theme, qreal &y)
void drawStandaloneInstructionsBox(const ThemeColors &theme, qreal &y)
void drawAliases(const sisl::InstructionDescription &inst, const ThemeColors &theme, qreal &y)
SislVisualizer(QWidget *parent=nullptr)
void resetScene(bool showHint)
sisl::IsaDescription description
void drawFieldSlices(const std::vector< sisl::FieldDescription > &fields, std::size_t width, const std::vector< sisl::FixedFieldDescription > &fixedFields, qreal top, const ThemeColors &theme, std::vector< bool > &occupied, std::vector< bool > &indexes)
void drawFormatHeader(const std::string &formatName, const ThemeColors &theme, qreal &y)
void setDescription(sisl::IsaDescription description)
void drawAllFormatBoxes(const ThemeColors &theme, qreal &y)
std::optional< std::string > currentFormat
void drawLayout(const std::vector< sisl::FieldDescription > &fields, std::size_t width, const std::vector< sisl::FixedFieldDescription > &fixedFields, qreal y, const ThemeColors &theme)
ThemeColors(const QPalette &pal)