mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-27 18:36:12 +00:00
36 lines
1.1 KiB
Text
36 lines
1.1 KiB
Text
// Copyright © SixtyFPS GmbH <info@slint.dev>
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
import { MaterialStyleMetrics } from "../styling/material_style_metrics.slint";
|
|
import { MaterialPalette } from "../styling/material_palette.slint";
|
|
import { Typography } from "../styling/typography.slint";
|
|
import { MaterialText } from "material_text.slint";
|
|
|
|
export component Badge {
|
|
in property <string> text;
|
|
|
|
width: max(MaterialStyleMetrics.size_16, label.width + 2 * MaterialStyleMetrics.padding_4);
|
|
height: max(MaterialStyleMetrics.size_16, label.height);
|
|
|
|
background_layer := Rectangle {
|
|
width: parent.width;
|
|
height: parent.height;
|
|
border_radius: self.height / 2;
|
|
background: MaterialPalette.error;
|
|
}
|
|
|
|
label := MaterialText {
|
|
text: root.text;
|
|
color: MaterialPalette.on_error;
|
|
vertical_alignment: center;
|
|
horizontal_alignment: center;
|
|
style: Typography.label_small;
|
|
}
|
|
|
|
states [
|
|
small when root.text == "" : {
|
|
background_layer.width: MaterialStyleMetrics.size_6;
|
|
background_layer.height: MaterialStyleMetrics.size_6;
|
|
}
|
|
]
|
|
}
|