Adds scalable image via aspect ratio setting
This commit is contained in:
parent
3694215fcb
commit
942c96e546
@ -66,10 +66,16 @@ Napi::Value QPixmapWrap::scaled(const Napi::CallbackInfo& info)
|
||||
{
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
Napi::Number width = info[0].As<Napi::Number>();
|
||||
Napi::Number height = info[1].As<Napi::Number>();
|
||||
|
||||
QPixmap* updatedPixMap = new QPixmap(this->instance->scaled(width, height));
|
||||
Napi::Number widthValue = info[0].As<Napi::Number>();
|
||||
Napi::Number heightValue = info[1].As<Napi::Number>();
|
||||
int width = widthValue.Int32Value();
|
||||
int height = heightValue.Int32Value();
|
||||
Qt::AspectRatioMode aspectRatioMode = Qt::IgnoreAspectRatio;
|
||||
if(info.Length() > 2){
|
||||
int aspectRatioModeInt = info[2].As<Napi::Number>().Int32Value();
|
||||
aspectRatioMode = static_cast<Qt::AspectRatioMode>(aspectRatioModeInt);
|
||||
}
|
||||
QPixmap* updatedPixMap = new QPixmap(this->instance->scaled(width, height, aspectRatioMode));
|
||||
auto instance = QPixmapWrap::constructor.New({ Napi::External<QPixmap>::New(env, updatedPixMap) });
|
||||
return instance;
|
||||
}
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
#include "src/cpp/core/YogaWidget/yogawidget_macro.h"
|
||||
#include "src/cpp/core/Events/eventwidget_macro.h"
|
||||
#include "src/cpp/core/Component/component_macro.h"
|
||||
#include <QSize>
|
||||
/*
|
||||
|
||||
This macro adds common QWidgets exported methods
|
||||
@ -121,6 +122,15 @@ Napi::Value update(const Napi::CallbackInfo& info){ \
|
||||
this->instance->update(); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
Napi::Value size(const Napi::CallbackInfo& info){ \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
QSize size = this->instance->size(); \
|
||||
Napi::Object sizeObj = Napi::Object::New(env); \
|
||||
sizeObj.Set("width", size.width()); \
|
||||
sizeObj.Set("height", size.height()); \
|
||||
return sizeObj; \
|
||||
} \
|
||||
|
||||
#endif //QWIDGET_WRAPPED_METHODS_DECLARATION
|
||||
|
||||
@ -144,6 +154,7 @@ Napi::Value update(const Napi::CallbackInfo& info){ \
|
||||
InstanceMethod("setMinimumSize",&WidgetWrapName::setMinimumSize), \
|
||||
InstanceMethod("repaint",&WidgetWrapName::repaint), \
|
||||
InstanceMethod("update",&WidgetWrapName::update), \
|
||||
InstanceMethod("size",&WidgetWrapName::size), \
|
||||
|
||||
#endif // QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE
|
||||
|
||||
|
||||
5
src/lib/QtEnums/index.ts
Normal file
5
src/lib/QtEnums/index.ts
Normal file
@ -0,0 +1,5 @@
|
||||
export enum AspectRatioMode {
|
||||
"IgnoreAspectRatio",
|
||||
"KeepAspectRatio",
|
||||
"KeepAspectRatioByExpanding"
|
||||
}
|
||||
@ -1,7 +1,8 @@
|
||||
import addon from "../../core/addon";
|
||||
import { Component, NativeElement } from "../../core/Component";
|
||||
|
||||
import { AspectRatioMode } from "../../QtEnums";
|
||||
type arg = string | NativeElement;
|
||||
|
||||
export class QPixmap extends Component {
|
||||
native: NativeElement;
|
||||
constructor(arg?: arg) {
|
||||
@ -18,8 +19,12 @@ export class QPixmap extends Component {
|
||||
load = (imageUrl: string) => {
|
||||
return this.native.load(imageUrl);
|
||||
};
|
||||
scaled = (width: number, height: number): QPixmap => {
|
||||
const nativePixmap = this.native.scaled(width, height);
|
||||
scaled = (
|
||||
width: number,
|
||||
height: number,
|
||||
aspectRatioMode?: AspectRatioMode
|
||||
): QPixmap => {
|
||||
const nativePixmap = this.native.scaled(width, height, aspectRatioMode);
|
||||
return new QPixmap(nativePixmap);
|
||||
};
|
||||
}
|
||||
|
||||
@ -57,6 +57,9 @@ export abstract class NodeWidget extends EventWidget {
|
||||
update = () => {
|
||||
this.native.update();
|
||||
};
|
||||
size = (): { width: number; height: number } => {
|
||||
return this.native.size();
|
||||
};
|
||||
}
|
||||
|
||||
export class QWidget extends NodeWidget {
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
// enums
|
||||
export { AspectRatioMode } from "./QtEnums";
|
||||
export { QApplication } from "./QtGui/QApplication";
|
||||
export { QWidget, QWidgetEvents } from "./QtGui/QWidget";
|
||||
export { QPixmap } from "./QtGui/QPixmap";
|
||||
|
||||
Loading…
Reference in New Issue
Block a user