Skip to content

Commit

Permalink
fix single line on not-editable ComboBox
Browse files Browse the repository at this point in the history
reference: #601 (review)
Signed-off-by: Ivan Morgillo <imorgillo@gmail.com>
  • Loading branch information
hamen committed Sep 20, 2024
1 parent d573cd5 commit 6095e94
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@ import com.intellij.util.ui.JBUI
import com.intellij.util.ui.components.BorderLayoutPanel
import icons.IdeSampleIconKeys
import icons.JewelIcons
import java.awt.Component
import javax.swing.BoxLayout
import javax.swing.DefaultComboBoxModel
import javax.swing.JLabel
import javax.swing.JPanel
import org.jetbrains.jewel.bridge.JewelComposePanel
import org.jetbrains.jewel.bridge.medium
import org.jetbrains.jewel.foundation.theme.JewelTheme
Expand All @@ -62,6 +57,11 @@ import org.jetbrains.jewel.ui.component.TextField
import org.jetbrains.jewel.ui.component.Typography
import org.jetbrains.jewel.ui.component.separator
import org.jetbrains.jewel.ui.theme.textAreaStyle
import java.awt.Component
import javax.swing.BoxLayout
import javax.swing.DefaultComboBoxModel
import javax.swing.JLabel
import javax.swing.JPanel

internal class SwingComparisonTabPanel : BorderLayoutPanel() {
private val mainContent =
Expand Down Expand Up @@ -201,7 +201,7 @@ internal class SwingComparisonTabPanel : BorderLayoutPanel() {
private fun Panel.comboBoxesRow() {
row("ComboBoxes:") {
// Swing ComboBoxes
val zoomLevels = arrayOf("100%", "125%", "150%", "175%", "200%", "300%")
val zoomLevels = arrayOf("100%", "125%", "150%", "175%", "200%", "300% eiojrwehiaeuhfd hfhiufh wephf wfnf fjoheiufhweuirh wqr")

JPanel()
.apply {
Expand Down Expand Up @@ -237,7 +237,7 @@ internal class SwingComparisonTabPanel : BorderLayoutPanel() {
Column(verticalArrangement = Arrangement.spacedBy(4.dp)) {
Text("Not editable")
ComboBox(
modifier = Modifier.width(100.dp),
modifier = Modifier.width(150.dp),
isEditable = false,
inputTextFieldState = inputTextFieldState,
menuContent = {
Expand Down Expand Up @@ -283,49 +283,51 @@ internal class SwingComparisonTabPanel : BorderLayoutPanel() {
}
},
)
ComboBox(
inputTextFieldState = inputTextFieldState,
outline = Outline.Warning,
menuContent = {
itemsComboBox.forEach {
if (it == "---") {
separator()
} else {
selectableItem(
selected = selectedComboBox == it,
onClick = {
selectedComboBox = it
inputTextFieldState.edit { replace(0, length, it) }
},
) {
Text(it)
Column(verticalArrangement = Arrangement.spacedBy(4.dp)) {
ComboBox(
inputTextFieldState = inputTextFieldState,
outline = Outline.Warning,
menuContent = {
itemsComboBox.forEach {
if (it == "---") {
separator()
} else {
selectableItem(
selected = selectedComboBox == it,
onClick = {
selectedComboBox = it
inputTextFieldState.edit { replace(0, length, it) }
},
) {
Text(it)
}
}
}
}
},
)
},
)

ComboBox(
inputTextFieldState = inputTextFieldState,
outline = Outline.Error,
menuContent = {
itemsComboBox.forEach {
if (it == "---") {
separator()
} else {
selectableItem(
selected = selectedComboBox == it,
onClick = {
selectedComboBox = it
inputTextFieldState.edit { replace(0, length, it) }
},
) {
Text(it)
ComboBox(
inputTextFieldState = inputTextFieldState,
outline = Outline.Error,
menuContent = {
itemsComboBox.forEach {
if (it == "---") {
separator()
} else {
selectableItem(
selected = selectedComboBox == it,
onClick = {
selectedComboBox = it
inputTextFieldState.edit { replace(0, length, it) }
},
) {
Text(it)
}
}
}
}
},
)
},
)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import androidx.compose.ui.layout.onSizeChanged
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import org.jetbrains.jewel.foundation.Stroke
import org.jetbrains.jewel.foundation.modifier.border
Expand Down Expand Up @@ -156,6 +157,8 @@ public fun ComboBox(
Text(
text = inputTextFieldState.text.toString(),
style = textStyle,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
modifier = Modifier.fillMaxWidth().padding(style.metrics.contentPadding),
)
}
Expand Down

0 comments on commit 6095e94

Please sign in to comment.