Skip to content

Commit 3e2576d

Browse files
committed
Adopt SFML's code formatting rules
1 parent 2a4dc2d commit 3e2576d

File tree

8 files changed

+1002
-687
lines changed

8 files changed

+1002
-687
lines changed

.clang-format

Lines changed: 134 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,159 @@
1-
Language: Cpp
1+
---
2+
# Project
3+
Standard: c++17
4+
ColumnLimit: 120
5+
6+
# Indentation
27
AccessModifierOffset: -4
3-
AlignAfterOpenBracket: true
4-
AlignConsecutiveAssignments: false
5-
AlignConsecutiveDeclarations: false
8+
BitFieldColonSpacing: Both
9+
ContinuationIndentWidth: 4
10+
IndentCaseLabels: true
11+
IndentCaseBlocks: false
12+
IndentExternBlock: Indent
13+
IndentPPDirectives: None
14+
IndentRequires: true
15+
IndentWidth: 4
16+
IndentWrappedFunctionNames: true
17+
TabWidth: 4
18+
UseTab: Never
19+
20+
# Alignment
21+
AlignAfterOpenBracket: Align
22+
AlignConsecutiveAssignments: Consecutive
23+
AlignConsecutiveBitFields: Consecutive
24+
AlignConsecutiveDeclarations: Consecutive
25+
AlignConsecutiveMacros: Consecutive
626
AlignEscapedNewlines: Left
7-
AlignOperands: true
8-
AlignTrailingComments: false
27+
AlignOperands: Align
28+
AlignTrailingComments: true
29+
30+
# Allow
31+
AllowAllArgumentsOnNextLine: false
32+
AllowAllConstructorInitializersOnNextLine: false
933
AllowAllParametersOfDeclarationOnNextLine: false
10-
AllowShortBlocksOnASingleLine: false
34+
AllowShortBlocksOnASingleLine: Never
1135
AllowShortCaseLabelsOnASingleLine: false
12-
AllowShortFunctionsOnASingleLine: InlineOnly
13-
AllowShortIfStatementsOnASingleLine: true
36+
AllowShortEnumsOnASingleLine: false
37+
AllowShortFunctionsOnASingleLine: None
38+
AllowShortIfStatementsOnASingleLine: Never
1439
AllowShortLoopsOnASingleLine: false
40+
AllowShortLambdasOnASingleLine: All
41+
42+
# Break
1543
AlwaysBreakAfterReturnType: None
16-
AlwaysBreakBeforeMultilineStrings: false
17-
AlwaysBreakTemplateDeclarations: true
18-
BinPackArguments: true
19-
BinPackParameters: true
44+
AlwaysBreakBeforeMultilineStrings: true
45+
AlwaysBreakTemplateDeclarations: Yes
46+
BreakBeforeConceptDeclarations: true
47+
BreakBeforeTernaryOperators: true
48+
BreakConstructorInitializers: AfterColon
49+
BreakBeforeBinaryOperators: None
50+
BreakInheritanceList: AfterColon
51+
BreakStringLiterals: true
52+
53+
# Initializers & arguments
54+
BinPackArguments: false
55+
BinPackParameters: false
56+
ConstructorInitializerAllOnOneLineOrOnePerLine: true
57+
ConstructorInitializerIndentWidth: 0
58+
Cpp11BracedListStyle: true
59+
60+
# Braces
2061
BreakBeforeBraces: Custom
2162
BraceWrapping:
22-
AfterClass: false
23-
AfterControlStatement: false
24-
AfterEnum: false
25-
AfterFunction: false
26-
AfterNamespace: false
27-
AfterStruct: false
63+
AfterCaseLabel: true
64+
AfterClass: true
65+
AfterControlStatement: Always
66+
AfterEnum: true
67+
AfterFunction: true
68+
AfterNamespace: true
69+
AfterStruct: true
2870
AfterUnion: true
2971
AfterExternBlock: true
3072
BeforeCatch: false
31-
BeforeElse: false
73+
BeforeElse: true
74+
BeforeLambdaBody: true
75+
BeforeWhile: false
3276
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
77+
SplitEmptyFunction: true
78+
SplitEmptyRecord: true
79+
SplitEmptyNamespace: true
80+
81+
# Namespaces
82+
CompactNamespaces: false
83+
FixNamespaceComments: true
5584
NamespaceIndentation: None
56-
PenaltyBreakBeforeFirstCallParameter: 1000
57-
PenaltyBreakComment: 10
58-
PenaltyReturnTypeOnItsOwnLine: 1000
59-
PointerAlignment: Left
60-
ReflowComments: true
85+
86+
# Derive
87+
DeriveLineEnding: false
88+
DerivePointerAlignment: false
89+
90+
# Empty lines
91+
EmptyLineBeforeAccessModifier: Always
92+
KeepEmptyLinesAtTheStartOfBlocks: true
93+
MaxEmptyLinesToKeep: 2
94+
95+
# Sorting
6196
SortIncludes: true
6297
SortUsingDeclarations: true
98+
99+
# Penalties
100+
PenaltyBreakAssignment: 1000
101+
PenaltyBreakBeforeFirstCallParameter: 1000
102+
PenaltyBreakComment: 200
103+
PenaltyBreakFirstLessLess: 100
104+
PenaltyBreakString: 1
105+
PenaltyBreakTemplateDeclaration: 0
106+
PenaltyExcessCharacter: 5
107+
PenaltyIndentedWhitespace: 1
108+
PenaltyReturnTypeOnItsOwnLine: 500
109+
110+
# Pointer alignment
111+
PointerAlignment: Left
112+
113+
# Comments
114+
ReflowComments: false
115+
116+
# Spaces
63117
SpaceAfterCStyleCast: false
64-
SpaceAfterTemplateKeyword: false
118+
SpaceAfterLogicalNot: false
119+
SpaceAfterTemplateKeyword: true
120+
SpaceAroundPointerQualifiers: Default
65121
SpaceBeforeAssignmentOperators: true
122+
SpaceBeforeCaseColon: false
123+
SpaceBeforeCpp11BracedList: false
124+
SpaceBeforeCtorInitializerColon: true
125+
SpaceBeforeInheritanceColon: true
66126
SpaceBeforeParens: ControlStatements
67127
SpaceBeforeRangeBasedForLoopColon: true
128+
SpaceBeforeSquareBrackets: false
129+
SpaceInEmptyBlock: false
68130
SpaceInEmptyParentheses: false
69131
SpacesBeforeTrailingComments: 1
70132
SpacesInAngles: false
71133
SpacesInCStyleCastParentheses: false
134+
SpacesInConditionalStatement: false
135+
SpacesInContainerLiterals: false
72136
SpacesInParentheses: false
73137
SpacesInSquareBrackets: false
74-
Standard: Cpp11
75-
UseTab: Never
138+
139+
# Line endings
140+
UseCRLF: false
141+
142+
# Qualifiers (const, volatile, static, etc)
143+
QualifierAlignment: Custom
144+
QualifierOrder: ['static', 'inline', 'constexpr', 'const', 'volatile', 'type']
145+
146+
---
147+
Language: ObjC
148+
IndentWidth: 4
149+
BreakBeforeBraces: Custom
150+
BraceWrapping:
151+
AfterObjCDeclaration: true
152+
153+
ObjCBinPackProtocolList: Never
154+
ObjCBlockIndentWidth: 4
155+
ObjCBreakBeforeNestedBlockParam: true
156+
ObjCSpaceAfterProperty: true
157+
ObjCSpaceBeforeProtocolList: false
158+
159+
...

