mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 15:19:59 +07:00
Revert "Revert "IJPL-60824 Implement the Run Widget minimum size""
This reverts commit ad30ac2046c31397a68ebf5a53444553e981468d. GitOrigin-RevId: c8ab3d1dc6cdfd70e27daf599957672adea6c9d9
This commit is contained in:
committed by
intellij-monorepo-bot
parent
e746ffce96
commit
0ad74d4af4
@@ -22,8 +22,6 @@ import com.intellij.openapi.actionSystem.ex.CustomComponentAction
|
||||
import com.intellij.openapi.actionSystem.impl.ActionButton
|
||||
import com.intellij.openapi.actionSystem.impl.ActionButtonWithText
|
||||
import com.intellij.openapi.actionSystem.impl.ActionToolbarImpl
|
||||
import com.intellij.openapi.actionSystem.impl.IdeaActionButtonLook.getIconPosition
|
||||
import com.intellij.openapi.actionSystem.impl.IdeaActionButtonLook.paintIconImpl
|
||||
import com.intellij.openapi.actionSystem.impl.Utils
|
||||
import com.intellij.openapi.actionSystem.remoting.ActionRemoteBehaviorSpecification
|
||||
import com.intellij.openapi.actionSystem.toolbarLayout.ToolbarLayoutStrategy
|
||||
@@ -56,11 +54,14 @@ import com.intellij.util.ui.EmptyIcon
|
||||
import com.intellij.util.ui.JBDimension
|
||||
import com.intellij.util.ui.JBInsets
|
||||
import com.intellij.util.ui.JBUI
|
||||
import com.intellij.util.ui.UIUtil
|
||||
import org.jetbrains.annotations.ApiStatus
|
||||
import java.awt.Color
|
||||
import java.awt.Component
|
||||
import java.awt.Dimension
|
||||
import java.awt.Graphics
|
||||
import java.awt.Insets
|
||||
import java.awt.Rectangle
|
||||
import java.awt.event.InputEvent
|
||||
import java.util.function.Predicate
|
||||
import javax.swing.Icon
|
||||
@@ -105,7 +106,6 @@ private fun createRunActionToolbar(): ActionToolbar {
|
||||
toolbar.setMinimumButtonSize {
|
||||
JBUI.size(JBUI.CurrentTheme.RunWidget.actionButtonWidth(), JBUI.CurrentTheme.RunWidget.toolbarHeight())
|
||||
}
|
||||
toolbar.setForceMinimumSize(true)
|
||||
toolbar.setActionButtonBorder(JBUI.CurrentTheme.RunWidget::toolbarBorderDirectionalGap, JBUI.CurrentTheme.RunWidget::toolbarBorderHeight)
|
||||
toolbar.setCustomButtonLook(RunWidgetButtonLook())
|
||||
return toolbar
|
||||
@@ -496,6 +496,13 @@ open class RedesignedRunConfigurationSelector : TogglePopupAction(), CustomCompo
|
||||
font = JBUI.CurrentTheme.RunWidget.configurationSelectorFont()
|
||||
}
|
||||
|
||||
override fun getButtonRect(): Rectangle? = super.buttonRect.apply {
|
||||
width -= getDownArrowIcon().iconWidth
|
||||
}
|
||||
|
||||
override fun getMinimumSize(): Dimension = preferredSize.apply {
|
||||
width = UIUtil.computeTextComponentMinimumSize(width, text, font?.let { getFontMetrics(it) }, 4)
|
||||
}
|
||||
}.also {
|
||||
it.foreground = JBUI.CurrentTheme.RunWidget.FOREGROUND
|
||||
it.setHorizontalTextAlignment(SwingConstants.LEFT)
|
||||
|
||||
@@ -5051,6 +5051,7 @@ f:com.intellij.util.ui.UIUtil
|
||||
- s:canDisplayFocusedState(java.awt.Component):Z
|
||||
- s:changeBackGround(java.awt.Component,java.awt.Color):V
|
||||
- s:colorToHex(java.awt.Color):java.lang.String
|
||||
- s:computeTextComponentMinimumSize(I,java.lang.String,java.awt.FontMetrics,I):I
|
||||
- s:configureNumericFormattedTextField(javax.swing.JFormattedTextField):V
|
||||
- s:convertToLabel(javax.swing.JEditorPane):V
|
||||
- s:createImage(I,I,I):java.awt.image.BufferedImage
|
||||
|
||||
@@ -560,6 +560,39 @@ public final class UIUtil {
|
||||
return ArrayUtilRt.toStringArray(lines);
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the minimum size the component must have to keep the given number of characters
|
||||
* <p>
|
||||
* Intended to be used for simple {@code JLabel}-like text components.
|
||||
* Often they provide the preferred size, but not the minimum size.
|
||||
* This function can be used to roughly compute the minimum size based on the preferred one.
|
||||
* The returned size will be reduced by the difference between the full text width and
|
||||
* the width of the text contracted to just the {@code nCharactersToKeep} first characters plus {@code "..."}
|
||||
* that's usually added by such components when the text doesn't fit.
|
||||
* </p>
|
||||
* <p>
|
||||
* Note that, due to various factors, the result may be off by a few pixels which is enough to gain or lose an extra character.
|
||||
* Because of fractional font metrics, fractional scaling, complicated calculations, rounding errors and other such things
|
||||
* it's hard to make strict guarantees here.
|
||||
* </p>
|
||||
* @param preferredSize the size of the component needed to keep everything, usually computed by {@link Component#getPreferredSize()}
|
||||
* @param text the currently set text
|
||||
* @param fontMetrics the current font metrics
|
||||
* @param nCharactersToKeep the number of characters the component must keep
|
||||
* @return the minimum size the component has to have to keep the given number of characters
|
||||
*/
|
||||
public static int computeTextComponentMinimumSize(
|
||||
int preferredSize,
|
||||
@Nullable String text,
|
||||
@Nullable FontMetrics fontMetrics,
|
||||
int nCharactersToKeep
|
||||
) {
|
||||
if (text == null || text.length() <= nCharactersToKeep || fontMetrics == null) return preferredSize;
|
||||
var fullTextWidth = fontMetrics.stringWidth(text);
|
||||
var minTextWidth = fontMetrics.stringWidth(text.substring(0, nCharactersToKeep) + "...");
|
||||
return preferredSize - (fullTextWidth - minTextWidth);
|
||||
}
|
||||
|
||||
public static void setActionNameAndMnemonic(@NotNull @Nls String text, @NotNull Action action) {
|
||||
assignMnemonic(text, action);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user