Skip to content

Commit fa1254e

Browse files
committed
Added linting in Github Actions with clang-format
1 parent 86ad463 commit fa1254e

29 files changed

+257
-204
lines changed

.clang-format

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
BasedOnStyle: Webkit
3+
AlignAfterOpenBracket: BlockIndent
4+
AlignConsecutiveMacros: true
5+
AlignTrailingComments: true
6+
AllowShortCaseLabelsOnASingleLine: false
7+
AllowShortFunctionsOnASingleLine: Inline
8+
AlwaysBreakTemplateDeclarations: Yes
9+
BreakBeforeBraces: Allman
10+
BreakBeforeTernaryOperators: true
11+
BreakConstructorInitializers: AfterColon
12+
ColumnLimit: 120
13+
ConstructorInitializerAllOnOneLineOrOnePerLine: true
14+
Cpp11BracedListStyle: true
15+
MaxEmptyLinesToKeep: 2
16+
PackConstructorInitializers: Never
17+
SortIncludes: false
18+
SpaceBeforeCtorInitializerColon: false
19+
SpaceBeforeInheritanceColon: false
20+
SpaceBeforeRangeBasedForLoopColon: false

.github/workflows/ci.yml

+9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
on: [push, pull_request]
22

33
jobs:
4+
lint:
5+
name: Clang-format
6+
runs-on: ubuntu-22.04
7+
steps:
8+
- uses: actions/checkout@v2
9+
- name: Install dependencies
10+
run: sudo apt install clang-format
11+
- name: Run clang-format
12+
run: clang-format $(find src -type f) --dry-run -Werror
413
build:
514
name: Compile
615
runs-on: ubuntu-latest

compile_flags.txt

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
-I./src
2+
-std=c++11
3+
-Wall
4+
-Wextra
5+
-Wshadow
6+
-Wwrite-strings

lint.sh

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
3+
clang-format $(find src -type f) -i
4+
echo "Done"

src/Gui/Button.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ class Button: public Widget
2323

2424
const sf::String& getString() const;
2525

26-
// callbacks ---------------------------------------------------------------
27-
26+
protected:
27+
// Callbacks
2828
void onStateChanged(State state) override;
2929
void onMouseMoved(float x, float y) override;
3030
void onMousePressed(float x, float y) override;

src/Gui/CheckBox.hpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,18 @@ class CheckBox: public Widget
2121

2222
void check(bool checked);
2323

24-
// callbacks ---------------------------------------------------------------
25-
24+
protected:
25+
// Callbacks
2626
void onStateChanged(State state) override;
2727
void onMouseReleased(float x, float y) override;
2828
void onKeyPressed(const sf::Event::KeyEvent& key) override;
2929

3030
private:
3131
void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
3232

33-
Box m_box;
33+
Box m_box;
3434
Cross m_cross;
35-
bool m_checked;
35+
bool m_checked;
3636
};
3737

3838
}

src/Gui/Image.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class Image: public Widget
2323
private:
2424
void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
2525

26-
sf::Vertex m_vertices[4];
26+
sf::Vertex m_vertices[4];
2727
const sf::Texture* m_texture;
2828
};
2929

src/Gui/Label.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ void Label::draw(sf::RenderTarget& target, sf::RenderStates states) const
6363
void Label::updateGeometry()
6464
{
6565
Widget::setSize(
66-
m_text.getLocalBounds().width + Theme::PADDING * 2,
67-
m_text.getLocalBounds().height + Theme::PADDING * 2
66+
m_text.getLocalBounds().width + Theme::PADDING * 2, m_text.getLocalBounds().height + Theme::PADDING * 2
6867
);
6968
}
7069

src/Gui/Layouts/Layout.hpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ class Layout: public Widget
3131
Widget* add(Widget* widget);
3232

3333
/// Helpers
34-
Button* addButton(const sf::String& string, std::function<void(void)> callback);
35-
Label* addLabel(const sf::String& string);
34+
Button* addButton(const sf::String& string, std::function<void(void)> callback);
35+
Label* addLabel(const sf::String& string);
3636
FormLayout* addFormLayout();
3737
HBoxLayout* addHBoxLayout();
3838
VBoxLayout* addVBoxLayout();
@@ -50,7 +50,7 @@ class Layout: public Widget
5050
void onKeyReleased(const sf::Event::KeyEvent& key) override;
5151
void onTextEntered(sf::Uint32 unicode) override;
5252

53-
Layout* toLayout() override { return this; } // hack?
53+
inline Layout* toLayout() override { return this; }
5454
bool focusNextWidget();
5555
bool focusPreviousWidget();
5656

@@ -64,10 +64,10 @@ class Layout: public Widget
6464
*/
6565
bool focusWidget(Widget* widget);
6666

67-
Widget* m_first;
68-
Widget* m_last;
69-
Widget* m_hover;
70-
Widget* m_focus;
67+
Widget* m_first;
68+
Widget* m_last;
69+
Widget* m_hover;
70+
Widget* m_focus;
7171
};
7272

7373
}