examples/minimal/main.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,25 @@
44

55
#include <SFML/Graphics.hpp>
66

7-
int main() {
7+
int main()
8+
{
89
sf::RenderWindow window(sf::VideoMode({640, 480}), "ImGui + SFML = <3");
910
window.setFramerateLimit(60);
10-
if (!ImGui::SFML::Init(window)) return -1;
11+
if (!ImGui::SFML::Init(window))
12+
return -1;
1113

1214
sf::CircleShape shape(100.f);
1315
shape.setFillColor(sf::Color::Green);
1416

1517
sf::Clock deltaClock;
16-
while (window.isOpen()) {
17-
while (const auto event = window.pollEvent()) {
18+
while (window.isOpen())
19+
{
20+
while (const auto event = window.pollEvent())
21+
{
1822
ImGui::SFML::ProcessEvent(window, *event);
1923

20-
if (event->is<sf::Event::Closed>()) {
24+
if (event->is<sf::Event::Closed>())
25+
{
2126
window.close();
2227
}
2328
}

examples/multiple_windows/main.cpp

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,45 @@
44

55
#include <SFML/Graphics.hpp>
66

7-
int main() {
7+
int main()
8+
{
89
sf::RenderWindow window(sf::VideoMode({1280, 720}), "ImGui + SFML = <3");
910
window.setFramerateLimit(60);
10-
if (!ImGui::SFML::Init(window)) return -1;
11+
if (!ImGui::SFML::Init(window))
12+
return -1;
1113

1214
sf::RenderWindow childWindow(sf::VideoMode({640, 480}), "ImGui-SFML Child window");
1315
childWindow.setFramerateLimit(60);
14-
if (!ImGui::SFML::Init(childWindow)) return -1;
16+
if (!ImGui::SFML::Init(childWindow))
17+
return -1;
1518

1619
sf::Clock deltaClock;
17-
while (window.isOpen()) {
20+
while (window.isOpen())
21+
{
1822
// Main window event processing
19-
while (const auto event = window.pollEvent()) {
23+
while (const auto event = window.pollEvent())
24+
{
2025
ImGui::SFML::ProcessEvent(window, *event);
21-
if (event->is<sf::Event::Closed>()) {
22-
if (childWindow.isOpen()) {
26+
if (event->is<sf::Event::Closed>())
27+
{
28+
if (childWindow.isOpen())
29+
{
2330
childWindow.close();
2431
}
2532
window.close();
2633
ImGui::SFML::Shutdown(); // will shutdown all windows
27-
return 0; // return here so that we don't call Update/Render
34+
return 0; // return here so that we don't call Update/Render
2835
}
2936
}
3037

3138
// Child window event processing
32-
if (childWindow.isOpen()) {
33-
while (const auto event = childWindow.pollEvent()) {
39+
if (childWindow.isOpen())
40+
{
41+
while (const auto event = childWindow.pollEvent())
42+
{
3443
ImGui::SFML::ProcessEvent(childWindow, *event);
35-
if (event->is<sf::Event::Closed>()) {
44+
if (event->is<sf::Event::Closed>())
45+
{
3646
childWindow.close();
3747
ImGui::SFML::Shutdown(childWindow);
3848
}
@@ -42,7 +52,8 @@ int main() {
4252
// Update
4353
const sf::Time dt = deltaClock.restart();
4454
ImGui::SFML::Update(window, dt);
45-
if (childWindow.isOpen()) {
55+
if (childWindow.isOpen())
56+
{
4657
ImGui::SFML::Update(childWindow, dt);
4758
}
4859

@@ -53,7 +64,8 @@ int main() {
5364
ImGui::End();
5465
ImGui::ShowDemoWindow();
5566
// Add ImGui widgets in the child window
56-
if (childWindow.isOpen()) {
67+
if (childWindow.isOpen())
68+
{
5769
ImGui::SFML::SetCurrentWindow(childWindow);
5870
ImGui::Begin("Works in a second window!");
5971
ImGui::Button("Example button");
@@ -70,7 +82,8 @@ int main() {
7082
window.display();
7183

7284
// Child window drawing
73-
if (childWindow.isOpen()) {
85+
if (childWindow.isOpen())
86+
{
7487
sf::CircleShape shape2(50.f);
7588
shape2.setFillColor(sf::Color::Red);
7689

imconfig-SFML.h

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,27 @@
88
#include "imgui-SFML_export.h"
99

1010
#define IM_VEC2_CLASS_EXTRA \
11-
template<typename T> \
12-
ImVec2(const sf::Vector2<T>& v) { \
11+
template <typename T> \
12+
ImVec2(const sf::Vector2<T>& v) \
13+
{ \
1314
x = static_cast<float>(v.x); \
1415
y = static_cast<float>(v.y); \
1516
} \
1617
\
17-
template<typename T> \
18-
operator sf::Vector2<T>() const { \
18+
template <typename T> \
19+
operator sf::Vector2<T>() const \
20+
{ \
1921
return sf::Vector2<T>(static_cast<T>(x), static_cast<T>(y)); \
2022
}
2123

22-
#define IM_VEC4_CLASS_EXTRA \
23-
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) { \
24-
} \
25-
operator sf::Color() const { \
26-
return sf::Color(static_cast<std::uint8_t>(x * 255.f), \
27-
static_cast<std::uint8_t>(y * 255.f), \
28-
static_cast<std::uint8_t>(z * 255.f), \
29-
static_cast<std::uint8_t>(w * 255.f)); \
24+
#define IM_VEC4_CLASS_EXTRA \
25+
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) \
26+
{ \
27+
} \
28+
operator sf::Color() const \
29+
{ \
30+
return sf::Color(static_cast<std::uint8_t>(x * 255.f), \
31+
static_cast<std::uint8_t>(y * 255.f), \
32+
static_cast<std::uint8_t>(z * 255.f), \
33+
static_cast<std::uint8_t>(w * 255.f)); \
3034
}

0 commit comments

Comments
 (0)