Skip to content

Commit

Permalink
Script API: added Button.WrapText, TextPadding properties
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-mogilko committed Oct 11, 2024
1 parent da8297a commit c6561ee
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Editor/AGS.Editor/Resources/agsdefns.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1890,6 +1890,14 @@ builtin managed struct Button extends GUIControl {
/// Gets/sets text alignment inside the button.
import attribute Alignment TextAlignment;
#endif
#ifdef SCRIPT_API_v362
/// Gets/sets whether the button will wrap its text.
import attribute bool WrapText;
/// Gets/sets amount of padding, restricting the text from left and right
import attribute int TextPaddingHorizontal;
/// Gets/sets amount of padding, restricting the text from top and bottom
import attribute int TextPaddingVertical;
#endif
};
builtin managed struct Slider extends GUIControl {
Expand Down
78 changes: 78 additions & 0 deletions Engine/ac/button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,48 @@ void Button_SetTextAlignment(GUIButton *butt, int align)
}
}

bool Button_GetWrapText(GUIButton *butt)
{
return butt->IsWrapText();
}

void Button_SetWrapText(GUIButton *butt, bool wrap)
{
if (butt->IsWrapText() != wrap)
{
butt->SetWrapText(wrap);
butt->MarkChanged();
}
}

int Button_GetTextPaddingHorizontal(GUIButton *butt)
{
return butt->TextPaddingHor;
}

void Button_SetTextPaddingHorizontal(GUIButton *butt, int pad)
{
if (butt->TextPaddingHor != pad)
{
butt->TextPaddingHor = pad;
butt->MarkChanged();
}
}

int Button_GetTextPaddingVertical(GUIButton *butt)
{
return butt->TextPaddingVer;
}

void Button_SetTextPaddingVertical(GUIButton *butt, int pad)
{
if (butt->TextPaddingVer != pad)
{
butt->TextPaddingVer = pad;
butt->MarkChanged();
}
}

//=============================================================================
//
// Script API Functions
Expand Down Expand Up @@ -451,6 +493,36 @@ RuntimeScriptValue Sc_Button_SetTextAlignment(void *self, const RuntimeScriptVal
API_OBJCALL_VOID_PINT(GUIButton, Button_SetTextAlignment);
}

RuntimeScriptValue Sc_Button_GetWrapText(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
API_OBJCALL_BOOL(GUIButton, Button_GetWrapText);
}

RuntimeScriptValue Sc_Button_SetWrapText(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
API_OBJCALL_VOID_PBOOL(GUIButton, Button_SetWrapText);
}

RuntimeScriptValue Sc_Button_GetTextPaddingHorizontal(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
API_OBJCALL_INT(GUIButton, Button_GetTextPaddingHorizontal);
}

RuntimeScriptValue Sc_Button_SetTextPaddingHorizontal(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
API_OBJCALL_VOID_PINT(GUIButton, Button_SetTextPaddingHorizontal);
}

RuntimeScriptValue Sc_Button_GetTextPaddingVertical(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
API_OBJCALL_INT(GUIButton, Button_GetTextPaddingVertical);
}

RuntimeScriptValue Sc_Button_SetTextPaddingVertical(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
API_OBJCALL_VOID_PINT(GUIButton, Button_SetTextPaddingVertical);
}

RuntimeScriptValue Sc_Button_GetAnimFrame(void *self, const RuntimeScriptValue *params, int32_t param_count)
{
API_OBJCALL_INT(GUIButton, Button_GetAnimFrame);
Expand All @@ -477,6 +549,12 @@ void RegisterButtonAPI()
{ "Button::SetText^1", API_FN_PAIR(Button_SetText) },
{ "Button::get_TextAlignment", API_FN_PAIR(Button_GetTextAlignment) },
{ "Button::set_TextAlignment", API_FN_PAIR(Button_SetTextAlignment) },
{ "Button::get_TextPaddingHorizontal", API_FN_PAIR(Button_GetTextPaddingHorizontal) },
{ "Button::set_TextPaddingHorizontal", API_FN_PAIR(Button_SetTextPaddingHorizontal) },
{ "Button::get_TextPaddingVertical", API_FN_PAIR(Button_GetTextPaddingVertical) },
{ "Button::set_TextPaddingVertical", API_FN_PAIR(Button_SetTextPaddingVertical) },
{ "Button::get_WrapText", API_FN_PAIR(Button_GetWrapText) },
{ "Button::set_WrapText", API_FN_PAIR(Button_SetWrapText) },
{ "Button::get_Animating", API_FN_PAIR(Button_IsAnimating) },
{ "Button::get_ClipImage", API_FN_PAIR(Button_GetClipImage) },
{ "Button::set_ClipImage", API_FN_PAIR(Button_SetClipImage) },
Expand Down

0 comments on commit c6561ee

Please sign in to comment.