Fluid 1.3.0
Material Design for QtQuick and Qml
Loading...
Searching...
No Matches
Symbol.qml
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2025 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com>
2// SPDX-License-Identifier: MPL-2.0
3
4import QtQuick
5import Fluid as MD
6
42Item {
43 id: icon
44
45 // Symbols are decorative unless the caller opts in with the native
46 // Accessible attached properties.
47 Accessible.role: Accessible.Graphic
48 Accessible.ignored: Accessible.name.length === 0
49
51 enum Style {
52 Outlined,
53 Rounded,
54 Sharp
55 }
56
58 enum Grade {
59 LowEmphasis,
60 NormalEmphasis,
61 HighEmphasis
62 }
63
65 enum OpticalSize {
66 Small,
67 Normal,
68 Medium,
69 Large
70 }
71
75 property string name
76
80 property int iconWidth: MD.Tokens.symbol.size
81
85 property int iconHeight: MD.Tokens.symbol.size
86
90 property color color: MD.Style.onBackgroundColor
91
95 property int style: Symbol.Style.Outlined
96
100 property int weight: Font.Normal
101
105 property bool fill: false
106
116 property int grade: Symbol.Grade.NormalEmphasis
117
123 property int opticalSize: Symbol.OpticalSize.Normal
124
126 property alias horizontalAlignment: text.horizontalAlignment
127
129 property alias verticalAlignment: text.verticalAlignment
130
131 implicitWidth: iconWidth
132 implicitHeight: iconHeight
133
134 Text {
135 id: text
136
137 anchors.fill: parent
138
139 // Force the OS native layout engine when FILL axis is set to 1 since
140 // distance field algorithms struggle with overlapping vector geometry,
141 // dynamic geometric modifications, and shifting path outlines that
142 // happen when completely solidifying or modifying standard glyphs
143 // (like transitioning an outline icon font into a solid shape)
144 renderType: icon.fill ? Text.NativeRendering : Text.QtRendering
145
146 font.family: {
147 switch (icon.style) {
148 case Symbol.Style.Rounded:
149 return MD.Theme.symbolsRoundedFontFamily;
150 case Symbol.Style.Sharp:
151 return MD.Theme.symbolsSharpFontFamily;
152 case Symbol.Style.Outlined:
153 default:
154 return MD.Theme.symbolsOutlinedFontFamily;
155 }
156 }
157 font.variableAxes: {
158 const gradeValues = [-25, 0, 200];
159 const weightValues = [Font.Thin, Font.ExtraLight, Font.Light, Font.Normal, Font.Medium, Font.DemiBold, Font.Bold];
160 const opticalSizes = [20, 24, 40, 48];
161
162 function closestValue(arr, val) {
163 if (val <= arr[0])
164 return arr[0];
165 if (val >= arr[arr.length - 1])
166 return arr[arr.length - 1];
167 for (let i = 0; i < arr.length; ++i) {
168 if (val <= arr[i])
169 return arr[i];
170 }
171 return arr[arr.length - 1];
172 }
173
174 return {
175 "FILL": icon.fill ? 1 : 0,
176 "GRAD": closestValue(gradeValues, icon.grade),
177 "wght": closestValue(weightValues, icon.weight),
178 "opsz": closestValue(opticalSizes, icon.opticalSize)
179 };
180 }
181 font.pixelSize: Math.max(icon.iconWidth, icon.iconHeight) / scale
182
183 horizontalAlignment: Text.AlignHCenter
184 verticalAlignment: Text.AlignVCenter
185
186 text: icon.name
187 textFormat: Text.PlainText
188
189 lineHeight: MD.Tokens.typescale.labelLarge.lineHeight
190 lineHeightMode: Text.FixedHeight
191
192 // scale: 1.0 / MD.Tokens.calculateCurveScale(Screen.devicePixelRatio)
193
194 color: icon.color
195 Accessible.ignored: true
196 }
197}
Material Symbols icon tokens.
Definition symbol.h:17