Skip to content

Feat: Editor UI Update #388

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Mar 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Editor/Include/Editor/Widget/Editor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// Created by Kindem on 2025/3/22.
//

#pragma once

#include <QWidget>

namespace Editor {
class Editor final : public QWidget {
Q_OBJECT

public:
Editor();
};
}
53 changes: 52 additions & 1 deletion Editor/Qml/EProjectHub.qml
Original file line number Diff line number Diff line change
@@ -1,5 +1,56 @@
import QtQuick
import QtQuick.Layouts

Rectangle {
color: ETheme.bgColor
RowLayout {
anchors.fill: parent
spacing: 0

ColumnLayout {
Layout.preferredWidth: 5
Layout.fillWidth: true
Layout.fillHeight: true

Rectangle {
Layout.fillWidth: true
Layout.fillHeight: true
color: ETheme.primaryBgColor

ColumnLayout {
id: menuCol
anchors.fill: parent
anchors.margins: 20

RowLayout {
Layout.preferredHeight: 1
Layout.fillHeight: true
Layout.fillWidth: true

Image {
source: Qt.url('Resource/Image/Logo.png')
sourceSize.width: menuCol.width
}
}

RowLayout {
Layout.preferredHeight: 7
Layout.fillHeight: true
Layout.fillWidth: true
}
}
}
}

ColumnLayout {
Layout.preferredWidth: 14
Layout.fillWidth: true
Layout.fillHeight: true

Rectangle {
Layout.fillWidth: true
Layout.fillHeight: true
color: ETheme.bgColor
}
}
}
}
29 changes: 12 additions & 17 deletions Editor/Qml/ESwitch.qml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import QtQuick
import QtQuick.Controls
import QtQuick.Controls.Basic


