Skip to content
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
4 changes: 2 additions & 2 deletions samples/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ static constexpr Id RootPanelId = 1;

static constexpr Id NextPanelId = 100;

int quit(uint32_t, void *instance) {
int quit(Id, void *instance) {
if (instance == nullptr) {
return ErrorCode;
}
Expand All @@ -46,7 +46,7 @@ static uint32_t LastTick = 0;
static uint32_t Diff = 0;
static constexpr uint32_t TimeDiff = 10;

int updateProgressbar(uint32_t, void *instance) {
int updateProgressbar(Id, void *instance) {
if (instance == nullptr) {
return ErrorCode;
}
Expand Down
6 changes: 3 additions & 3 deletions src/tinyui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ static Style DefaultStyle {
{ "Arial.ttf", 35, nullptr }
};

static const char *SeverityToken[] = {
static constexpr char const *SeverityToken[] = {
"",
"*TRACE*",
"*DEBUG*",
Expand All @@ -57,7 +57,7 @@ void log_message(LogSeverity severity, const char *message) {

Context *gCtx = nullptr;

Context *Context::create(const char *title, Style &style) {
Context *Context::create(const char *title, const Style &style) {
Context *ctx = new Context;
ctx->mLogger = log_message;
ctx->mAppTitle = title;
Expand All @@ -71,7 +71,7 @@ void Context::destroy(Context *ctx) {
delete ctx;
}

bool TinyUi::createContext(const char *title, Style &style) {
bool TinyUi::createContext(const char *title, const Style &style) {
if (gCtx != nullptr) {
return false;
}
Expand Down
11 changes: 7 additions & 4 deletions src/tinyui.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@

// Type declarations ----------------------------------------------------------

/// @brief This enum is used to describe the alignment of a widget.
using Id = uint64_t;

/// @brief The return code type used in the ui library.
using ret_code = int32_t;

Expand Down Expand Up @@ -319,7 +322,7 @@
/// @brief This interface is used to store all neede message handlers.
struct CallbackI {
/// The function callback
typedef int (*funcCallback) (uint32_t id, void *data);
typedef int (*funcCallback) (Id id, void *data);

Check warning on line 325 in src/tinyui.h

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

"using" should be preferred to "typedef" for type aliasing.

See more on https://sonarcloud.io/project/issues?id=kimkulling_tiny_ui&issues=AZzysdH7P-CYkGMXwAh2&open=AZzysdH7P-CYkGMXwAh2&pullRequest=21
/// The function callback array, not handled callbacks are marked as a nullptr.
funcCallback mfuncCallback[Events::NumEvents];
/// The data instance.
Expand All @@ -336,7 +339,7 @@
/// @param callbackFunc The callback function.
/// @param instance The instance to use.
/// @param eventType The event type to use.
CallbackI(funcCallback callbackFunc, void *instance, size_t eventType = Events::MouseButtonDownEvent) :
CallbackI(funcCallback callbackFunc, void *instance, size_t eventType = Events::MouseButtonDownEvent) :
mfuncCallback{ nullptr }, mInstance(instance) {
clear();
mfuncCallback[eventType] = callbackFunc;
Expand Down Expand Up @@ -411,7 +414,7 @@
/// @param title The title of the context.
/// @param style The style to use.
/// @return The created context.
static Context *create(const char *title, Style &style);
static Context *create(const char *title, const Style &style);

/// @brief Will destroy a valid tinyui context.
/// @param ctx The context to destroy.
Expand All @@ -431,7 +434,7 @@
/// @param title The app title.
/// @param style The style to use.
/// @return true if successful.
static bool createContext(const char *title, Style &style);
static bool createContext(const char *title, const Style &style);

/// @brief Will destroy the context.
/// @return true if successful.
Expand Down
27 changes: 18 additions & 9 deletions src/widgets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@

static void releaseImageCache(Context &ctx) {
for (auto it = ctx.mImageCache.begin(); it != ctx.mImageCache.end(); ++it) {
Image *image = it->second;
if (image != nullptr) {
if (Image *image = it->second; image != nullptr) {
Renderer::releaseSurfaceImpl(image->mSurfaceImpl);
delete image;
}
Expand Down Expand Up @@ -125,10 +124,10 @@
if (widget != nullptr) {
if (widget->mType == type) {
return widget;
} else {
ctx.mLogger(LogSeverity::Error, "A widget with the same id but different type already exists.");
return nullptr;
}
}

ctx.mLogger(LogSeverity::Error, "A widget with the same id but different type already exists.");
return nullptr;
}

widget = new Widget;
Expand Down Expand Up @@ -344,7 +343,7 @@
if (ctx.mRoot == nullptr) {
return InvalidRenderHandle;
}
Widget *child = createWidget(ctx, id, parentId, rect, WidgetType::Box);
Widget *child = createWidget(ctx, id, parentId, rect, WidgetType::ImageBox);
if (child == nullptr) {
return ErrorCode;
}
Expand All @@ -371,7 +370,7 @@
return ResultOk;
}

static int onTreeViewItemClicked(uint32_t id, void *data) {
static int onTreeViewItemClicked(Id id, void *data) {

Check failure on line 373 in src/widgets.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace this use of "void *" with a more meaningful type.

See more on https://sonarcloud.io/project/issues?id=kimkulling_tiny_ui&issues=AZzysdFMP-CYkGMXwAh1&open=AZzysdFMP-CYkGMXwAh1&pullRequest=21

Check warning on line 373 in src/widgets.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove the unused parameter "data", make it unnamed, or declare it "[[maybe_unused]]".

See more on https://sonarcloud.io/project/issues?id=kimkulling_tiny_ui&issues=AZzysdFMP-CYkGMXwAh0&open=AZzysdFMP-CYkGMXwAh0&pullRequest=21
Widget *treeView = Widgets::findWidget(id, TinyUi::getContext().mRoot);
if (treeView == nullptr) {
return ErrorCode;
Expand Down Expand Up @@ -437,7 +436,8 @@
const int32_t w = parentRect.width;
const int32_t h = parentRect.height;
size_t numChildren = parentWidget->mChildren.size() + 1;
const Rect rect(parentRect.top.x + margin, parentRect.top.y + numChildren * margin + numChildren * h, w, h);
const Rect rect(parentRect.top.x + margin, parentRect.top.y + numChildren * margin +
static_cast<int32_t>(numChildren) * h, w, h);
Widget *child = createWidget(ctx, id, parentItemId, rect, WidgetType::Label);
if (child == nullptr) {
return ErrorCode;
Expand Down Expand Up @@ -568,6 +568,15 @@
Renderer::drawRect(ctx, r.top.x, r.top.y, r.width, r.height, currentWidget->mFilledRect, ctx.mStyle.mBorder);
}
break;

case WidgetType::ImageBox:
{
Renderer::drawRect(ctx, r.top.x, r.top.y, r.width, r.height, currentWidget->mFilledRect, ctx.mStyle.mBorder);
if (currentWidget->mImage != nullptr) {
Renderer::drawImage(ctx, r.top.x, r.top.y, r.width, r.height, currentWidget->mImage);
}
}
break;
}

for (auto &child : currentWidget->mChildren) {
Expand Down
10 changes: 4 additions & 6 deletions src/widgets.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ enum class WidgetType {
Container = 0, ///< A container widget
Button, ///< A button widget
Label, ///< A label widget
InputField, ///<
InputField, ///< An input field widget
Panel, ///< A panel widget
Box, ///< A box widget
TreeView, ///< A treeeview widget
ImageBox, ///< An image box widget
TreeView, ///< A treeview widget
ProgressBar, ///< A status bar widget
Count ///< The number of widgets
};
Expand All @@ -56,10 +57,7 @@ struct FilledState {
uint32_t filledState{0}; ///< The filled state in percent (0-100)
};

/// @brief This enum is used to descripe the alignment of a widget.
using Id = uint64_t;

/// @brief This enum is used to descripe the alignment of a widget.
/// @brief This enum is used to describe the alignment of a widget.
enum class WidgetStyle {
Invalid = -1,
BorderStyle, ///< The widget has a border
Expand Down
Loading