Skip to content

Commit e74053f

Browse files
committed
Format all code using ClangFormat
* Add .clang-format file * Reformat the code * Add CI step to check that clang-format was ran * Add README notes about ClangFormat
1 parent aadb86b commit e74053f

File tree

8 files changed

+430
-399
lines changed

8 files changed

+430
-399
lines changed

.clang-format

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
Language: Cpp
2+
AccessModifierOffset: -4
3+
AlignAfterOpenBracket: true
4+
AlignConsecutiveAssignments: false
5+
AlignConsecutiveDeclarations: false
6+
AlignEscapedNewlines: Left
7+
AlignOperands: true
8+
AlignTrailingComments: false
9+
AllowAllParametersOfDeclarationOnNextLine: false
10+
AllowShortBlocksOnASingleLine: false
11+
AllowShortCaseLabelsOnASingleLine: false
12+
AllowShortFunctionsOnASingleLine: InlineOnly
13+
AllowShortIfStatementsOnASingleLine: true
14+
AllowShortLoopsOnASingleLine: false
15+
AlwaysBreakAfterReturnType: None
16+
AlwaysBreakBeforeMultilineStrings: false
17+
AlwaysBreakTemplateDeclarations: true
18+
BinPackArguments: true
19+
BinPackParameters: true
20+
BreakBeforeBraces: Custom
21+
BraceWrapping:
22+
AfterClass: false
23+
AfterControlStatement: false
24+
AfterEnum: false
25+
AfterFunction: false
26+
AfterNamespace: false
27+
AfterStruct: false
28+
AfterUnion: true
29+
AfterExternBlock: true
30+
BeforeCatch: false
31+
BeforeElse: false
32+
IndentBraces: false
33+
SplitEmptyFunction: false
34+
SplitEmptyRecord: false
35+
SplitEmptyNamespace: false
36+
BreakBeforeBinaryOperators: None
37+
BreakBeforeTernaryOperators: false
38+
BreakConstructorInitializers: AfterColon
39+
BreakInheritanceList: AfterColon
40+
BreakStringLiterals: true
41+
ColumnLimit: 100
42+
ConstructorInitializerAllOnOneLineOrOnePerLine: true
43+
ConstructorInitializerIndentWidth: 4
44+
ContinuationIndentWidth: 4
45+
Cpp11BracedListStyle: true
46+
DerivePointerAlignment: false
47+
FixNamespaceComments: false
48+
IncludeBlocks: Preserve
49+
IndentCaseLabels: false
50+
IndentPPDirectives: None
51+
IndentWidth: 4
52+
IndentWrappedFunctionNames: false
53+
KeepEmptyLinesAtTheStartOfBlocks: false
54+
MaxEmptyLinesToKeep: 1
55+
NamespaceIndentation: None
56+
PenaltyBreakBeforeFirstCallParameter: 1000
57+
PenaltyBreakComment: 10
58+
PenaltyReturnTypeOnItsOwnLine: 1000
59+
PointerAlignment: Left
60+
ReflowComments: true
61+
SortIncludes: true
62+
SortUsingDeclarations: true
63+
SpaceAfterCStyleCast: false
64+
SpaceAfterTemplateKeyword: false
65+
SpaceBeforeAssignmentOperators: true
66+
SpaceBeforeParens: ControlStatements
67+
SpaceBeforeRangeBasedForLoopColon: true
68+
SpaceInEmptyParentheses: false
69+
SpacesBeforeTrailingComments: 1
70+
SpacesInAngles: false
71+
SpacesInCStyleCastParentheses: false
72+
SpacesInParentheses: false
73+
SpacesInSquareBrackets: false
74+
Standard: Cpp11
75+
UseTab: Never

.github/workflows/build.yml

+8
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,14 @@ jobs:
112112
submodules: recursive
113113
path: imgui-sfml
114114

115+
# Container action is only supported on Linux
116+
- name: Check Clang Format
117+
if: runner.os == 'Linux'
118+
uses: DoozyX/[email protected]
119+
with:
120+
source: '.'
121+
extensions: 'h,cpp'
122+
115123
- name: Checkout SFML
116124
uses: actions/checkout@v2
117125
with:

README.md

