Skip to content
Open
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
39 changes: 39 additions & 0 deletions library/cmake/MinGWCross.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,42 @@ if(NOT DEFINED ENV{MINGW_DEBUG_INFO})
# So that the debug info only appears once
set(ENV{MINGW_DEBUG_INFO} SHOWN)
endif()

# Set the toolchain prefix
set(MINGW_PREFIX /usr)
set(MINGW_TOOL_PREFIX x86_64-w64-mingw32-)

# Set the compilers with full paths
find_program(MINGW_CC ${MINGW_TOOL_PREFIX}gcc
PATHS /usr/bin /usr/local/bin /usr/x86_64-w64-mingw32/bin
REQUIRED)
find_program(MINGW_CXX ${MINGW_TOOL_PREFIX}g++
PATHS /usr/bin /usr/local/bin /usr/x86_64-w64-mingw32/bin
REQUIRED)
find_program(MINGW_WINDRES ${MINGW_TOOL_PREFIX}windres
PATHS /usr/bin /usr/local/bin /usr/x86_64-w64-mingw32/bin
REQUIRED)

set(CMAKE_C_COMPILER ${MINGW_CC})
set(CMAKE_CXX_COMPILER ${MINGW_CXX})
set(CMAKE_RC_COMPILER ${MINGW_WINDRES})

# Set the pkg-config executable
find_program(MINGW_PKGCONFIG ${MINGW_TOOL_PREFIX}pkg-config
PATHS /usr/bin /usr/local/bin /usr/x86_64-w64-mingw32/bin)
if(MINGW_PKGCONFIG)
set(ENV{PKG_CONFIG} ${MINGW_PKGCONFIG})
endif()

# Set the find root path
set(CMAKE_FIND_ROOT_PATH /usr/x86_64-w64-mingw32)
set(SDL2_PATH /usr/x86_64-w64-mingw32)

# Set the default flags
set(CMAKE_C_FLAGS_INIT "-D_WIN32_WINNT=0x0601")
set(CMAKE_CXX_FLAGS_INIT "${CMAKE_C_FLAGS_INIT} -std=gnu++17")

# Set the default link flags
set(CMAKE_EXE_LINKER_FLAGS_INIT "-static-libgcc -static-libstdc++ -Wl,--enable-auto-import")
set(CMAKE_SHARED_LINKER_FLAGS_INIT "-static-libgcc -static-libstdc++ -Wl,--enable-auto-import")
set(CMAKE_MODULE_LINKER_FLAGS_INIT "-static-libgcc -static-libstdc++ -Wl,--enable-auto-import")
8 changes: 8 additions & 0 deletions library/include/borealis/core/application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,12 @@ class Application
*/
static std::string getLocale();

/**
* Fuerza el locale de la aplicación (i18n) a un valor específico.
* Llamar antes de Application::init().
*/
static void setLocale(const std::string& locale);

static void addToFreeQueue(View* view);

/**
Expand Down Expand Up @@ -444,6 +450,8 @@ class Application
static void registerBuiltInXMLViews();

inline static DebugLayer* debugLayer = nullptr;

static std::string forcedLocale;
};

} // namespace brls
4 changes: 4 additions & 0 deletions library/include/borealis/views/button.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ enum class ButtonState
class Button : public Box
{
public:
/**
* Reemplaza el contenido interno del botón por cualquier vista personalizada (por ejemplo, un Box vertical con imagen y texto).
*/
void setCustomContent(brls::View* view);
Button();