src/Gui/Menu.hpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,17 @@
77
namespace gui
88
{
99

10+
/**
11+
* Entry point for the GUI.
12+
* A Menu is a VBoxLayout with a general onEvent handler
13+
*/
1014
class Menu: public gui::VBoxLayout
1115
{
1216
public:
1317
Menu(sf::RenderTarget& window);
1418

1519
/**
16-
* Handle event and send it to widgets
17-
* @return triggered widget ID, or -1 if none
20+
* Handle an SFML event and send it to widgets
1821
*/
1922
void onEvent(const sf::Event& event);
2023

src/Gui/OptionsBox.hpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ class OptionsBox: public Widget
5252
*/
5353
void selectPrevious();
5454

55-
// callbacks ---------------------------------------------------------------
56-
55+
protected:
56+
// Callbacks
5757
void onStateChanged(State state) override;
5858
void onMouseMoved(float x, float y) override;
5959
void onMousePressed(float x, float y) override;
@@ -75,13 +75,13 @@ class OptionsBox: public Widget
7575
};
7676

7777
typedef std::vector<Item> ItemVector;
78-
ItemVector m_items;
79-
size_t m_current_index;
78+
ItemVector m_items;
79+
size_t m_currentIndex;
8080

8181
// Visual components
82-
ItemBox<sf::Text> m_box;
83-
ItemBox<Arrow> m_arrow_left;
84-
ItemBox<Arrow> m_arrow_right;
82+
ItemBox<sf::Text> m_box;
83+
ItemBox<Arrow> m_arrowLeft;
84+
ItemBox<Arrow> m_arrowRight;
8585
};
8686

8787
}

src/Gui/OptionsBox.inl

+33-33
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,24 @@ namespace gui
55

66
template <class T>
77
OptionsBox<T>::OptionsBox():
8-
m_current_index(-1),
8+
m_currentIndex(-1),
99
m_box(Box::Input),
10-
m_arrow_left(Arrow(Arrow::Left)),
11-
m_arrow_right(Arrow(Arrow::Right))
10+
m_arrowLeft(Arrow(Arrow::Left)),
11+
m_arrowRight(Arrow(Arrow::Right))
1212
{
1313
// Build visual components
1414
m_box.item().setFont(Theme::getFont());
1515
m_box.item().setCharacterSize(Theme::textSize);
1616
m_box.setSize(Theme::minWidgetWidth, Theme::getBoxHeight());
1717

1818
// Pack left arrow
19-
m_arrow_left.setSize(Theme::getBoxHeight(), Theme::getBoxHeight());
20-
m_arrow_left.centerItem(m_arrow_left.item());
19+
m_arrowLeft.setSize(Theme::getBoxHeight(), Theme::getBoxHeight());
20+
m_arrowLeft.centerItem(m_arrowLeft.item());
2121

2222
// Pack right arrow
23-
m_arrow_right.setSize(Theme::getBoxHeight(), Theme::getBoxHeight());
24-
m_arrow_right.setPosition(m_box.getSize().x - Theme::getBoxHeight(), 0);
25-
m_arrow_right.centerItem(m_arrow_right.item());
23+
m_arrowRight.setSize(Theme::getBoxHeight(), Theme::getBoxHeight());
24+
m_arrowRight.setPosition(m_box.getSize().x - Theme::getBoxHeight(), 0);
25+
m_arrowRight.centerItem(m_arrowRight.item());
2626

2727
// Widget local bounds
2828
setSize(m_box.getSize());
@@ -40,8 +40,8 @@ void OptionsBox<T>::addItem(const sf::String& label, const T& value)
4040
if (width > getSize().x)
4141
{
4242
m_box.setSize(width, Theme::getBoxHeight());
43-
m_arrow_right.setPosition(width - Theme::getBoxHeight(), 0);
44-
m_arrow_right.centerItem(m_arrow_right.item());
43+
m_arrowRight.setPosition(width - Theme::getBoxHeight(), 0);
44+
m_arrowRight.centerItem(m_arrowRight.item());
4545
setSize(m_box.getSize());
4646
}
4747

@@ -54,7 +54,7 @@ void OptionsBox<T>::selectItem(size_t item_index)
5454
{
5555
if (item_index < m_items.size())
5656
{
57-
m_current_index = item_index;
57+
m_currentIndex = item_index;
5858
m_box.item().setString(m_items[item_index].label);
5959
m_box.centerText(m_box.item());
6060
}
@@ -64,14 +64,14 @@ void OptionsBox<T>::selectItem(size_t item_index)
6464
template <class T>
6565
const T& OptionsBox<T>::getSelectedValue() const
6666
{
67-
return m_items[m_current_index].value;
67+
return m_items[m_currentIndex].value;
6868
}
6969

7070

7171
template <class T>
7272
size_t OptionsBox<T>::getSelectedIndex() const
7373
{
74-
return m_current_index;
74+
return m_currentIndex;
7575
}
7676

7777

@@ -81,7 +81,7 @@ void OptionsBox<T>::selectNext()
8181
if (m_items.size() > 1)
8282
{
8383
// Get next item index
84-
selectItem(m_current_index == (m_items.size() - 1) ? 0 : m_current_index + 1);
84+
selectItem(m_currentIndex == (m_items.size() - 1) ? 0 : m_currentIndex + 1);
8585
triggerCallback();
8686
}
8787
}
@@ -93,7 +93,7 @@ void OptionsBox<T>::selectPrevious()
9393
if (m_items.size() > 1)
9494
{
9595
// Get previous item index
96-
selectItem(m_current_index == 0 ? m_items.size() - 1 : m_current_index - 1);
96+
selectItem(m_currentIndex == 0 ? m_items.size() - 1 : m_currentIndex - 1);
9797
triggerCallback();
9898
}
9999
}
@@ -104,8 +104,8 @@ void OptionsBox<T>::draw(sf::RenderTarget& target, sf::RenderStates states) cons
104104
{
105105
states.transform *= getTransform();
106106
target.draw(m_box, states);
107-
target.draw(m_arrow_left, states);
108-
target.draw(m_arrow_right, states);
107+
target.draw(m_arrowLeft, states);
108+
target.draw(m_arrowRight, states);
109109
}
110110

