...
This commit is contained in:
10
ui/label.sx
10
ui/label.sx
@@ -3,9 +3,7 @@
|
||||
#import "ui/render.sx";
|
||||
#import "ui/events.sx";
|
||||
#import "ui/view.sx";
|
||||
|
||||
GLYPH_WIDTH_APPROX :f32: 8.0;
|
||||
GLYPH_HEIGHT_APPROX :f32: 16.0;
|
||||
#import "ui/font.sx";
|
||||
|
||||
Label :: struct {
|
||||
text: string;
|
||||
@@ -23,11 +21,7 @@ Label :: struct {
|
||||
|
||||
impl View for Label {
|
||||
size_that_fits :: (self: *Label, proposal: ProposedSize) -> Size {
|
||||
// Approximate: chars × avg glyph width, scaled by font size
|
||||
scale := self.font_size / GLYPH_HEIGHT_APPROX;
|
||||
w := xx self.text.len * GLYPH_WIDTH_APPROX * scale;
|
||||
h := self.font_size;
|
||||
Size.{ width = w, height = h };
|
||||
measure_text(self.text, self.font_size);
|
||||
}
|
||||
|
||||
layout :: (self: *Label, bounds: Frame) {
|
||||
|
||||
Reference in New Issue
Block a user