Skip to content

Commit

Permalink
Fix MenuPopup overlap anchor #199
Browse files Browse the repository at this point in the history
  • Loading branch information
BloCamLimb committed Jan 7, 2024
1 parent 765cbb7 commit 8556c8e
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ public Font getFont(int i) {
/**
* Returns the number of characters (i.e. constructor <code>limit - start</code> in code units).
*/
@ApiStatus.Internal
public int getCharCount() {
return mAdvances.length;
}
Expand All @@ -161,13 +162,15 @@ public int getCharCount() {
* @return advances, or null
* @see GraphemeBreak
*/
@ApiStatus.Internal
public float[] getAdvances() {
return mAdvances;
}

/**
* Helper of {@link #getAdvances()}.
*/
@ApiStatus.Internal
public float getAdvance(int i) {
if (i == mAdvances.length) {
return mAdvance;
Expand Down Expand Up @@ -213,6 +216,7 @@ public float getAdvance() {
return mAdvance;
}

@ApiStatus.Internal
public int getMemoryUsage() {
int m = 48;
m += 16 + MathUtil.align8(mGlyphs.length << 2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ private MenuPopupWindow createPopupWindow() {
MenuPopupWindow popupWindow = new MenuPopupWindow(
mContext);

//TODO Added by ModernUI, use Resources in the future
popupWindow.setBackgroundDrawable(new Drawable() {
private final float mRadius = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DP,
8, mContext.getResources().getDisplayMetrics());
Expand All @@ -240,6 +241,8 @@ public boolean getPadding(@NonNull Rect padding) {
});
popupWindow.setEnterTransition(new AutoTransition());
popupWindow.setExitTransition(new AutoTransition());
// always overlap
popupWindow.setOverlapAnchor(true);

popupWindow.setHoverListener(mMenuItemHoverListener);
popupWindow.setOnItemClickListener(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public StandardMenuPopup(Context context, @NonNull MenuBuilder menu,

mAnchorView = anchorView;

//TODO Added by ModernUI, use Resources in the future
mPopup = new MenuPopupWindow(context);
mPopup.setBackgroundDrawable(new Drawable() {
private final float mRadius = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DP,
Expand All @@ -141,6 +142,7 @@ public boolean getPadding(@NonNull Rect padding) {
});
mPopup.setEnterTransition(new AutoTransition());
mPopup.setExitTransition(new AutoTransition());
// always overlap
mPopup.setOverlapAnchor(true);

// Present the menu using our context, not the menu builder's context.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,9 @@ public void postShow() {
*/
@Override
public void show() {
// Fixed by Modern UI
// buildDropDown() needs to know OverlapAnchor or not
mPopup.setOverlapAnchor(mOverlapAnchor);
int height = buildDropDown();

if (mPopup.isShowing()) {
Expand Down Expand Up @@ -501,7 +504,7 @@ public void show() {
mPopup.setOutsideTouchable(!mForceIgnoreOutsideTouch && !mDropDownAlwaysVisible);
mPopup.setTouchInterceptor(mTouchInterceptor);
mPopup.setEpicenterBounds(mEpicenterBounds);
mPopup.setOverlapAnchor(mOverlapAnchor);
//mPopup.setOverlapAnchor(mOverlapAnchor);
mPopup.showAsDropDown(mDropDownAnchorView, mDropDownHorizontalOffset,
mDropDownVerticalOffset, mDropDownGravity);
mDropDownList.setSelection(ListView.INVALID_POSITION);
Expand Down
59 changes: 59 additions & 0 deletions core/src/test/java/icyllis/modernui/test/TestContextMenu.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Modern UI.
* Copyright (C) 2019-2024 BloCamLimb. All rights reserved.
*
* Modern UI is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* Modern UI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with Modern UI. If not, see <https://www.gnu.org/licenses/>.
*/

package icyllis.modernui.test

import icyllis.modernui.ModernUI
import icyllis.modernui.fragment.Fragment
import icyllis.modernui.graphics.drawable.ColorDrawable
import icyllis.modernui.util.DataSet
import icyllis.modernui.view.LayoutInflater
import icyllis.modernui.view.View
import icyllis.modernui.view.ViewGroup
import org.apache.logging.log4j.Level
import org.apache.logging.log4j.core.config.Configurator

fun main() {
System.setProperty("java.awt.headless", "true")
Configurator.setRootLevel(Level.ALL)
ModernUI().use { app -> app.run(TestContextMenu()) }
}

class TestContextMenu : Fragment() {

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: DataSet?
): View {
val view = View(context)
val color = 0xFF00_0000u
view.background = ColorDrawable(color.toInt())
view.layoutParams =
ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)
view.setOnCreateContextMenuListener { menu, _, _ ->
menu.add("1")
menu.add("2")
menu.add("3")
menu.add("4")
menu.add("5")
menu.add("6")
}
return view
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

package icyllis.modernui.test;

import icyllis.arc3d.image.GIFDecoder;
import icyllis.arc3d.core.image.GIFDecoder;
import icyllis.modernui.ModernUI;
import icyllis.modernui.graphics.Bitmap;
import org.apache.logging.log4j.Level;
Expand Down

0 comments on commit 8556c8e

Please sign in to comment.