Created
July 4, 2025 18:50
-
-
Save tresabhi/3043ebe789bd69f120f5b26c5d0d782a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // want | |
| import { Palette } from "generated/palette.slint"; | |
| import { HorizontalBox } from "std-widgets.slint"; | |
| export enum ButtonVariant { | |
| Solid, | |
| Outline | |
| } | |
| export component Button inherits Rectangle { | |
| in property <string> text; | |
| in property <ButtonVariant> variant: ButtonVariant.Solid; | |
| property <color> intractable-solid-color: area.has-hover ? Palette.accent-10 : Palette.accent-9; | |
| property <color> intractable-transparent-color: area.has-hover ? Palette.accent-a2 : transparent; | |
| border-radius: self.height / 2; | |
| background: variant == ButtonVariant.Solid ? intractable-solid-color : intractable-transparent-color; | |
| border-color: variant == ButtonVariant.Outline ? intractable-solid-color : transparent; | |
| border-width: variant == ButtonVariant.Outline ? 2px : 0px; | |
| animate background { duration: 200ms; } | |
| area := TouchArea { } | |
| VerticalLayout { | |
| padding-top: 12px; | |
| padding-bottom: 12px; | |
| padding-left: 16px; | |
| padding-right: 16px; | |
| HorizontalLayout { | |
| alignment: center; | |
| @children | |
| Text { | |
| color: Palette.base-12; | |
| text: root.text; | |
| } | |
| } | |
| } | |
| } | |
| // is | |
| import { Palette } from "generated/palette.slint"; | |
| import { HorizontalBox } from "std-widgets.slint"; | |
| export enum ButtonVariant { | |
| Solid, | |
| Outline | |
| } | |
| export component Button inherits Rectangle { | |
| in property <string> text; | |
| in property <ButtonVariant> variant: ButtonVariant.Solid; | |
| property <color> intractable-solid-color: area.has-hover ? Palette.accent-10 : Palette.accent-9; | |
| property <color> intractable-transparent-color: area.has-hover ? Palette.accent-a2 : transparent; | |
| border-radius: self.height / 2; | |
| background: variant == ButtonVariant.Solid ? intractable-solid-color : intractable-transparent-color; | |
| border-color: variant == ButtonVariant.Outline ? intractable-solid-color : transparent; | |
| border-width: variant == ButtonVariant.Outline ? 2px : 0px; | |
| animate background { duration: 200ms; } | |
| area := TouchArea { } | |
| VerticalLayout { | |
| padding-top: 12px; | |
| padding-bottom: 12px; | |
| padding-left: 16px; | |
| padding-right: 16px; | |
| HorizontalLayout { | |
| alignment: center; | |
| @children | |
| Text { | |
| color: Palette.base-12; | |
| text: root.text; | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment