Skip to content

Commit

Permalink
Adopt SFML's code formatting rules
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisThrasher committed Sep 24, 2024
1 parent 2a4dc2d commit 3e2576d
Show file tree
Hide file tree
Showing 8 changed files with 1,002 additions and 687 deletions.
184 changes: 134 additions & 50 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,75 +1,159 @@
Language: Cpp
---
# Project
Standard: c++17
ColumnLimit: 120

# Indentation
AccessModifierOffset: -4
AlignAfterOpenBracket: true
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
BitFieldColonSpacing: Both
ContinuationIndentWidth: 4
IndentCaseLabels: true
IndentCaseBlocks: false
IndentExternBlock: Indent
IndentPPDirectives: None
IndentRequires: true
IndentWidth: 4
IndentWrappedFunctionNames: true
TabWidth: 4
UseTab: Never

# Alignment
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: Consecutive
AlignConsecutiveBitFields: Consecutive
AlignConsecutiveDeclarations: Consecutive
AlignConsecutiveMacros: Consecutive
AlignEscapedNewlines: Left
AlignOperands: true
AlignTrailingComments: false
AlignOperands: Align
AlignTrailingComments: true

# Allow
AllowAllArgumentsOnNextLine: false
AllowAllConstructorInitializersOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: false
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: InlineOnly
AllowShortIfStatementsOnASingleLine: true
AllowShortEnumsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
AllowShortLambdasOnASingleLine: All

# Break
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: true
BinPackArguments: true
BinPackParameters: true
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: Yes
BreakBeforeConceptDeclarations: true
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: AfterColon
BreakBeforeBinaryOperators: None
BreakInheritanceList: AfterColon
BreakStringLiterals: true

# Initializers & arguments
BinPackArguments: false
BinPackParameters: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 0
Cpp11BracedListStyle: true

# Braces
BreakBeforeBraces: Custom
BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterStruct: false
AfterCaseLabel: true
AfterClass: true
AfterControlStatement: Always
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterStruct: true
AfterUnion: true
AfterExternBlock: true
BeforeCatch: false
BeforeElse: false
BeforeElse: true
BeforeLambdaBody: true
BeforeWhile: false
IndentBraces: false
SplitEmptyFunction: false
SplitEmptyRecord: false
SplitEmptyNamespace: false
BreakBeforeBinaryOperators: None
BreakBeforeTernaryOperators: false
BreakConstructorInitializers: AfterColon
BreakInheritanceList: AfterColon
BreakStringLiterals: true
ColumnLimit: 100
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
FixNamespaceComments: false
IncludeBlocks: Preserve
IndentCaseLabels: false
IndentPPDirectives: None
IndentWidth: 4
IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: false
MaxEmptyLinesToKeep: 1
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true

# Namespaces
CompactNamespaces: false
FixNamespaceComments: true
NamespaceIndentation: None
PenaltyBreakBeforeFirstCallParameter: 1000
PenaltyBreakComment: 10
PenaltyReturnTypeOnItsOwnLine: 1000
PointerAlignment: Left
ReflowComments: true

# Derive
DeriveLineEnding: false
DerivePointerAlignment: false

# Empty lines
EmptyLineBeforeAccessModifier: Always
KeepEmptyLinesAtTheStartOfBlocks: true
MaxEmptyLinesToKeep: 2

# Sorting
SortIncludes: true
SortUsingDeclarations: true

# Penalties
PenaltyBreakAssignment: 1000
PenaltyBreakBeforeFirstCallParameter: 1000
PenaltyBreakComment: 200
PenaltyBreakFirstLessLess: 100
PenaltyBreakString: 1
PenaltyBreakTemplateDeclaration: 0
PenaltyExcessCharacter: 5
PenaltyIndentedWhitespace: 1
PenaltyReturnTypeOnItsOwnLine: 500

# Pointer alignment
PointerAlignment: Left

# Comments
ReflowComments: false

# Spaces
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceAroundPointerQualifiers: Default
SpaceBeforeAssignmentOperators: true
SpaceBeforeCaseColon: false
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceBeforeSquareBrackets: false
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInConditionalStatement: false
SpacesInContainerLiterals: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
UseTab: Never

# Line endings
UseCRLF: false

# Qualifiers (const, volatile, static, etc)
QualifierAlignment: Custom
QualifierOrder: ['static', 'inline', 'constexpr', 'const', 'volatile', 'type']

---
Language: ObjC
IndentWidth: 4
BreakBeforeBraces: Custom
BraceWrapping:
AfterObjCDeclaration: true

ObjCBinPackProtocolList: Never
ObjCBlockIndentWidth: 4
ObjCBreakBeforeNestedBlockParam: true
ObjCSpaceAfterProperty: true
ObjCSpaceBeforeProtocolList: false

...
15 changes: 10 additions & 5 deletions examples/minimal/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,25 @@

#include <SFML/Graphics.hpp>

int main() {
int main()
{
sf::RenderWindow window(sf::VideoMode({640, 480}), "ImGui + SFML = <3");
window.setFramerateLimit(60);
if (!ImGui::SFML::Init(window)) return -1;
if (!ImGui::SFML::Init(window))
return -1;

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

sf::Clock deltaClock;
while (window.isOpen()) {
while (const auto event = window.pollEvent()) {
while (window.isOpen())
{
while (const auto event = window.pollEvent())
{
ImGui::SFML::ProcessEvent(window, *event);

if (event->is<sf::Event::Closed>()) {
if (event->is<sf::Event::Closed>())
{
window.close();
}
}
Expand Down
41 changes: 27 additions & 14 deletions examples/multiple_windows/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,45 @@

#include <SFML/Graphics.hpp>

int main() {
int main()
{
sf::RenderWindow window(sf::VideoMode({1280, 720}), "ImGui + SFML = <3");
window.setFramerateLimit(60);
if (!ImGui::SFML::Init(window)) return -1;
if (!ImGui::SFML::Init(window))
return -1;

sf::RenderWindow childWindow(sf::VideoMode({640, 480}), "ImGui-SFML Child window");
childWindow.setFramerateLimit(60);
if (!ImGui::SFML::Init(childWindow)) return -1;
if (!ImGui::SFML::Init(childWindow))
return -1;

sf::Clock deltaClock;
while (window.isOpen()) {
while (window.isOpen())
{
// Main window event processing
while (const auto event = window.pollEvent()) {
while (const auto event = window.pollEvent())
{
ImGui::SFML::ProcessEvent(window, *event);
if (event->is<sf::Event::Closed>()) {
if (childWindow.isOpen()) {
if (event->is<sf::Event::Closed>())
{
if (childWindow.isOpen())
{
childWindow.close();
}
window.close();
ImGui::SFML::Shutdown(); // will shutdown all windows
return 0; // return here so that we don't call Update/Render
return 0; // return here so that we don't call Update/Render
}
}

// Child window event processing
if (childWindow.isOpen()) {
while (const auto event = childWindow.pollEvent()) {
if (childWindow.isOpen())
{
while (const auto event = childWindow.pollEvent())
{
ImGui::SFML::ProcessEvent(childWindow, *event);
if (event->is<sf::Event::Closed>()) {
if (event->is<sf::Event::Closed>())
{
childWindow.close();
ImGui::SFML::Shutdown(childWindow);
}
Expand All @@ -42,7 +52,8 @@ int main() {
// Update
const sf::Time dt = deltaClock.restart();
ImGui::SFML::Update(window, dt);
if (childWindow.isOpen()) {
if (childWindow.isOpen())
{
ImGui::SFML::Update(childWindow, dt);
}

Expand All @@ -53,7 +64,8 @@ int main() {
ImGui::End();
ImGui::ShowDemoWindow();
// Add ImGui widgets in the child window
if (childWindow.isOpen()) {
if (childWindow.isOpen())
{
ImGui::SFML::SetCurrentWindow(childWindow);
ImGui::Begin("Works in a second window!");
ImGui::Button("Example button");
Expand All @@ -70,7 +82,8 @@ int main() {
window.display();

// Child window drawing
if (childWindow.isOpen()) {
if (childWindow.isOpen())
{
sf::CircleShape shape2(50.f);
shape2.setFillColor(sf::Color::Red);

Expand Down
28 changes: 16 additions & 12 deletions imconfig-SFML.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,27 @@
#include "imgui-SFML_export.h"

#define IM_VEC2_CLASS_EXTRA \
template<typename T> \
ImVec2(const sf::Vector2<T>& v) { \
template <typename T> \
ImVec2(const sf::Vector2<T>& v) \
{ \
x = static_cast<float>(v.x); \
y = static_cast<float>(v.y); \
} \
\
template<typename T> \
operator sf::Vector2<T>() const { \
template <typename T> \
operator sf::Vector2<T>() const \
{ \
return sf::Vector2<T>(static_cast<T>(x), static_cast<T>(y)); \
}

#define IM_VEC4_CLASS_EXTRA \
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) { \
} \
operator sf::Color() const { \
return sf::Color(static_cast<std::uint8_t>(x * 255.f), \
static_cast<std::uint8_t>(y * 255.f), \
static_cast<std::uint8_t>(z * 255.f), \
static_cast<std::uint8_t>(w * 255.f)); \
#define IM_VEC4_CLASS_EXTRA \
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) \
{ \
} \
operator sf::Color() const \
{ \
return sf::Color(static_cast<std::uint8_t>(x * 255.f), \
static_cast<std::uint8_t>(y * 255.f), \
static_cast<std::uint8_t>(z * 255.f), \
static_cast<std::uint8_t>(w * 255.f)); \
}
Loading

0 comments on commit 3e2576d

Please sign in to comment.