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 opticalSizes = [20, 24, 40, 48];
160
161 function closestValue(arr, val) {
162 if (val <= arr[0])
163 return arr[0];
164 if (val >= arr[arr.length - 1])
165 return arr[arr.length - 1];
166 for (let i = 0; i < arr.length; ++i) {
167 if (val <= arr[i])
168 return arr[i];
169 }
170 return arr[arr.length - 1];
171 }
172
173 return {
174 "FILL": icon.fill ? 1 : 0,
175 "GRAD": closestValue(gradeValues, icon.grade),
176 "opsz": closestValue(opticalSizes, icon.opticalSize)
177 };
178 }
179 font.pixelSize: Math.max(icon.iconWidth, icon.iconHeight)
180 font.weight: icon.weight
181
182 horizontalAlignment: Text.AlignHCenter
183 verticalAlignment: Text.AlignVCenter
184
185 text: icon.name
186 textFormat: Text.PlainText
187
188 lineHeight: font.pixelSize
189 lineHeightMode: Text.FixedHeight
190
191 color: icon.color
192 Accessible.ignored: true
193 }
194}
Material Symbols icon tokens.
Definition symbol.h:17