void onFocusGained() override;
Expand Down
23 changes: 14 additions & 9 deletions library/include/borealis/views/dialog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,22 @@ class DialogButton
// A modal dialog with zero to three buttons
// and anything as content
// Create the dialog then use open() and close()
class Dialog : public Box
{
class Dialog : public Box {
private:
std::string text;
brls::Label* label = nullptr;
BRLS_BIND(Box, container, "brls/dialog/container");
BRLS_BIND(AppletFrame, appletFrame, "brls/dialog/applet");

unsigned frameX, frameY, frameWidth, frameHeight;

std::vector<DialogButton*> buttons;

void rebuildButtons();
void buttonClick(DialogButton* button);

bool cancelable = true;

protected:
BRLS_BIND(Button, button1, "brls/dialog/button1");
BRLS_BIND(Button, button2, "brls/dialog/button2");
BRLS_BIND(Button, button3, "brls/dialog/button3");

BRLS_BIND(Rectangle, button2separator, "brls/dialog/button2/separator");
BRLS_BIND(Rectangle, button3separator, "brls/dialog/button3/separator");

Expand All @@ -66,6 +62,16 @@ class Dialog : public Box
Dialog(Box* contentView);
~Dialog();

/**
* Cambia el texto del diálogo (solo si fue creado con string)
*/
void setText(const std::string& newText) {
this->text = newText;
if (this->label)
this->label->setText(newText);
}
const std::string& getText() const { return this->text; }

AppletFrame* getAppletFrame() override;

/**
Expand All @@ -89,8 +95,7 @@ class Dialog : public Box
virtual void open();
void close(std::function<void(void)> cb = [] {});

bool isTranslucent() override
{
bool isTranslucent() override {
return true;
}
};
Expand Down
3 changes: 3 additions & 0 deletions library/include/borealis/views/label.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ class Label : public View
static inline bool OPENCC_ON = true;
void setCursor(int cursor);

// Permite medir el ancho real de un texto con una fuente y tamaño dados
static float measureTextWidth(int font, float fontSize, const std::string& text);

protected:
std::string truncatedText;
std::string fullText;
Expand Down
12 changes: 12 additions & 0 deletions library/lib/core/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
#include <cstdio>
#include <cstdlib>
#include <cmath>
#ifndef YG_ENABLE_EVENTS
#define YG_ENABLE_EVENTS
#endif
#include <yoga/YGNode.h>
#include <yoga/event/event.h>

Expand Down Expand Up @@ -68,6 +71,8 @@
namespace brls
{

std::string Application::forcedLocale = "";

bool Application::init()
{
Application::inited = false;
Expand Down Expand Up @@ -1047,9 +1052,16 @@ ImeManager* Application::getImeManager()

std::string Application::getLocale()
{
if (!forcedLocale.empty())
return forcedLocale;
return Application::getPlatform()->getLocale();
}

void Application::setLocale(const std::string& locale)
{
forcedLocale = locale;
}

void Application::addToFreeQueue(View* view)
{
if (std::binary_search(deletionPool.cbegin(), deletionPool.cend(), view))
Expand Down
15 changes: 14 additions & 1 deletion library/lib/views/button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@ const std::string buttonXML = R"xml(
</brls:Box>
)xml";

// Permite reemplazar el contenido interno del botón por cualquier vista personalizada
void Button::setCustomContent(brls::View* view)
{
// Elimina todas las vistas hijas actuales (incluyendo el label por defecto)
auto& children = this->getChildren();
while (!children.empty()) {
this->removeView(children.back());
}
// Añade la vista personalizada
this->addView(view);
// Opcional: guarda referencia si se requiere para gestión posterior
}
Button::Button()
{
this->inflateFromXMLString(buttonXML);
Expand Down Expand Up @@ -176,7 +188,8 @@ void Button::setTextColor(NVGcolor color)

void Button::setText(std::string text)
{
this->label->setText(text);
if (this->label)
this->label->setText(text);
}

void Button::setFontSize(float value)
Expand Down
13 changes: 7 additions & 6 deletions library/lib/views/dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,15 @@ Dialog::Dialog(std::string text)
{
Style style = Application::getStyle();

Label* label = new Label();
label->setText(text);
label->setFontSize(style["brls/dialog/fontSize"]);
label->setHorizontalAlign(HorizontalAlign::CENTER);
label->setSingleLine(false);

this->label = new Label();
this->label->setText(text);
this->label->setFontSize(style["brls/dialog/fontSize"]);
this->label->setHorizontalAlign(HorizontalAlign::CENTER);
this->label->setSingleLine(false);

Box* box = new Box();
box->addView(label);
box->addView(this->label);
box->setAlignItems(AlignItems::CENTER);
box->setJustifyContent(JustifyContent::CENTER);
box->setPadding(style["brls/dialog/paddingTopBottom"], style["brls/dialog/paddingLeftRight"], style["brls/dialog/paddingTopBottom"], style["brls/dialog/paddingLeftRight"]);
Expand Down
10 changes: 10 additions & 0 deletions library/lib/views/label.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -678,4 +678,14 @@ View* Label::create()
return new Label();
}

float brls::Label::measureTextWidth(int font, float fontSize, const std::string& text) {
NVGcontext* vg = brls::Application::getNVGContext();
if (!vg) return 0.0f;
nvgFontFaceId(vg, font);
nvgFontSize(vg, fontSize);
float bounds[4];
nvgTextBounds(vg, 0, 0, text.c_str(), nullptr, bounds);
return bounds[2] - bounds[0];
}

} // namespace brls