Skip to content

Commit

Permalink
add getStringWidth method
Browse files Browse the repository at this point in the history
  • Loading branch information
scheffle committed Mar 23, 2024
1 parent 2d2a277 commit d08fbb1
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions vstgui/uidescription-scripting/detail/drawcontextobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,14 @@ struct DrawContextObject::Impl
context->restoreGlobalState ();
--globalStatesStored;
}
void getStringWidth (CScriptVar* var) const
{
static constexpr auto signature = "drawContext.getStringWidth(string);"sv;
checkContextOrThrow ();
auto stringVar = getArgument (var, "string"sv, signature);
auto width = context->getStringWidth (stringVar->getString ().data ());
var->getReturnVar ()->setDouble (width);
}
};

//------------------------------------------------------------------------
Expand All @@ -342,6 +350,7 @@ DrawContextObject::DrawContextObject ()
impl = std::make_unique<Impl> ();
scriptVar->setLifeTimeObserver (this);
addFunc ("clearRect"sv, [this] (auto var) { impl->clearRect (var); }, {"rect"sv, "style"sv});
addFunc ("getStringWidth"sv, [this] (auto var) { impl->getStringWidth (var); }, {"string"sv});
addFunc ("drawArc"sv, [this] (auto var) { impl->drawArc (var); },
{"rect"sv, "startAngle"sv, "endAngle"sv, "style"sv});
addFunc ("drawBitmap"sv, [this] (auto var) { impl->drawBitmap (var); },
Expand Down

0 comments on commit d08fbb1

Please sign in to comment.