111111

@@ -134,8 +134,8 @@ void OptionsBox<T>::onStateChanged(State state)
134134
// Hovered state is handled in the onMouseMoved callback
135135
if (state == StateDefault || state == StateFocused)
136136
{
137-
m_arrow_left.applyState(state);
138-
m_arrow_right.applyState(state);
137+
m_arrowLeft.applyState(state);
138+
m_arrowRight.applyState(state);
139139
m_box.applyState(state);
140140
}
141141
}
@@ -144,34 +144,34 @@ void OptionsBox<T>::onStateChanged(State state)
144144
template <class T>
145145
void OptionsBox<T>::onMouseMoved(float x, float y)
146146
{
147-
updateArrow(m_arrow_left, x, y);
148-
updateArrow(m_arrow_right, x, y);
147+
updateArrow(m_arrowLeft, x, y);
148+
updateArrow(m_arrowRight, x, y);
149149
}
150150

151151

152152
template <class T>
153153
void OptionsBox<T>::onMousePressed(float x, float y)
154154
{
155-
if (m_arrow_left.containsPoint(x, y))
156-
m_arrow_left.press();
155+
if (m_arrowLeft.containsPoint(x, y))
156+
m_arrowLeft.press();
157157

158-
else if (m_arrow_right.containsPoint(x, y))
159-
m_arrow_right.press();
158+
else if (m_arrowRight.containsPoint(x, y))
159+
m_arrowRight.press();
160160
}
161161

162162

163163
template <class T>
164164
void OptionsBox<T>::onMouseReleased(float x, float y)
165165
{
166-
if (m_arrow_left.containsPoint(x, y))
166+
if (m_arrowLeft.containsPoint(x, y))
167167
{
168168
selectPrevious();
169-
m_arrow_left.release();
169+
m_arrowLeft.release();
170170
}
171-
else if (m_arrow_right.containsPoint(x, y))
171+
else if (m_arrowRight.containsPoint(x, y))
172172
{
173173
selectNext();
174-
m_arrow_right.release();
174+
m_arrowRight.release();
175175
}
176176
}
177177

@@ -182,12 +182,12 @@ void OptionsBox<T>::onKeyPressed(const sf::Event::KeyEvent& key)
182182
if (key.code == sf::Keyboard::Left)
183183
{
184184
selectPrevious();
185-
m_arrow_left.press();
185+
m_arrowLeft.press();
186186
}
187187
else if (key.code == sf::Keyboard::Right)
188188
{
189189
selectNext();
190-
m_arrow_right.press();
190+
m_arrowRight.press();
191191
}
192192
}
193193

@@ -197,11 +197,11 @@ void OptionsBox<T>::onKeyReleased(const sf::Event::KeyEvent& key)
197197
{
198198
if (key.code == sf::Keyboard::Left)
199199
{
200-
m_arrow_left.release();
200+
m_arrowLeft.release();
201201
}
202202
else if (key.code == sf::Keyboard::Right)
203203
{
204-
m_arrow_right.release();
204+
m_arrowRight.release();
205205
}
206206
}
207207

src/Gui/ProgressBar.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ void ProgressBar::setValue(float value)
3636
float x = Theme::borderSize + (getSize().x - Theme::borderSize * 2) * value / 100;
3737
m_bar[1].position.x = m_bar[2].position.x = x;
3838

39-
m_text.setString(std::to_string((int) value) + "%");
39+
m_text.setString(std::to_string((int)value) + "%");
4040
m_box.centerText(m_text);
4141

4242
m_value = value;

src/Gui/ProgressBar.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ class ProgressBar: public Widget
2323
private:
2424
void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
2525

26-
Box m_box;
26+
Box m_box;
2727
sf::Vertex m_bar[4];
28-
sf::Text m_text;
29-
float m_value;
28+
sf::Text m_text;
29+
float m_value;
3030
};
3131

3232
}

0 commit comments

Comments
 (0)