Skip to content

Commit

Permalink
[UI] Improved support for buttons that are icon-only.
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-manias committed Feb 23, 2025
1 parent c34cd17 commit c3c481c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
31 changes: 19 additions & 12 deletions scripts/gui/button.fluid
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ gui.button = function(Options)
self.disable = function(self)
self.disabled = true
self.viewport.acDisable()
self.text.opacity = 0.5
if self.text then self.text.opacity = 0.5 end
self.bkgd.fill = gui.style.button.bkgd
if self.events.disable then self.events.disable(self) end
self.viewport.acDraw()
Expand All @@ -32,7 +32,7 @@ gui.button = function(Options)
self.enable = function(self)
self.disabled = false
self.viewport.acDisable()
self.text.opacity = 1.0
if self.text then self.text.opacity = 1.0 end
self.bkgd.fill = gui.style.button.bkgd
if self.events.enable then self.events.enable(self) end
self.viewport.acDraw()
Expand Down Expand Up @@ -112,18 +112,25 @@ gui.button = function(Options)
overflow = VOF_HIDDEN
})

self.text = self._textClip.new('VectorText', {
x = GAP + label_offset,
y = FONT_HEIGHT + math.floor((HEIGHT - FONT_HEIGHT - (gui.style.widget.strokeWidth * 2)) * 0.5),
face = gui.fonts.button.face,
fontSize = string.format('%.2fpt', gui.fonts.button.size),
fill = gui.style.widget.text,
string = Options.text,
lineLimit = 1
})
if Options.text then
self.text = self._textClip.new('VectorText', {
x = GAP + label_offset,
y = FONT_HEIGHT + math.floor((HEIGHT - FONT_HEIGHT - (gui.style.widget.strokeWidth * 2)) * 0.5),
face = gui.fonts.button.face,
fontSize = string.format('%.2fpt', gui.fonts.button.size),
fill = gui.style.widget.text,
string = Options.text,
lineLimit = 1
})
end

if calc_width then
self.viewport.width = GAP + label_offset + self.text.textWidth + GAP
if Options.text then
self.viewport.width = GAP + label_offset + self.text.textWidth + GAP
else
self.viewport.width = (HEIGHT - ICON_SIZE) + ICON_SIZE
self.iconRender.x = (HEIGHT - ICON_SIZE) * 0.5
end
end

self.viewport.mtSubscribeFeedback(bit.bor(FM_HAS_FOCUS, FM_CHILD_HAS_FOCUS, FM_LOST_FOCUS), function(Viewport, Event)
Expand Down
4 changes: 2 additions & 2 deletions src/vector/vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -326,10 +326,10 @@ class extVectorGradient : public objVectorGradient {
FRGB Colour;
RGB8 ColourRGB; // A cached conversion of the FRGB value
STRING ID;
LONG NumericID;
LONG NumericID;
double Angle;
double Length;
bool CalcAngle; // True if the Angle/Length values require recalculation.
bool CalcAngle; // True if the Angle/Length values require recalculation.
};

class extVectorPattern : public objVectorPattern {
Expand Down

0 comments on commit c3c481c

Please sign in to comment.