Skip to content

Commit 0e88cf6

Browse files
committed
Button now hoas a _text_size_ setting.
1 parent b5e09bb commit 0e88cf6

2 files changed

Lines changed: 11 additions & 9 deletions

File tree

build.zig.zon

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.{
22
.name = .engine,
3-
.version = "0.9.7",
3+
.version = "0.9.8",
44
.fingerprint = 0xe8a81a8d0aa558d5,
55
.minimum_zig_version = "0.15.2",
66
.dependencies = .{
@@ -17,8 +17,8 @@
1717
.hash = "zigimg-0.1.0-8_eo2vBrFQBhsrLpexdcDQY-zrlzkyFZfKuYX-Nry6KN",
1818
},
1919
.resources = .{
20-
.url = "git+https://github.com/loftafi/resources.git#a2e19ef2f160fa6b2f604f4be9ea74d46220a3a0",
21-
.hash = "resources-0.8.0-J0GwI0A7AgDmjLZCTHb_b6QF49HOtRUwcRTJ4jHVXBFF",
20+
.url = "git+https://github.com/loftafi/resources.git#435fd7f45d3b8676ed21e119245591555a0f10eb",
21+
.hash = "resources-0.8.1-J0GwI-Y8AgCo63btSU4NZk9_Y_kWS5Gu6Lmb4Ki6nZp4",
2222
},
2323
},
2424
.paths = .{

src/engine.zig

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,7 @@ pub const Element = struct {
474474
button: struct {
475475
font: *Font = undefined,
476476
font_name: ?[]const u8 = null,
477+
text_size: TextSize = .normal,
477478
text: []const u8 = "",
478479
translated: []const u8 = "",
479480
text_texture: ?*sdl.SDL_Texture = null,
@@ -1272,7 +1273,7 @@ pub const Element = struct {
12721273
}
12731274

12741275
if (self.type.button.text_texture) |t| {
1275-
const size = TextSize.normal.pixel_size(display, t);
1276+
const size = self.type.button.text_size.pixel_size(display, t);
12761277
width += size.width;
12771278
}
12781279
return @max(self.minimum.width, width);
@@ -1596,7 +1597,7 @@ pub const Element = struct {
15961597

15971598
if (element.type.text_input.text.items.len > 0) {
15981599
if (element.type.text_input.texture) |texture| {
1599-
const size = .normal.pixel_size(display, texture);
1600+
const size = TextSize.normal.pixel_size(display, texture);
16001601
// Draw the text
16011602
var dest: Rect = .{
16021603
.x = @round(x),
@@ -1620,7 +1621,7 @@ pub const Element = struct {
16201621
}
16211622
} else {
16221623
if (element.type.text_input.placeholder_texture) |texture| {
1623-
const size = .normal.pixel_size(display, texture);
1624+
const size = TextSize.normal.pixel_size(display, texture);
16241625
// Draw the placeholder text
16251626
var dest: Rect = .{
16261627
.x = @round(x),
@@ -1886,7 +1887,7 @@ pub const Element = struct {
18861887
// The inner content can contain a button and/or text texture.
18871888
var content_width = element.type.button.icon_size.width;
18881889
if (element.type.button.text_texture) |texture| {
1889-
const size = .normal.pixel_size(display, texture);
1890+
const size = element.type.button.text_size.pixel_size(display, texture);
18901891

18911892
// Do we need space between text and icon?
18921893
if (content_width > 0)
@@ -1942,7 +1943,7 @@ pub const Element = struct {
19421943
}
19431944
}
19441945
if (element.type.button.text_texture) |texture| {
1945-
const size = .normal.pixel_size(display, texture);
1946+
const size = element.type.button.text_size.pixel_size(display, texture);
19461947
var dest: Rect = .{
19471948
.x = element.rect.x + element.type.button.icon_size.width + element.pad.left + content_offset,
19481949
.y = element.rect.y + (element.rect.height / 2.0) - (size.height / 2),
@@ -2011,7 +2012,7 @@ pub const Element = struct {
20112012
if (display.generate_text_texture(self.type.text_input.text.items, self.type.text_input.font)) |texture| {
20122013
self.type.text_input.texture = texture;
20132014
// For now, the cursor position is simply the end of the text.
2014-
self.type.text_input.cursor_pixels = .normal.pixel_size(display, texture).width;
2015+
self.type.text_input.cursor_pixels = TextSize.normal.pixel_size(display, texture).width;
20152016
}
20162017
} else {
20172018
self.type.text_input.cursor_pixels = 0;
@@ -5468,6 +5469,7 @@ pub fn setup_button(
54685469
element.type.button.background_pressed = null;
54695470
element.type.button.background_hover = null;
54705471
element.type.button.background_disabled = null;
5472+
element.type.button.text_size = .normal;
54715473
element.type.button.font = select_font(display.fonts.items, element.type.button.font_name);
54725474

54735475
if (element.focus == .unspecified)

0 commit comments

Comments
 (0)