+8-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ Dependencies
1414
* [SFML](https://github.com/SFML/SFML) >= 2.5.0
1515
* [Dear ImGui](https://github.com/ocornut/imgui) >= 1.68
1616

17+
Contributing
18+
-----
19+
20+
* The code is written in C++03. See [#7](https://github.com/eliasdaler/imgui-sfml/issues/7)
21+
* The code should be formatted via [ClangFormat](https://clang.llvm.org/docs/ClangFormat.html) using `.clang-format` provided in the root of this repository
22+
1723
How-to
1824
----
1925

@@ -91,13 +97,12 @@ See example file [here](examples/main.cpp)
9197
#include "imgui.h"
9298
#include "imgui-SFML.h"
9399

100+
#include <SFML/Graphics/CircleShape.hpp>
94101
#include <SFML/Graphics/RenderWindow.hpp>
95102
#include <SFML/System/Clock.hpp>
96103
#include <SFML/Window/Event.hpp>
97-
#include <SFML/Graphics/CircleShape.hpp>
98104

99-
int main()
100-
{
105+
int main() {
101106
sf::RenderWindow window(sf::VideoMode(640, 480), "ImGui + SFML = <3");
102107
window.setFramerateLimit(60);
103108
ImGui::SFML::Init(window);

examples/main.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
#include "imgui.h"
2-
#include "imgui-SFML.h"
1+
#include "imgui.h" // necessary for ImGui::*, imgui-SFML.h doesn't include imgui.h
32

3+
#include "imgui-SFML.h" // for ImGui::SFML::* functions and SFML-specific overloads
4+
5+
#include <SFML/Graphics/CircleShape.hpp>
46
#include <SFML/Graphics/RenderWindow.hpp>
57
#include <SFML/System/Clock.hpp>
68
#include <SFML/Window/Event.hpp>
7-
#include <SFML/Graphics/CircleShape.hpp>
89

9-
int main()
10-
{
10+
int main() {
1111
sf::RenderWindow window(sf::VideoMode(640, 480), "ImGui + SFML = <3");
1212
window.setFramerateLimit(60);
1313
ImGui::SFML::Init(window);
@@ -29,7 +29,7 @@ int main()
2929
ImGui::SFML::Update(window, deltaClock.restart());
3030

3131
ImGui::ShowDemoWindow();
32-
32+
3333
ImGui::Begin("Hello, world!");
3434
ImGui::Button("Look at this pretty button");
3535
ImGui::End();
@@ -41,6 +41,6 @@ int main()
4141
}
4242

4343
ImGui::SFML::Shutdown();
44-
44+
4545
return 0;
4646
}

imconfig-SFML.h

+16-21
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,27 @@
11
// Add this to your imconfig.h
22

3-
#include <SFML/System/Vector2.hpp>
43
#include <SFML/Graphics/Color.hpp>
4+
#include <SFML/System/Vector2.hpp>
55

66
#include "imgui-SFML_export.h"
77

8-
#define IM_VEC2_CLASS_EXTRA \
9-
template <typename T> \
10-
ImVec2(const sf::Vector2<T>& v) { \
11-
x = static_cast<float>(v.x); \
12-
y = static_cast<float>(v.y); \
13-
} \
14-
\
15-
template <typename T> \
16-
operator sf::Vector2<T>() const { \
17-
return sf::Vector2<T>(x, y); \
8+
#define IM_VEC2_CLASS_EXTRA \
9+
template<typename T> \
10+
ImVec2(const sf::Vector2<T>& v) { \
11+
x = static_cast<float>(v.x); \
12+
y = static_cast<float>(v.y); \
13+
} \
14+
\
15+
template<typename T> \
16+
operator sf::Vector2<T>() const { \
17+
return sf::Vector2<T>(x, y); \
1818
}
1919

20-
#define IM_VEC4_CLASS_EXTRA \
21-
ImVec4(const sf::Color & c) \
22-
: x(c.r / 255.f), y(c.g / 255.f), z(c.b / 255.f), w(c.a / 255.f)\
23-
{} \
24-
operator sf::Color() const { \
25-
return sf::Color( \
26-
static_cast<sf::Uint8>(x * 255.f), \
27-
static_cast<sf::Uint8>(y * 255.f), \
28-
static_cast<sf::Uint8>(z * 255.f), \
29-
static_cast<sf::Uint8>(w * 255.f)); \
20+
#define IM_VEC4_CLASS_EXTRA \
21+
ImVec4(const sf::Color& c) : x(c.r / 255.f), y(c.g / 255.f), z(c.b / 255.f), w(c.a / 255.f) {} \
22+
operator sf::Color() const { \
23+
return sf::Color(static_cast<sf::Uint8>(x * 255.f), static_cast<sf::Uint8>(y * 255.f), \
24+
static_cast<sf::Uint8>(z * 255.f), static_cast<sf::Uint8>(w * 255.f)); \
3025
}
3126

3227
#define ImTextureID unsigned int

0 commit comments

Comments
 (0)