mirror of
https://github.com/zoriya/noctalia-shell.git
synced 2026-08-15 18:43:59 +00:00
Merge pull request #510 from sakarie9/media-max-width
MediaMini: implement dynamic width with max width setting
This commit is contained in:
@@ -1089,6 +1089,14 @@
|
||||
"label": "Visualizer-Typ",
|
||||
"description": "Stil des Audio-Visualizers auswählen."
|
||||
},
|
||||
"max-width": {
|
||||
"label": "Maximale Breite",
|
||||
"description": "Stellt die maximale Horizontalgröße des Widgets ein. Das Widget wird sich an kürzere Inhalte anpassen."
|
||||
},
|
||||
"use-fixed-width": {
|
||||
"label": "Feste Breite verwenden",
|
||||
"description": "Wenn aktiviert, verwendet das Widget immer die maximale Breite, anstatt sich dynamisch an den Inhalt anzupassen."
|
||||
},
|
||||
"scrolling-mode": {
|
||||
"label": "Scrollmodus",
|
||||
"description": "Steuern, wann Textscrolling für lange Track-Titel aktiviert ist."
|
||||
|
||||
@@ -1072,6 +1072,14 @@
|
||||
"label": "Visualizer type",
|
||||
"description": "Choose the style of audio visualizer to display."
|
||||
},
|
||||
"max-width": {
|
||||
"label": "Maximum Width",
|
||||
"description": "Sets the maximum horizontal size of the widget. The widget will shrink to fit shorter content."
|
||||
},
|
||||
"use-fixed-width": {
|
||||
"label": "Use Fixed Width",
|
||||
"description": "When enabled, the widget will always use the maximum width instead of dynamically adjusting to content."
|
||||
},
|
||||
"scrolling-mode": {
|
||||
"label": "Scrolling mode",
|
||||
"description": "Control when text scrolling is enabled for long track titles."
|
||||
|
||||
@@ -1072,6 +1072,14 @@
|
||||
"label": "Tipo de visualizador",
|
||||
"description": "Elegir el estilo de visualizador de audio a mostrar."
|
||||
},
|
||||
"max-width": {
|
||||
"label": "Ancho Máximo",
|
||||
"description": "Establece el tamaño horizontal máximo del widget. El widget se reducirá para adaptarse a contenido más corto."
|
||||
},
|
||||
"use-fixed-width": {
|
||||
"label": "Usar Ancho Fijo",
|
||||
"description": "Cuando está activado, el widget siempre usará el ancho máximo en lugar de ajustarse dinámicamente al contenido."
|
||||
},
|
||||
"scrolling-mode": {
|
||||
"label": "Modo de desplazamiento",
|
||||
"description": "Controlar cuándo está habilitado el desplazamiento de texto para títulos de pista largos."
|
||||
|
||||
@@ -1068,6 +1068,14 @@
|
||||
"label": "Type de visualiseur",
|
||||
"description": "Choisir le style de visualiseur audio à afficher."
|
||||
},
|
||||
"max-width": {
|
||||
"label": "Largeur Maximale",
|
||||
"description": "Définit la taille horizontale maximale du widget. Le widget se rétrécira pour s'adapter à un contenu plus court."
|
||||
},
|
||||
"use-fixed-width": {
|
||||
"label": "Utiliser une Largeur Fixe",
|
||||
"description": "Lorsque activé, le widget utilisera toujours la largeur maximale au lieu de s'ajuster dynamiquement au contenu."
|
||||
},
|
||||
"scrolling-mode": {
|
||||
"label": "Mode de défilement",
|
||||
"description": "Contrôler quand le défilement de texte est activé pour les titres de piste longs."
|
||||
|
||||
@@ -1072,6 +1072,14 @@
|
||||
"label": "Tipo de visualizador",
|
||||
"description": "Escolher o estilo de visualizador de áudio a exibir."
|
||||
},
|
||||
"max-width": {
|
||||
"label": "Largura Máxima",
|
||||
"description": "Define o tamanho horizontal máximo do widget. O widget será reduzido para se adequar a conteúdo mais curto."
|
||||
},
|
||||
"use-fixed-width": {
|
||||
"label": "Usar Largura Fixa",
|
||||
"description": "Quando ativado, o widget sempre usará a largura máxima em vez de ajustar dinamicamente ao conteúdo."
|
||||
},
|
||||
"scrolling-mode": {
|
||||
"label": "Modo de rolagem",
|
||||
"description": "Controlar quando a rolagem de texto está habilitada para títulos de faixa longos."
|
||||
|
||||
@@ -1072,6 +1072,14 @@
|
||||
"label": "可视化器类型",
|
||||
"description": "选择要显示的音频可视化器样式。"
|
||||
},
|
||||
"max-width": {
|
||||
"label": "最大宽度",
|
||||
"description": "设置小部件的最大水平尺寸。当内容较短时,小部件会自动收缩以适应内容。"
|
||||
},
|
||||
"use-fixed-width": {
|
||||
"label": "使用固定宽度",
|
||||
"description": "启用后,小部件将始终使用最大宽度,而不根据内容动态调整。"
|
||||
},
|
||||
"scrolling-mode": {
|
||||
"label": "滚动模式",
|
||||
"description": "控制何时为长曲目标题启用文本滚动。"
|
||||
|
||||
@@ -38,8 +38,9 @@ Item {
|
||||
readonly property string visualizerType: (widgetSettings.visualizerType !== undefined && widgetSettings.visualizerType !== "") ? widgetSettings.visualizerType : widgetMetadata.visualizerType
|
||||
readonly property string scrollingMode: (widgetSettings.scrollingMode !== undefined) ? widgetSettings.scrollingMode : widgetMetadata.scrollingMode
|
||||
|
||||
// Fixed width - no expansion
|
||||
readonly property real widgetWidth: Math.max(145, screen.width * 0.06)
|
||||
// Maximum widget width with user settings support
|
||||
readonly property real maxWidth: (widgetSettings.maxWidth !== undefined) ? widgetSettings.maxWidth : Math.max(widgetMetadata.maxWidth, screen.width * 0.06)
|
||||
readonly property bool useFixedWidth: (widgetSettings.useFixedWidth !== undefined) ? widgetSettings.useFixedWidth : widgetMetadata.useFixedWidth
|
||||
|
||||
readonly property bool hasActivePlayer: MediaService.currentPlayer !== null
|
||||
readonly property string placeholderText: I18n.tr("bar.widget-settings.media-mini.no-active-player")
|
||||
@@ -60,7 +61,7 @@ Item {
|
||||
}
|
||||
|
||||
implicitHeight: visible ? (isVerticalBar ? calculatedVerticalDimension() : Style.barHeight) : 0
|
||||
implicitWidth: visible ? (isVerticalBar ? calculatedVerticalDimension() : widgetWidth) : 0
|
||||
implicitWidth: visible ? (isVerticalBar ? calculatedVerticalDimension() : dynamicWidth) : 0
|
||||
|
||||
// "visible": Always Visible, "hidden": Hide When Empty, "transparent": Transparent When Empty
|
||||
visible: hideMode !== "hidden" || hasActivePlayer
|
||||
@@ -80,6 +81,49 @@ Item {
|
||||
return Math.round((Style.baseWidgetSize - 5) * scaling)
|
||||
}
|
||||
|
||||
function calculateContentWidth() {
|
||||
// Calculate the actual content width based on visible elements
|
||||
var contentWidth = 0
|
||||
var margins = Style.marginS * scaling * 2 // Left and right margins
|
||||
|
||||
// Icon or album art width
|
||||
if (!hasActivePlayer || !showAlbumArt) {
|
||||
// Icon width
|
||||
contentWidth += Style.fontSizeL * scaling
|
||||
} else if (showAlbumArt && hasActivePlayer) {
|
||||
// Album art width
|
||||
contentWidth += 21 * scaling
|
||||
}
|
||||
|
||||
// Spacing between icon/art and text
|
||||
contentWidth += Style.marginS * scaling
|
||||
|
||||
// Text width (use the measured width)
|
||||
contentWidth += fullTitleMetrics.contentWidth
|
||||
|
||||
// Additional small margin for text
|
||||
contentWidth += Style.marginXXS * 2
|
||||
|
||||
// Add container margins
|
||||
contentWidth += margins
|
||||
|
||||
return Math.ceil(contentWidth)
|
||||
}
|
||||
|
||||
// Dynamic width: adapt to content but respect maximum width setting
|
||||
readonly property real dynamicWidth: {
|
||||
// If using fixed width mode, always use maxWidth
|
||||
if (useFixedWidth) {
|
||||
return maxWidth
|
||||
}
|
||||
// Otherwise, adapt to content
|
||||
if (!hasActivePlayer) {
|
||||
return maxWidth
|
||||
}
|
||||
// Use content width but don't exceed user-set maximum width
|
||||
return Math.min(calculateContentWidth(), maxWidth)
|
||||
}
|
||||
|
||||
// A hidden text element to safely measure the full title width
|
||||
NText {
|
||||
id: fullTitleMetrics
|
||||
@@ -95,11 +139,19 @@ Item {
|
||||
visible: root.visible
|
||||
anchors.left: parent.left
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
width: isVerticalBar ? root.width : (widgetWidth)
|
||||
width: isVerticalBar ? root.width : dynamicWidth
|
||||
height: isVerticalBar ? width : Style.capsuleHeight
|
||||
radius: isVerticalBar ? width / 2 : Style.radiusM
|
||||
color: Settings.data.bar.showCapsule ? Color.mSurfaceVariant : Color.transparent
|
||||
|
||||
// Smooth width transition
|
||||
Behavior on width {
|
||||
NumberAnimation {
|
||||
duration: Style.animationNormal
|
||||
easing.type: Easing.InOutCubic
|
||||
}
|
||||
}
|
||||
|
||||
Item {
|
||||
id: mainContainer
|
||||
anchors.fill: parent
|
||||
|
||||
@@ -19,6 +19,8 @@ ColumnLayout {
|
||||
property bool valueShowVisualizer: widgetData.showVisualizer !== undefined ? widgetData.showVisualizer : widgetMetadata.showVisualizer
|
||||
property string valueVisualizerType: widgetData.visualizerType || widgetMetadata.visualizerType
|
||||
property string valueScrollingMode: widgetData.scrollingMode || widgetMetadata.scrollingMode
|
||||
property int valueMaxWidth: widgetData.maxWidth !== undefined ? widgetData.maxWidth : widgetMetadata.maxWidth
|
||||
property bool valueUseFixedWidth: widgetData.useFixedWidth !== undefined ? widgetData.useFixedWidth : widgetMetadata.useFixedWidth
|
||||
|
||||
Component.onCompleted: {
|
||||
if (widgetData && widgetData.hideMode !== undefined) {
|
||||
@@ -33,6 +35,8 @@ ColumnLayout {
|
||||
settings.showVisualizer = valueShowVisualizer
|
||||
settings.visualizerType = valueVisualizerType
|
||||
settings.scrollingMode = valueScrollingMode
|
||||
settings.maxWidth = parseInt(widthInput.text) || widgetMetadata.maxWidth
|
||||
settings.useFixedWidth = valueUseFixedWidth
|
||||
return settings
|
||||
}
|
||||
|
||||
@@ -87,6 +91,22 @@ ColumnLayout {
|
||||
minimumWidth: 200
|
||||
}
|
||||
|
||||
NTextInput {
|
||||
id: widthInput
|
||||
Layout.fillWidth: true
|
||||
label: I18n.tr("bar.widget-settings.media-mini.max-width.label")
|
||||
description: I18n.tr("bar.widget-settings.media-mini.max-width.description")
|
||||
placeholderText: widgetMetadata.maxWidth
|
||||
text: valueMaxWidth
|
||||
}
|
||||
|
||||
NToggle {
|
||||
label: I18n.tr("bar.widget-settings.media-mini.use-fixed-width.label")
|
||||
description: I18n.tr("bar.widget-settings.media-mini.use-fixed-width.description")
|
||||
checked: valueUseFixedWidth
|
||||
onToggled: checked => valueUseFixedWidth = checked
|
||||
}
|
||||
|
||||
NComboBox {
|
||||
label: I18n.tr("bar.widget-settings.media-mini.scrolling-mode.label")
|
||||
description: I18n.tr("bar.widget-settings.media-mini.scrolling-mode.description")
|
||||
|
||||
@@ -89,6 +89,8 @@ Singleton {
|
||||
"hideMode": "hidden",
|
||||
"scrollingMode"// "visible", "hidden", "transparent"
|
||||
: "hover",
|
||||
"maxWidth": 145,
|
||||
"useFixedWidth": false,
|
||||
"showAlbumArt": false,
|
||||
"showVisualizer": false,
|
||||
"visualizerType": "linear"
|
||||
|
||||
Reference in New Issue
Block a user