lipido / kargos

KDE Plasma port of GNOME Argos and OSX BitBar
GNU General Public License v3.0
126 stars 13 forks source link

Request: Add color gradient to text #34

Closed dyllan500 closed 4 years ago

dyllan500 commented 4 years ago

It would be a nice addition to an already great plasmoid. Below is an example and code of gradient text. I am not that knowledgeable in QML to figure out how to add it to the project. Thanks for all the great work.

gradient

import QtQuick 2.0
import org.kde.plasma.components 2.0 as PlasmaComponents
import QtQuick.Window 2.2
import QtGraphicalEffects 1.0

PlasmaComponents.Label {
    Rectangle {
        id: gradientRect;
        width: 10
        height: 10
        gradient: Gradient {
            GradientStop { position: 0; color: "red" }
            GradientStop { position: 1; color: "orange" }
        }
        visible: false;
        layer.enabled: true;
        layer.smooth: true
    }

    Text {
        id: txt
        anchors.centerIn: parent
        text: "Hello, world"
        font.pixelSize: 16
        layer.enabled: true
        layer.samplerName: "maskSource"
        layer.effect: ShaderEffect {
            property var colorSource: gradientRect;
            fragmentShader: "
                        uniform lowp sampler2D colorSource;
                        uniform lowp sampler2D maskSource;
                        uniform lowp float qt_Opacity;
                        varying highp vec2 qt_TexCoord0;
                        void main() {
                            gl_FragColor =
                                texture2D(colorSource, qt_TexCoord0)
                                * texture2D(maskSource, qt_TexCoord0).a
                                * qt_Opacity;
                        }
                    "
            }   
        }

}
shocklateboy92 commented 4 years ago

While that would be a cool feature, I think it's a little out of scope. Things like gradients should be the job of a Plasma theme.

I suspect there are already lots of plasma themes that give you the effect you're after. Otherwise, you can probably create one by turning that effect into an SVG.