Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Commit

Permalink
Set the minimum resize size to 0.5x (#1666)
Browse files Browse the repository at this point in the history
  • Loading branch information
MortimerGoro authored and keianhzo committed Aug 27, 2019
1 parent 5801937 commit e5eac7d
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1057,9 +1057,9 @@ public void updateVisibleWidgets() {
}

@Override
public void startWidgetResize(final Widget aWidget, float aMaxWidth, float aMaxHeight) {
public void startWidgetResize(final Widget aWidget, float aMaxWidth, float aMaxHeight, float minWidth, float minHeight) {
mWindows.enterResizeMode();
queueRunnable(() -> startWidgetResizeNative(aWidget.getHandle(), aMaxWidth, aMaxHeight));
queueRunnable(() -> startWidgetResizeNative(aWidget.getHandle(), aMaxWidth, aMaxHeight, minWidth, minHeight));
}

@Override
Expand Down Expand Up @@ -1300,7 +1300,7 @@ public WindowWidget getFocusedWindow() {
private native void updateWidgetNative(int aHandle, WidgetPlacement aPlacement);
private native void updateVisibleWidgetsNative();
private native void removeWidgetNative(int aHandle);
private native void startWidgetResizeNative(int aHandle, float maxWidth, float maxHeight);
private native void startWidgetResizeNative(int aHandle, float maxWidth, float maxHeight, float minWidth, float minHeight);
private native void finishWidgetResizeNative(int aHandle);
private native void startWidgetMoveNative(int aHandle, int aMoveBehaviour);
private native void finishWidgetMoveNative();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -850,8 +850,10 @@ public void onWidgetUpdate(Widget aWidget) {
// Browser window may have been resized, adjust the navigation bar
float targetWidth = aWidget.getPlacement().worldWidth;
float defaultWidth = WidgetPlacement.floatDimension(getContext(), R.dimen.window_world_width);
targetWidth = Math.max(defaultWidth, targetWidth);
targetWidth = Math.min(targetWidth, defaultWidth * 1.5f);
float maxWidth = defaultWidth * 1.5f;
float minWidth = defaultWidth * 0.5f;
targetWidth = Math.max(targetWidth, minWidth);
targetWidth = Math.min(targetWidth, maxWidth);

float ratio = targetWidth / defaultWidth;
mWidgetPlacement.worldWidth = targetWidth;
Expand Down Expand Up @@ -1019,8 +1021,9 @@ private void finishWidgetResize() {

private void startWidgetResize() {
if (mAttachedWindow != null) {
Pair<Float, Float> targetSize = mAttachedWindow.getSizeForScale(mAttachedWindow.getMaxWindowScale());
mWidgetManager.startWidgetResize(mAttachedWindow, targetSize.first, 4.5f);
Pair<Float, Float> maxSize = mAttachedWindow.getSizeForScale(mAttachedWindow.getMaxWindowScale());
Pair<Float, Float> minSize = mAttachedWindow.getSizeForScale(0.5f);
mWidgetManager.startWidgetResize(mAttachedWindow, maxSize.first, 4.5f, minSize.first, minSize.second);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ interface WorldClickListener {
void updateWidget(@NonNull Widget aWidget);
void removeWidget(@NonNull Widget aWidget);
void updateVisibleWidgets();
void startWidgetResize(@NonNull Widget aWidget, float maxWidth, float maxHeight);
void startWidgetResize(@NonNull Widget aWidget, float maxWidth, float maxHeight, float minWidth, float minHeight);
void finishWidgetResize(@NonNull Widget aWidget);
void startWidgetMove(@NonNull Widget aWidget, @WidgetMoveBehaviourFlags int aMoveBehaviour);
void finishWidgetMove();
Expand Down
9 changes: 5 additions & 4 deletions app/src/main/cpp/BrowserWorld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -933,11 +933,11 @@ BrowserWorld::RemoveWidget(int32_t aHandle) {
}

void
BrowserWorld::StartWidgetResize(int32_t aHandle, const vrb::Vector& aMaxSize) {
BrowserWorld::StartWidgetResize(int32_t aHandle, const vrb::Vector& aMaxSize, const vrb::Vector& aMinSize) {
ASSERT_ON_RENDER_THREAD();
WidgetPtr widget = m.GetWidget(aHandle);
if (widget) {
widget->StartResize(aMaxSize);
widget->StartResize(aMaxSize, aMinSize);
}
}

Expand Down Expand Up @@ -1440,8 +1440,9 @@ JNI_METHOD(void, removeWidgetNative)
}

JNI_METHOD(void, startWidgetResizeNative)
(JNIEnv*, jobject, jint aHandle, jfloat aMaxWidth, jfloat aMaxHeight) {
crow::BrowserWorld::Instance().StartWidgetResize(aHandle, vrb::Vector(aMaxWidth, aMaxHeight, 0.0f));
(JNIEnv*, jobject, jint aHandle, jfloat aMaxWidth, jfloat aMaxHeight, jfloat aMinWidth, jfloat aMinHeight) {
crow::BrowserWorld::Instance().StartWidgetResize(aHandle,
vrb::Vector(aMaxWidth, aMaxHeight, 0.0f), vrb::Vector(aMinWidth, aMinHeight, 0.0f));
}

JNI_METHOD(void, finishWidgetResizeNative)
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/cpp/BrowserWorld.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class BrowserWorld {
void AddWidget(int32_t aHandle, const WidgetPlacementPtr& placement);
void UpdateWidget(int32_t aHandle, const WidgetPlacementPtr& aPlacement);
void RemoveWidget(int32_t aHandle);
void StartWidgetResize(int32_t aHandle, const vrb::Vector& aMaxSize);
void StartWidgetResize(int32_t aHandle, const vrb::Vector& aMaxSize, const vrb::Vector& aMinSize);
void FinishWidgetResize(int32_t aHandle);
void StartWidgetMove(int32_t aHandle, const int32_t aMoveBehavour);
void FinishWidgetMove();
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/cpp/Widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ Widget::SetPlacement(const WidgetPlacementPtr& aPlacement) {
}

void
Widget::StartResize(const vrb::Vector& aMaxSize) {
Widget::StartResize(const vrb::Vector& aMaxSize, const vrb::Vector& aMinSize) {
vrb::Vector worldMin, worldMax;
GetWidgetMinAndMax(worldMin, worldMax);
if (m.resizer) {
Expand All @@ -458,7 +458,7 @@ Widget::StartResize(const vrb::Vector& aMaxSize) {
m.resizer = WidgetResizer::Create(create, this);
m.transform->InsertNode(m.resizer->GetRoot(), 0);
}
m.resizer->SetMaxSize(aMaxSize);
m.resizer->SetResizeLimits(aMaxSize, aMinSize);
m.resizing = true;
m.resizer->ToggleVisible(true);
if (m.quad) {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/cpp/Widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class Widget {
vrb::TransformPtr GetTransformNode() const;
const WidgetPlacementPtr& GetPlacement() const;
void SetPlacement(const WidgetPlacementPtr& aPlacement);
void StartResize(const vrb::Vector& aMaxSize);
void StartResize(const vrb::Vector& aMaxSize, const vrb::Vector& aMinSize);
void FinishResize();
bool IsResizing() const;
bool IsResizingActive() const;
Expand Down
9 changes: 6 additions & 3 deletions app/src/main/cpp/WidgetResizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ struct WidgetResizer::State {
vrb::Vector currentMax;
vrb::Vector pointerOffset;
vrb::Vector maxSize;
vrb::Vector minSize;
bool resizing;
vrb::TogglePtr root;
std::vector<ResizeHandlePtr> resizeHandles;
Expand All @@ -274,6 +275,7 @@ struct WidgetResizer::State {
currentMin = min;
currentMax = max;
maxSize = kDefaultMaxResize;
minSize = kDefaultMinResize;

vrb::Vector horizontalSize(0.0f, 0.5f, 0.0f);
vrb::Vector verticalSize(0.5f, 0.0f, 0.0f);
Expand Down Expand Up @@ -485,8 +487,8 @@ struct WidgetResizer::State {
}

// Clamp to max and min resize sizes
width = fmaxf(fminf(width, maxSize.x()), kDefaultMinResize.x());
height = fmaxf(fminf(height, maxSize.y()), kDefaultMinResize.y());
width = fmaxf(fminf(width, maxSize.x()), minSize.x());
height = fmaxf(fminf(height, maxSize.y()), minSize.y());
if (keepAspect) {
height = width / originalAspect;
}
Expand Down Expand Up @@ -529,8 +531,9 @@ WidgetResizer::SetSize(const vrb::Vector& aMin, const vrb::Vector& aMax) {
}

void
WidgetResizer::SetMaxSize(const vrb::Vector& aMaxSize) {
WidgetResizer::SetResizeLimits(const vrb::Vector& aMaxSize, const vrb::Vector& aMinSize) {
m.maxSize = aMaxSize;
m.minSize = aMinSize;
}

void
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/cpp/WidgetResizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class WidgetResizer {
static WidgetResizerPtr Create(vrb::CreationContextPtr& aContext, Widget * aWidget);
vrb::NodePtr GetRoot() const;
void SetSize(const vrb::Vector& aMin, const vrb::Vector& aMax);
void SetMaxSize(const vrb::Vector& aMaxSize);
void SetResizeLimits(const vrb::Vector& aMaxSize, const vrb::Vector& aMinSize);
void ToggleVisible(bool aVisible);
bool TestIntersection(const vrb::Vector& point) const;
void HandleResizeGestures(const vrb::Vector& aPoint, bool aPressed, bool& aResized, bool &aResizeEnded);
Expand Down

0 comments on commit e5eac7d

Please sign in to comment.