仿照qt的QGradient::Preset渐变类型写的,因为lvgl只支持水平/垂直渐变,且只支持两种颜色的渐变,所以有些类型的渐变未能实现,有些则缺少中间颜色。
代码:
namespace Gradient
{
enum Preset
{
WarmFlame = 1,
NightFade = 2,
SpringWarmth = 3,
JuicyPeach = 4,
YoungPassion = 5,
LadyLips = 6,
SunnyMorning = 7,
RainyAshville = 8,
FrozenDreams = 9,
WinterNeva = 10,
DustyGrass = 11,
TemptingAzure = 12,
HeavyRain = 13,
AmyCrisp = 14,
MeanFruit = 15,
DeepBlue = 16,
RipeMalinka = 17,
CloudyKnoxville = 18,
MalibuBeach = 19,
NewLife = 20,
TrueSunset = 21,
MorpheusDen = 22,
RareWind = 23,
NearMoon = 24,
WildApple = 25,
SaintPetersburg = 26,
PlumPlate = 28,
EverlastingSky = 29,
HappyFisher = 30,
Blessing = 31,
SharpeyeEagle = 32,
LadogaBottom = 33,
LemonGate = 34,
ItmeoBranding = 35,
ZeusMiracle = 36,
OldHat = 37,
StarWine = 38,
HappyAcid = 41,
AwesomePine = 42,
NewYork = 43,
ShyRainbow = 44,
MixedHopes = 46,
FlyHigh = 47,
StrongBliss = 48,
FreshMilk = 49,
SnowAgain = 50,
FebruaryInk = 51,
KindSteel = 52,
SoftGrass = 53,
GrownEarly = 54,
SharpBlues = 55,
ShadyWater = 56,
DirtyBeauty = 57,
GreatWhale = 58,
TeenNotebook = 59,
PoliteRumors = 60,
SweetPeriod = 61,
WideMatrix = 62,
SoftCherish = 63,
RedSalvation = 64,
BurningSpring = 65,
NightParty = 66,
SkyGlider = 67,
HeavenPeach = 68,
PurpleDivision = 69,
AquaSplash = 70,
SpikyNaga = 72,
LoveKiss = 73,
CleanMirror = 75,
PremiumDark = 76,
ColdEvening = 77,
CochitiLake = 78,
SummerGames = 79,
PassionateBed = 80,
MountainRock = 81,
DesertHump = 82,
JungleDay = 83,
PhoenixStart = 84,
OctoberSilence = 85,
FarawayRiver = 86,
AlchemistLab = 87,
OverSun = 88,
PremiumWhite = 89,
MarsParty = 90,
EternalConstance = 91,
JapanBlush = 92,
SmilingRain = 93,
CloudyApple = 94,
BigMango = 95,
HealthyWater = 96,
AmourAmour = 97,
RiskyConcrete = 98,
StrongStick = 99,
ViciousStance = 100,
PaloAlto = 101,
HappyMemories = 102,
MidnightBloom = 103,
Crystalline = 104,
PartyBliss = 106,
ConfidentCloud = 107,
LeCocktail = 108,
RiverCity = 109,
FrozenBerry = 110,
ChildCare = 112,
FlyingLemon = 113,
NewRetrowave = 114,
HiddenJaguar = 115,
AboveTheSky = 116,
Nega = 117,
DenseWater = 118,
Seashore = 120,
MarbleWall = 121,
CheerfulCaramel = 122,
NightSky = 123,
MagicLake = 124,
YoungGrass = 125,
ColorfulPeach = 126,
GentleCare = 127,
PlumBath = 128,
HappyUnicorn = 129,
AfricanField = 131,
SolidStone = 132,
OrangeJuice = 133,
GlassWater = 134,
NorthMiracle = 136,
FruitBlend = 137,
MillenniumPine = 138,
HighFlight = 139,
MoleHall = 140,
SpaceShift = 142,
ForestInei = 143,
RoyalGarden = 144,
RichMetal = 145,
JuicyCake = 146,
SmartIndigo = 147,
SandStrike = 148,
NorseBeauty = 149,
AquaGuidance = 150,
SunVeggie = 151,
SeaLord = 152,
BlackSea = 153,
GrassShampoo = 154,
LandingAircraft = 155,
WitchDance = 156,
SleeplessNight = 157,
AngelCare = 158,
CrystalRiver = 159,
SoftLipstick = 160,
SaltMountain = 161,
PerfectWhite = 162,
FreshOasis = 163,
StrictNovember = 164,
MorningSalad = 165,
DeepRelief = 166,
SeaStrike = 167,
NightCall = 168,
SupremeSky = 169,
LightBlue = 170,
MindCrawl = 171,
LilyMeadow = 172,
SugarLollipop = 173,
SweetDessert = 174,
MagicRay = 175,
TeenParty = 176,
FrozenHeat = 177,
GagarinView = 178,
FabledSunset = 179,
PerfectBlue = 180,
NumPresets
};
void setGradient(Gradient::Preset gradient,lv_draw_rect_dsc_t * rect_dsc);
}
void Gradient::setGradient(Preset gradient, lv_draw_rect_dsc_t *rect_dsc)
{
std::map<Preset,std::tuple<lv_color_t,lv_color_t,lv_grad_dir_t>> map;
map[WarmFlame] = std::make_tuple(lv_color_make(0xff,0x9a,0x9e),lv_color_make(0xfa,0xd0,0xc4),LV_GRAD_DIR_HOR);
map[NightFade] = std::make_tuple(lv_color_make(0xfb,0xc2,0xeb),lv_color_make(0xa1,0x8c,0xd1),LV_GRAD_DIR_VER);
map[SpringWarmth] = std::make_tuple(lv_color_make(0xff,0xd1,0xff),lv_color_make(0xfa,0xd0,0xc4),LV_GRAD_DIR_VER);
map[JuicyPeach] = std::make_tuple(lv_color_make(0xff,0xec,0xd2),lv_color_make(0xfc,0xb6,0x9f),LV_GRAD_DIR_HOR);
map[YoungPassion] = std::make_tuple(lv_color_make(0xff,0x81,0x77),lv_color_make(0xb1,0x2a,0x5b),LV_GRAD_DIR_HOR);
map[LadyLips] = std::make_tuple(lv_color_make(0xfe,0xcf,0xef),lv_color_make(0xff,0x9a,0x9e),LV_GRAD_DIR_VER);
map[SunnyMorning] = std::make_tuple(lv_color_make(0xf6,0xd3,0x65),lv_color_make(0xfd,0xa0,0x85),LV_GRAD_DIR_HOR);
map[RainyAshville] = std::make_tuple(lv_color_make(0xa6,0xc1,0xee),lv_color_make(0xfb,0xc2,0xeb),LV_GRAD_DIR_VER);
map[FrozenDreams] = std::make_tuple(lv_color_hex(0xe6dee9),lv_color_hex(0xfdcbf1),LV_GRAD_DIR_VER);
map[WinterNeva] = std::make_tuple(lv_color_hex(0xa1c4fd),lv_color_hex(0xc2e9fb),LV_GRAD_DIR_HOR);
map[DustyGrass] = std::make_tuple(lv_color_hex(0xd4fc79),lv_color_hex(0x96e6a1),LV_GRAD_DIR_HOR);
map[TemptingAzure] = std::make_tuple(lv_color_hex(0x84fab0),lv_color_hex(0x8fd3f4),LV_GRAD_DIR_HOR);
map[HeavyRain] = std::make_tuple(lv_color_hex(0xe2ebf0),lv_color_hex(0xcfd9df),LV_GRAD_DIR_VER);
map[AmyCrisp] = std::make_tuple(lv_color_hex(0xa6c0fe),lv_color_hex(0xf68084),LV_GRAD_DIR_HOR);
map[MeanFruit] = std::make_tuple(lv_color_hex(0xfccb90),lv_color_hex(0xd57eeb),LV_GRAD_DIR_HOR);
map[DeepBlue] = std::make_tuple(lv_color_hex(0xe0c3fc),lv_color_hex(0x8ec5fc),LV_GRAD_DIR_HOR);
map[RipeMalinka] = std::make_tuple(lv_color_hex(0xf093fb),lv_color_hex(0xf5576c),LV_GRAD_DIR_HOR);
map[CloudyKnoxville] = std::make_tuple(lv_color_hex(0xfdfbfb),lv_color_hex(0xebedee),LV_GRAD_DIR_HOR);
map[MalibuBeach] = std::make_tuple(lv_color_hex(0x4facfe),lv_color_hex(0x00f2fe),LV_GRAD_DIR_HOR);
map[NewLife] = std::make_tuple(lv_color_hex(0x38f9d7),lv_color_hex(0x43e97b),LV_GRAD_DIR_HOR);//20
map[TrueSunset] = std::make_tuple(lv_color_hex(0xfee140),lv_color_hex(0xfa709a),LV_GRAD_DIR_HOR);
map[MorpheusDen] = std::make_tuple(lv_color_hex(0x330867),lv_color_hex(0x30cfd0),LV_GRAD_DIR_VER);
map[RareWind] = std::make_tuple(lv_color_hex(0xfed6e3),lv_color_hex(0xa8edea),LV_GRAD_DIR_VER);
map[NearMoon] = std::make_tuple(lv_color_hex(0xb490ca),lv_color_hex(0x5ee7df),LV_GRAD_DIR_VER);
map[WildApple] = std::make_tuple(lv_color_hex(0xfef9d7),lv_color_hex(0xd299c2),LV_GRAD_DIR_VER);
map[SaintPetersburg] = std::make_tuple(lv_color_hex(0xf5f7fa),lv_color_hex(0xc3cfe2),LV_GRAD_DIR_HOR);
map[PlumPlate] = std::make_tuple(lv_color_hex(0x667eea),lv_color_hex(0x764ba2),LV_GRAD_DIR_HOR);
map[EverlastingSky] = std::make_tuple(lv_color_hex(0xfdfcfb),lv_color_hex(0xe2d1c3),LV_GRAD_DIR_HOR);
map[HappyFisher] = std::make_tuple(lv_color_hex(0x89f7fe),lv_color_hex(0x66a6ff),LV_GRAD_DIR_HOR);
map[Blessing] = std::make_tuple(lv_color_hex(0xd1fdff),lv_color_hex(0xfddb92),LV_GRAD_DIR_VER);
map[SharpeyeEagle] = std::make_tuple(lv_color_hex(0xb1f4cf),lv_color_hex(0x9890e3),LV_GRAD_DIR_VER);
map[LadogaBottom] = std::make_tuple(lv_color_hex(0xd9ded8),lv_color_hex(0xebc0fd),LV_GRAD_DIR_VER);
map[LemonGate] = std::make_tuple(lv_color_hex(0xf9f586),lv_color_hex(0x96fbc4),LV_GRAD_DIR_VER);
map[ItmeoBranding] = std::make_tuple(lv_color_hex(0x2af598),lv_color_hex(0x009efd),LV_GRAD_DIR_VER);
map[ZeusMiracle] = std::make_tuple(lv_color_hex(0xf6f3ff),lv_color_hex(0xcd9cf2),LV_GRAD_DIR_VER);//35
// map[OldHat] =
// map[StarWine] =
map[HappyAcid] = std::make_tuple(lv_color_hex(0x72afd3),lv_color_hex(0x37ecba),LV_GRAD_DIR_VER);
map[AwesomePine] = std::make_tuple(lv_color_hex(0xcfc7f8),lv_color_hex(0xebbba7),LV_GRAD_DIR_VER);
map[NewYork] = std::make_tuple(lv_color_hex(0xace0f9),lv_color_hex(0xfff1eb),LV_GRAD_DIR_VER);
// map[ShyRainbow] =
map[MixedHopes] = std::make_tuple(lv_color_hex(0xfa71cd),lv_color_hex(0xc471f5),LV_GRAD_DIR_VER);
map[FlyHigh] = std::make_tuple(lv_color_hex(0x6f86d6),lv_color_hex(0x48c6ef),LV_GRAD_DIR_VER);
// map[StrongBliss] =
map[FreshMilk] = std::make_tuple(lv_color_hex(0xf5efef),lv_color_hex(0xfeada6),LV_GRAD_DIR_VER);
map[SnowAgain] = std::make_tuple(lv_color_hex(0xeef1f5),lv_color_hex(0xe6e9f0),LV_GRAD_DIR_VER);
map[FebruaryInk] = std::make_tuple(lv_color_hex(0xe7f0fd),lv_color_hex(0xaccbee),LV_GRAD_DIR_VER);
map[KindSteel] = std::make_tuple(lv_color_hex(0xe9defa),lv_color_hex(0xfbfcdb),LV_GRAD_DIR_HOR);
map[SoftGrass] = std::make_tuple(lv_color_hex(0xdeecdd),lv_color_hex(0xc1dfc4),LV_GRAD_DIR_VER);
map[GrownEarly] = std::make_tuple(lv_color_hex(0x3cba92),lv_color_hex(0x0ba360),LV_GRAD_DIR_VER);
map[SharpBlues] = std::make_tuple(lv_color_hex(0x005bea),lv_color_hex(0x00c6fb),LV_GRAD_DIR_VER);
map[ShadyWater] = std::make_tuple(lv_color_hex(0x74ebd5),lv_color_hex(0x9face6),LV_GRAD_DIR_HOR);
map[DirtyBeauty] = std::make_tuple(lv_color_hex(0xbac8e0),lv_color_hex(0x6a85b6),LV_GRAD_DIR_VER);
map[GreatWhale] = std::make_tuple(lv_color_hex(0x6991c7),lv_color_hex(0xa3bded),LV_GRAD_DIR_VER);
map[TeenNotebook] = std::make_tuple(lv_color_hex(0xfbc8d4),lv_color_hex(0x9795f0),LV_GRAD_DIR_VER);
map[PoliteRumors] = std::make_tuple(lv_color_hex(0x8989ba),lv_color_hex(0xa7a6cb),LV_GRAD_DIR_VER);
// map[SweetPeriod] =
// map[WideMatrix] =
// map[SoftCherish] =
map[RedSalvation] = std::make_tuple(lv_color_hex(0x453a94),lv_color_hex(0xf43b47),LV_GRAD_DIR_VER);
// map[BurningSpring] =
map[NightParty] = std::make_tuple(lv_color_hex(0xd43f8d),lv_color_hex(0x0250c5),LV_GRAD_DIR_VER);
map[SkyGlider] = std::make_tuple(lv_color_hex(0x6e45e2),lv_color_hex(0x88d3ce),LV_GRAD_DIR_VER);
map[HeavenPeach] = std::make_tuple(lv_color_hex(0x97d9e1),lv_color_hex(0xd9afd9),LV_GRAD_DIR_VER);
map[PurpleDivision] = std::make_tuple(lv_color_hex(0xe5b2ca),lv_color_hex(0x7028e4),LV_GRAD_DIR_VER);
map[AquaSplash] = std::make_tuple(lv_color_hex(0x13547a),lv_color_hex(0x80d0c7),LV_GRAD_DIR_HOR);
// map[SpikyNaga] =
map[LoveKiss] = std::make_tuple(lv_color_hex(0xffb199),lv_color_hex(0xff0844),LV_GRAD_DIR_VER);
map[CleanMirror] = std::make_tuple(lv_color_hex(0x93a5cf),lv_color_hex(0xe4efe9),LV_GRAD_DIR_HOR);
map[PremiumDark] = std::make_tuple(lv_color_hex(0x434343),lv_color_hex(0x000000),LV_GRAD_DIR_HOR);
map[ColdEvening] = std::make_tuple(lv_color_hex(0xa2b6df),lv_color_hex(0x0c3483),LV_GRAD_DIR_VER);
map[CochitiLake] = std::make_tuple(lv_color_hex(0x93a5cf),lv_color_hex(0xe4efe9),LV_GRAD_DIR_HOR);
map[SummerGames] = std::make_tuple(lv_color_hex(0x92fe9d),lv_color_hex(0x00c9ff),LV_GRAD_DIR_HOR);
map[PassionateBed] = std::make_tuple(lv_color_hex(0xff758c),lv_color_hex(0xff7eb3),LV_GRAD_DIR_HOR);
map[MountainRock] = std::make_tuple(lv_color_hex(0x868f96),lv_color_hex(0x596164),LV_GRAD_DIR_HOR);
map[DesertHump] = std::make_tuple(lv_color_hex(0xdfa579),lv_color_hex(0xc79081),LV_GRAD_DIR_VER);
map[JungleDay] = std::make_tuple(lv_color_hex(0x8baaaa),lv_color_hex(0xae8b9c),LV_GRAD_DIR_HOR);
map[PhoenixStart] = std::make_tuple(lv_color_hex(0xf83600),lv_color_hex(0xf9d423),LV_GRAD_DIR_HOR);
map[OctoberSilence] = std::make_tuple(lv_color_hex(0xb721ff),lv_color_hex(0x21d4fd),LV_GRAD_DIR_HOR);
map[FarawayRiver] = std::make_tuple(lv_color_hex(0x6e45e2),lv_color_hex(0x88d3ce),LV_GRAD_DIR_HOR);
map[AlchemistLab] = std::make_tuple(lv_color_hex(0xd558c8),lv_color_hex(0x24d292),LV_GRAD_DIR_HOR);
map[OverSun] = std::make_tuple(lv_color_hex(0xabecd6),lv_color_hex(0xfbed96),LV_GRAD_DIR_HOR);
// map[PremiumWhite] =
map[MarsParty] = std::make_tuple(lv_color_hex(0x9b23ea),lv_color_hex(0x5f72bd),LV_GRAD_DIR_VER);
map[EternalConstance] = std::make_tuple(lv_color_hex(0x537895),lv_color_hex(0x09203f),LV_GRAD_DIR_VER);
map[JapanBlush] = std::make_tuple(lv_color_hex(0xddd6f3),lv_color_hex(0xfaaca8),LV_GRAD_DIR_HOR);
map[SmilingRain] = std::make_tuple(lv_color_hex(0xdcb0ed),lv_color_hex(0x99c99c),LV_GRAD_DIR_HOR);
map[CloudyApple] = std::make_tuple(lv_color_hex(0xe3eeff),lv_color_hex(0xf3e7e9),LV_GRAD_DIR_VER);
map[BigMango] = std::make_tuple(lv_color_hex(0xd09693),lv_color_hex(0xc71d6f),LV_GRAD_DIR_VER);
map[HealthyWater] = std::make_tuple(lv_color_hex(0x96deda),lv_color_hex(0x50c9c3),LV_GRAD_DIR_HOR);
map[AmourAmour] = std::make_tuple(lv_color_hex(0xfe5196),lv_color_hex(0xf77062),LV_GRAD_DIR_VER);
map[RiskyConcrete] = std::make_tuple(lv_color_hex(0xebebeb),lv_color_hex(0xc4c5c7),LV_GRAD_DIR_VER);
map[StrongStick] = std::make_tuple(lv_color_hex(0xa8caba),lv_color_hex(0x5d4157),LV_GRAD_DIR_HOR);
map[ViciousStance] = std::make_tuple(lv_color_hex(0x29323c),lv_color_hex(0x485563),LV_GRAD_DIR_HOR);
map[PaloAlto] = std::make_tuple(lv_color_hex(0xf4d03f),lv_color_hex(0x16a085),LV_GRAD_DIR_HOR);
map[HappyMemories] = std::make_tuple(lv_color_hex(0xf09819),lv_color_hex(0xff5858),LV_GRAD_DIR_HOR);
map[MidnightBloom] = std::make_tuple(lv_color_hex(0x4e4376),lv_color_hex(0x2b5876),LV_GRAD_DIR_HOR);
map[Crystalline] = std::make_tuple(lv_color_hex(0x8ddad5),lv_color_hex(0x00cdac),LV_GRAD_DIR_HOR);
map[PartyBliss] = std::make_tuple(lv_color_hex(0x04befe),lv_color_hex(0x4481eb),LV_GRAD_DIR_VER);
map[ConfidentCloud] = std::make_tuple(lv_color_hex(0xf3e7e9),lv_color_hex(0xdad4ec),LV_GRAD_DIR_VER);
map[LeCocktail] = std::make_tuple(lv_color_hex(0x874da2),lv_color_hex(0xc43a30),LV_GRAD_DIR_HOR);
map[RiverCity] = std::make_tuple(lv_color_hex(0x04befe),lv_color_hex(0x4481eb),LV_GRAD_DIR_VER);
map[FrozenBerry] = std::make_tuple(lv_color_hex(0xc7eafd),lv_color_hex(0xe8198b),LV_GRAD_DIR_VER);
map[ChildCare] = std::make_tuple(lv_color_hex(0xfdd6bd),lv_color_hex(0xf794a4),LV_GRAD_DIR_HOR);
map[FlyingLemon] = std::make_tuple(lv_color_hex(0x64b3f4),lv_color_hex(0xc2e59c),LV_GRAD_DIR_HOR);
map[NewRetrowave] = std::make_tuple(lv_color_hex(0xa981bb),lv_color_hex(0x3b41c5),LV_GRAD_DIR_VER);
map[HiddenJaguar] = std::make_tuple(lv_color_hex(0xf9f047),lv_color_hex(0x0fd850),LV_GRAD_DIR_VER);
// map[AboveTheSky] =
map[Nega] = std::make_tuple(lv_color_hex(0xee9ca7),lv_color_hex(0xffdde1),LV_GRAD_DIR_HOR);
map[DenseWater] = std::make_tuple(lv_color_hex(0x3ab5b0),lv_color_hex(0x56317a),LV_GRAD_DIR_HOR);
map[Seashore] = std::make_tuple(lv_color_hex(0x68e0cf),lv_color_hex(0x209cff),LV_GRAD_DIR_VER);
map[MarbleWall] = std::make_tuple(lv_color_hex(0xe6dee9),lv_color_hex(0xbdc2e8),LV_GRAD_DIR_VER);
map[CheerfulCaramel] = std::make_tuple(lv_color_hex(0xeacda3),lv_color_hex(0xe6b980),LV_GRAD_DIR_VER);
map[NightSky] = std::make_tuple(lv_color_hex(0x2a5298),lv_color_hex(0x1e3c72),LV_GRAD_DIR_VER);
map[MagicLake] = std::make_tuple(lv_color_hex(0xc9ffbf),lv_color_hex(0xffafbd),LV_GRAD_DIR_VER);
map[YoungGrass] = std::make_tuple(lv_color_hex(0x00e3ae),lv_color_hex(0x9be15d),LV_GRAD_DIR_VER);
map[ColorfulPeach] = std::make_tuple(lv_color_hex(0xed6ea0),lv_color_hex(0xec8c69),LV_GRAD_DIR_HOR);
map[GentleCare] = std::make_tuple(lv_color_hex(0xffc3a0),lv_color_hex(0xffafbd),LV_GRAD_DIR_HOR);
map[PlumBath] = std::make_tuple(lv_color_hex(0x6713d2),lv_color_hex(0xcc208e),LV_GRAD_DIR_VER);
map[HappyUnicorn] = std::make_tuple(lv_color_hex(0x12fff7),lv_color_hex(0xb3ffab),LV_GRAD_DIR_VER);
map[AfricanField] = std::make_tuple(lv_color_hex(0xFF6B95),lv_color_hex(0xFFC796),LV_GRAD_DIR_HOR);
map[SolidStone] = std::make_tuple(lv_color_hex(0x243949),lv_color_hex(0x517fa4),LV_GRAD_DIR_HOR);
map[OrangeJuice] = std::make_tuple(lv_color_hex(0xff9a44),lv_color_hex(0xfc6076),LV_GRAD_DIR_VER);
map[GlassWater] = std::make_tuple(lv_color_hex(0xffffff),lv_color_hex(0xdfe9f3),LV_GRAD_DIR_VER);
map[NorthMiracle] = std::make_tuple(lv_color_hex(0x00dbde),lv_color_hex(0xfc00ff),LV_GRAD_DIR_HOR);
map[FruitBlend] = std::make_tuple(lv_color_hex(0xf9d423),lv_color_hex(0xff4e50),LV_GRAD_DIR_HOR);
map[MillenniumPine] = std::make_tuple(lv_color_hex(0xf5d100),lv_color_hex(0x50cc7f),LV_GRAD_DIR_VER);
map[HighFlight] = std::make_tuple(lv_color_hex(0x0acffe),lv_color_hex(0x495aff),LV_GRAD_DIR_HOR);
map[MoleHall] = std::make_tuple(lv_color_hex(0x9bc5c3),lv_color_hex(0x616161),LV_GRAD_DIR_HOR);
// map[SpaceShift] =
map[ForestInei] = std::make_tuple(lv_color_hex(0xbfd9fe),lv_color_hex(0xdf89b5),LV_GRAD_DIR_VER);
map[RoyalGarden] = std::make_tuple(lv_color_hex(0xed6ea0),lv_color_hex(0xec8c69),LV_GRAD_DIR_HOR);
map[RichMetal] = std::make_tuple(lv_color_hex(0xd7d2cc),lv_color_hex(0x304352),LV_GRAD_DIR_HOR);
map[JuicyCake] = std::make_tuple(lv_color_hex(0xf9d423),lv_color_hex(0xe14fad),LV_GRAD_DIR_VER);
map[SmartIndigo] = std::make_tuple(lv_color_hex(0x7579ff),lv_color_hex(0xb224ef),LV_GRAD_DIR_VER);
map[SandStrike] = std::make_tuple(lv_color_hex(0xc1c161),lv_color_hex(0xd4d4b1),LV_GRAD_DIR_HOR);
map[NorseBeauty] = std::make_tuple(lv_color_hex(0xec77ab),lv_color_hex(0x7873f5),LV_GRAD_DIR_HOR);
map[AquaGuidance] = std::make_tuple(lv_color_hex(0x00ecbc),lv_color_hex(0x007adf),LV_GRAD_DIR_VER);
map[SunVeggie] = std::make_tuple(lv_color_hex(0x20E2D7),lv_color_hex(0xF9FEA5),LV_GRAD_DIR_HOR);
// map[SeaLord] =
// map[BlackSea] =
map[GrassShampoo] = std::make_tuple(lv_color_hex(0xDFFFCD),lv_color_hex(0x39F3BB),LV_GRAD_DIR_HOR);
// map[LandingAircraft] =
map[WitchDance] = std::make_tuple(lv_color_hex(0xA8BFFF),lv_color_hex(0x884D80),LV_GRAD_DIR_HOR);
map[SleeplessNight] = std::make_tuple(lv_color_hex(0x5271C4),lv_color_hex(0xECA1FE),LV_GRAD_DIR_HOR);
map[AngelCare] = std::make_tuple(lv_color_hex(0xFFE29F),lv_color_hex(0xFF719A),LV_GRAD_DIR_HOR);
map[CrystalRiver] = std::make_tuple(lv_color_hex(0x22E1FF),lv_color_hex(0x625EB1),LV_GRAD_DIR_HOR);
map[SoftLipstick] = std::make_tuple(lv_color_hex(0xB6CEE8),lv_color_hex(0xF578DC),LV_GRAD_DIR_HOR);
map[SaltMountain] = std::make_tuple(lv_color_hex(0xFFFEFF),lv_color_hex(0xD7FFFE),LV_GRAD_DIR_HOR);
map[PerfectWhite] = std::make_tuple(lv_color_hex(0xE3FDF5),lv_color_hex(0xFFE6FA),LV_GRAD_DIR_HOR);
map[FreshOasis] = std::make_tuple(lv_color_hex(0x7DE2FC),lv_color_hex(0xB9B6E5),LV_GRAD_DIR_HOR);
map[StrictNovember] = std::make_tuple(lv_color_hex(0xCBBACC),lv_color_hex(0x2580B3),LV_GRAD_DIR_HOR);
map[MorningSalad] = std::make_tuple(lv_color_hex(0xB7F8DB),lv_color_hex(0x50A7C2),LV_GRAD_DIR_HOR);
map[DeepRelief] = std::make_tuple(lv_color_hex(0x7085B6),lv_color_hex(0xDEF3F8),LV_GRAD_DIR_HOR);
// map[SeaStrike] =
map[NightCall] = std::make_tuple(lv_color_hex(0xAC32E4),lv_color_hex(0x4801FF),LV_GRAD_DIR_HOR);
map[SupremeSky] = std::make_tuple(lv_color_hex(0xD4FFEC),lv_color_hex(0x4596FB),LV_GRAD_DIR_HOR);
map[LightBlue] = std::make_tuple(lv_color_hex(0x9EFBD3),lv_color_hex(0x45D4FB),LV_GRAD_DIR_HOR);
map[MindCrawl] = std::make_tuple(lv_color_hex(0x473B7B),lv_color_hex(0x30D2BE),LV_GRAD_DIR_HOR);
map[LilyMeadow] = std::make_tuple(lv_color_hex(0x65379B),lv_color_hex(0x6457C6),LV_GRAD_DIR_HOR);
map[SugarLollipop] = std::make_tuple(lv_color_hex(0xA445B2),lv_color_hex(0xFF0066),LV_GRAD_DIR_HOR);
map[SweetDessert] = std::make_tuple(lv_color_hex(0x7742B2),lv_color_hex(0xFD8BD9),LV_GRAD_DIR_HOR);
map[MagicRay] = std::make_tuple(lv_color_hex(0xFF3CAC),lv_color_hex(0x2B86C5),LV_GRAD_DIR_HOR);
map[TeenParty] = std::make_tuple(lv_color_hex(0xFF057C),lv_color_hex(0x321575),LV_GRAD_DIR_HOR);
map[FrozenHeat] = std::make_tuple(lv_color_hex(0xFF057C),lv_color_hex(0x4CC3FF),LV_GRAD_DIR_HOR);
// map[GagarinView] =
// map[FabledSunset] =
map[PerfectBlue] = std::make_tuple(lv_color_hex(0x3D4E81),lv_color_hex(0x6E7FF3),LV_GRAD_DIR_HOR);
auto it = map.find(gradient);
if (it == map.end())
{
rect_dsc->bg_color = lv_color_hex(0xFFFFFF);
rect_dsc->bg_grad_color = lv_color_hex(0xFFFFFF);
rect_dsc->bg_grad_dir = LV_GRAD_DIR_HOR;
}
else
{
auto tuple = map[gradient];
rect_dsc->bg_color = std::get<0>(tuple);
rect_dsc->bg_grad_color = std::get<1>(tuple);
rect_dsc->bg_grad_dir = std::get<2>(tuple);
}
}
使用示例:
int main(int argc, char **argv)
{
lv_init();
hal_init();
lv_log_register_print_cb(esp32_log_cb);
lv_obj_t * page = lv_canvas_create(lv_scr_act());
lv_obj_set_size(page, LV_HOR_RES, LV_VER_RES); //设置为屏幕大小
lv_coord_t canvas_width = LV_HOR_RES;
lv_coord_t canvas_height = LV_VER_RES;
lv_img_cf_t color_format = LV_IMG_CF_TRUE_COLOR ; // ARGB8888格式
size_t buffer_size = lv_img_cf_get_px_size(color_format) * canvas_width / 8 * canvas_height;
std::unique_ptr<unsigned char[]> buffer = std::make_unique<unsigned char[]>(buffer_size);
lv_canvas_set_buffer(page, buffer.get(), canvas_width, canvas_height, color_format);
lv_draw_rect_dsc_t rect_dsc;
lv_draw_rect_dsc_init(&rect_dsc);// 初始化矩形样式描述符
Gradient::Preset set = Gradient::SoftLipstick;
Gradient::setGradient(set,&rect_dsc);
lv_canvas_draw_rect(page, 0, 0, LV_HOR_RES, LV_VER_RES, &rect_dsc);// 在Canvas上绘制一个矩形
while (1)
{
lv_timer_handler();
usleep(5 * 1000);
}
return 0;
}
相关内容:
Qt绘图:渐变_qt画圆环并填充颜色-CSDN博客