Item {

enum Size {
Small,
Middle,
Expand All @@ -13,7 +11,7 @@ Item {

enum Filler {
None,
Withchar
Text
}

property string text: ''
Expand All @@ -38,33 +36,32 @@ Item {
indicator: Rectangle {
function getBackgroundColor(checked, disabled) {
if (disabled) {
return checked ? ETheme.disabledCheckedColor : ETheme.disabledColor;
return checked ? ETheme.primaryDisabledColor : ETheme.disabledColor;
}
return checked ? ETheme.primaryColor : ETheme.secondaryBgColor;
}

implicitWidth: 40 + 2 * (root.size - 1)
implicitWidth: 45 + 2 * (root.size - 1)
implicitHeight: 24 + 2 * (root.size - 1)
x: switchWidget.leftPadding
anchors.verticalCenter: parent.verticalCenter
radius: width / 2
radius: width / 4
color: getBackgroundColor(switchWidget.checked, root.disabled)

Rectangle {
function getX(check, down) {
if (check && down)
return parent.width - 2 * radius - 8;
return parent.width - 4 * radius - 8;
else
return check ? parent.width - width - 2 : 2

return check ? parent.width - width - 4 : 4
}

id: handle
x: getX(switchWidget.checked, switchWidget.down)
anchors.verticalCenter: parent.verticalCenter
radius: switchWidget.checked ? 9 + root.size : 7 + root.size
radius: 7 + root.size
height: 2 * radius
width: switchWidget.down ? 2 * radius + 6 : 2 * radius
width: 2 * radius
color: ETheme.fontColor;

Behavior on width {
Expand All @@ -75,17 +72,16 @@ Item {
Behavior on x {
NumberAnimation {
duration: 100
easing.type: easing.InOutCubic
}
}
}

Text {
function getChar(filler, checked, down) {
if (filler == ESwitch.Filler.None || down) {
function getText(filler, checked, down) {
if (filler === ESwitch.Filler.None || down) {
return '';
} else {
return checked ? "" : "";
return checked ? "Y" : "N";
}
}

Expand All @@ -95,11 +91,10 @@ Item {
color: ETheme.fontColor
x: switchWidget.checked ? (parent.width - handle.radius * 2 - font.pixelSize - 2) / 2 : (parent.width + handle.radius * 2 - font.pixelSize + 2) / 2;
anchors.verticalCenter: parent.verticalCenter
text: getChar(root.filler, switchWidget.checked, switchWidget.down)
text: getText(root.filler, switchWidget.checked, switchWidget.down)
Behavior on x {
NumberAnimation {
duration: 100
easing.type: easing.OutExpo
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions Editor/Qml/ETheme.qml
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,21 @@ import QtQuick

QtObject {
property color bgColor: Qt.color('#212121')
property color primaryBgColor: Qt.color('#2a2a2a')
property color primaryColor: Qt.color('#e74c3c')
property color primaryHoverColor: Qt.color('#ce4d40')
property color primaryFocusColor: Qt.color('#c0392b')
property color primaryDisabledColor: Qt.color('#4b4a49')
property color secondaryColor: Qt.color('#d58845')
property color secondaryHoverColor: Qt.color('#d58845')
property color secondaryFocusColor: Qt.color('#9b6a40')
property color disabledColor: Qt.color('#676563')
property color fontColor: Qt.color('#ecf0f1')
property color linkFontColor: Qt.color('#91b9c4')
property color secondaryBgColor: Qt.color('#8e8e8e')
property color disabledCheckedColor: Qt.color('#c9a9a6')

property FontLoader normalFont: FontLoader { source: Qt.url('Resource/Font/MiSans-Normal.ttf') }
property FontLoader boldFont: FontLoader { source: Qt.url('Resource/Font/MiSans-Bold.ttf') }
property FontLoader normalFont: FontLoader { source: Qt.url('Resource/Font/MiSans-Medium.ttf') }
property FontLoader boldFont: FontLoader { source: Qt.url('Resource/Font/MiSans-Semibold.ttf') }
property int tiele1FontSize: 20
property int title2FontSize: 18
property int title3FontSize: 16
Expand Down
4 changes: 3 additions & 1 deletion Editor/Qml/EWidgetSamples.qml
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ Rectangle {
style: EText.Style.Title1
}
}

RowLayout {
ESwitch {
text: 'Small Switch'
Expand All @@ -295,6 +296,7 @@ Rectangle {
size: ESwitch.Size.Large
}
}

RowLayout {
ESwitch {
text: 'Disabled Checked'
Expand All @@ -308,7 +310,7 @@ Rectangle {
}
ESwitch {
text: 'Filled Symbol'
filler: ESwitch.Filler.Withchar
filler: ESwitch.Filler.Text
}
}
}
Expand Down
Binary file added Editor/Qml/Resource/Font/MiSans-Demibold.ttf
Binary file not shown.
Binary file added Editor/Qml/Resource/Font/MiSans-ExtraLight.ttf
Binary file not shown.
Binary file added Editor/Qml/Resource/Font/MiSans-Heavy.ttf
Binary file not shown.
Binary file added Editor/Qml/Resource/Font/MiSans-Light.ttf
Binary file not shown.
Binary file added Editor/Qml/Resource/Font/MiSans-Medium.ttf
Binary file not shown.
Binary file added Editor/Qml/Resource/Font/MiSans-Regular.ttf
Binary file not shown.
Binary file added Editor/Qml/Resource/Font/MiSans-Semibold.ttf
Binary file not shown.
Binary file added Editor/Qml/Resource/Font/MiSans-Thin.ttf
Binary file not shown.
Binary file added Editor/Qml/Resource/Image/Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
91 changes: 70 additions & 21 deletions Editor/Src/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@

#include <Core/Cmdline.h>
#include <Editor/QmlEngine.h>
#include <Editor/Widget/Editor.h>
#include <Editor/Widget/ProjectHub.h>
#include <Editor/Widget/WidgetSamples.h>

#if BUILD_CONFIG_DEBUG
#include <Editor/Widget/GraphicsSampleWidget.h>

static Core::CmdlineArgValue<bool> caGraphicsWindowSample(
static Core::CmdlineArgValue<bool> caGraphicsSample(
"graphicsSample", "-graphicsSample", false,
"Whether to run graphics sample instead of editor");

static Core::CmdlineArgValue<bool> caRunSample(
static Core::CmdlineArgValue<bool> caWidgetSamples(
"widgetSamples", "-widgetSamples", false,
"Whether to run widget samples instead of editor");
#endif
Expand All @@ -29,9 +30,46 @@ static Core::CmdlineArgValue<std::string> caProjectRoot(
"projectRoot", "-project", "",
"project root path");

static void InitializePreQtApp(int argc, char** argv)
enum class EditorApplicationModel : uint8_t {
#if BUILD_CONFIG_DEBUG
graphicsSample,
widgetSamples,
#endif
projectHub,
editor,
max
};

static EditorApplicationModel GetAppModel()
{
Core::Cli::Get().Parse(argc, argv);
#if BUILD_CONFIG_DEBUG
if (caGraphicsSample.GetValue()) {
return EditorApplicationModel::graphicsSample;
}
if (caWidgetSamples.GetValue()) {
return EditorApplicationModel::widgetSamples;
}
#endif
if (caProjectRoot.GetValue().empty()) {
return EditorApplicationModel::projectHub;
}
return EditorApplicationModel::editor;
}

static bool NeedInitCore(EditorApplicationModel inModel)
{
bool result = inModel == EditorApplicationModel::editor;
#if BUILD_CONFIG_DEBUG
result = result || inModel == EditorApplicationModel::graphicsSample;
#endif
return result;
}

static void InitializePreQtApp(EditorApplicationModel inModel)
{
if (!NeedInitCore(inModel)) {
return;
}

Runtime::EngineInitParams params {};
params.logToFile = true;
Expand All @@ -46,35 +84,46 @@ static void InitializePostQtApp()
Editor::QmlEngine::Get().Start();
}

static void Cleanup()
static void Cleanup(EditorApplicationModel inModel)
{
Editor::QmlEngine::Get().Stop();

if (!NeedInitCore(inModel)) {
return;
}
Runtime::EngineHolder::Unload();
}

static Common::UniquePtr<QWidget> CreateMainWidget(EditorApplicationModel inModel)
{
#if BUILD_CONFIG_DEBUG
if (inModel == EditorApplicationModel::graphicsSample) {
return new Editor::GraphicsSampleWidget();
}
if (inModel == EditorApplicationModel::widgetSamples) {
return new Editor::WidgetSamples();
}
#endif
if (inModel == EditorApplicationModel::projectHub) { // NOLINT
return new Editor::ProjectHub();
}
return new Editor::Editor();
}

int main(int argc, char* argv[])
{
InitializePreQtApp(argc, argv);
Core::Cli::Get().Parse(argc, argv);
const auto appModel = GetAppModel();

InitializePreQtApp(appModel);
QApplication qtApplication(argc, argv);
InitializePostQtApp();

Common::UniquePtr<QWidget> mainWidget;
#if BUILD_CONFIG_DEBUG
if (caGraphicsWindowSample.GetValue()) {
mainWidget = new Editor::GraphicsSampleWidget();
} else if (caRunSample.GetValue()) {
mainWidget = new Editor::WidgetSamples();
} else
#endif
if (caProjectRoot.GetValue().empty()) { // NOLINT
mainWidget = new Editor::ProjectHub();
} else {
// TODO editor main
}
Common::UniquePtr<QWidget> mainWidget = CreateMainWidget(appModel);
mainWidget->show();

const int execRes = QApplication::exec();
mainWidget = nullptr;
Cleanup();
mainWidget.Reset();
Cleanup(appModel);
return execRes;
}
10 changes: 10 additions & 0 deletions Editor/Src/Widget/Editor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//
// Created by Kindem on 2025/3/22.
//

#include <Editor/Widget/Editor.h>
#include <Editor/Widget/moc_Editor.cpp>

namespace Editor {
Editor::Editor() = default;
} // namespace Editor
2 changes: 1 addition & 1 deletion Editor/Src/Widget/ProjectHub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ namespace Editor {
: QmlWidget("EProjectHub.qml")
{
setWindowFlags(windowFlags() & ~Qt::WindowMaximizeButtonHint);
setFixedSize(1024, 768);
setFixedSize(800, 600);
}
}