@papercraftgames/estragon 0.1.0-beta.20 → 0.1.0-beta.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -159,6 +159,9 @@ func _script(name: String, path: String, span: Model.Span, check_constructor: bo
159
159
  func _gogo(name: String, path: String, authored: String, span: Model.Span, check_constructor: bool = true) -> Dictionary:
160
160
  if visiting.has(path): return _fail("Cyclic Gogo component inheritance: "+path,span)
161
161
  visiting[path] = true
162
+ # Explicit imports can reach this path before project-tag lookup initializes
163
+ # the optional scope. Initialize it before testing its source index.
164
+ scope()
162
165
  var text: String = scope().read(project.authored(authored)) if project.sources.has(project.authored(authored)) else FileAccess.get_file_as_string(authored)
163
166
  var source := Source.new(text,authored,path,project)
164
167
  var module = Parser.new(source).parse()
@@ -48,11 +48,14 @@ func _component(node: Model.Component) -> void:
48
48
  if stack_direction.is_empty(): stack_direction = "row"
49
49
  for attribute in node.attributes:
50
50
  if attribute.name=="direction": stack_direction = str(attribute.value.value) if attribute.value is Model.Literal else StackContract.preset(resolved.script)
51
+ if VisualStyle.rect_conflict(resolved.script,node.attributes.map(func(item): return item.name)):
52
+ _error("Rect fill and background_color conflict; author only the canonical background_color or legacy fill",node.name_span)
53
+ return
51
54
  var seen: Dictionary = {}
52
55
  for attribute in node.attributes:
53
56
  var name := attribute.name
54
57
  if VisualStyle.property(name) and VisualStyle.has_api(resolved.script) and not VisualStyle.supported(resolved.script):
55
- _error("Shared visual styling on Text/Rect/Button is deferred to S02; use the existing local widget properties",attribute.name_span)
58
+ _error("Shared visual styling is unsupported on this participant",attribute.name_span)
56
59
  return
57
60
  if seen.has(name):
58
61
  _error("Duplicate Node property or signal " + name, attribute.name_span)
@@ -103,7 +106,7 @@ func _component(node: Model.Component) -> void:
103
106
  if not file.diagnostics.is_empty(): return
104
107
  var is_length := Length.registered(resolved.script,name)
105
108
  if is_length:
106
- _length(attribute,Length.domain(name))
109
+ _length(attribute,Length.domain(name,resolved.script))
107
110
  if not file.diagnostics.is_empty(): return
108
111
  if attribute.value is Model.Literal:
109
112
  if is_length or is_color:
@@ -10,7 +10,7 @@ func _init() -> void:
10
10
  func _submit(text: String) -> void:
11
11
  var name := str(get_edited_property())
12
12
  var value: Variant = float(text) if text.is_valid_float() else text
13
- var parsed := Length.parse(value,Length.domain(name))
13
+ var parsed := Length.parse(value,Length.domain(name,get_edited_object().get_script()))
14
14
  if parsed.has("error"):
15
15
  input.tooltip_text = parsed.error
16
16
  input.modulate = Color(1,0.5,0.5)
@@ -3,5 +3,5 @@
3
3
  name="Estragon"
4
4
  description="Native Gogo/GGX highlighting, compilation and validation before Play."
5
5
  author="Resist Design"
6
- version="0.1.0-beta.20"
6
+ version="0.1.0-beta.21"
7
7
  script="plugin.gd"
@@ -482,22 +482,29 @@ func _preflight(desired, previous, parent: Node, contracts: Variant = null) -> b
482
482
  if not message.is_empty():
483
483
  validation_error = desired.source+": "+message+"; previous tree retained"
484
484
  return false
485
+ if VisualStyle.rect_conflict(desired.type,desired.properties.keys()):
486
+ validation_error = desired.source+": Rect fill and background_color conflict; previous tree retained"
487
+ return false
485
488
  for key in desired.properties:
486
489
  if not properties.has(key) or key in ["script","owner"] or int(properties[key].usage)&PROPERTY_USAGE_READ_ONLY: return false
487
490
  var value = desired.properties[key]
488
491
  if VisualStyle.property(str(key)) and VisualStyle.has_api(desired.type) and not VisualStyle.supported(desired.type):
489
- validation_error = desired.source+": shared widget styling is deferred to S02; previous tree retained"
492
+ validation_error = desired.source+": shared visual styling is unsupported on this participant; previous tree retained"
490
493
  return false
491
494
  if key=="grow" and Length.registered(desired.type,"width") and (not typeof(value) in [TYPE_INT,TYPE_FLOAT] or not is_finite(float(value)) or value<0):
492
495
  validation_error = desired.source+": grow requires a finite nonnegative weight; previous tree retained"
493
496
  return false
497
+ if key=="fill" and VisualStyle.marked(desired.type,"ESTRAGON_RECT_STYLE"):
498
+ if not value is Color or VisualStyle.parse_color(value).has("error"):
499
+ validation_error = desired.source+": Rect fill requires a finite native Color; previous tree retained"
500
+ return false
494
501
  if VisualStyle.registered(desired.type,key):
495
502
  var parsed := VisualStyle.parse_color(value)
496
503
  if parsed.has("error"):
497
504
  validation_error = desired.source+": invalid style '"+str(key)+"': "+parsed.error+"; previous tree retained"
498
505
  return false
499
506
  if Length.registered(desired.type,key):
500
- var parsed := Length.parse(value,Length.domain(key))
507
+ var parsed := Length.parse(value,Length.domain(key,desired.type))
501
508
  if parsed.has("error"):
502
509
  validation_error = desired.source+": invalid length '"+str(key)+"': "+parsed.error+"; previous tree retained"
503
510
  return false
@@ -55,36 +55,3 @@ func _layout_options() -> Dictionary:
55
55
  var result := super._layout_options()
56
56
  result["alignment"] = [horizontal_align,vertical_align,"start"]
57
57
  return result
58
- var padding: Variant = 0.0:
59
- set(value):
60
- if is_same(padding,value) or not lengths.assign("padding",value): return
61
- padding = value
62
- _changed()
63
- var padding_top: Variant = "auto":
64
- set(value):
65
- if is_same(padding_top,value) or not lengths.assign("padding_top",value): return
66
- padding_top = value
67
- _changed()
68
- var padding_right: Variant = "auto":
69
- set(value):
70
- if is_same(padding_right,value) or not lengths.assign("padding_right",value): return
71
- padding_right = value
72
- _changed()
73
- var padding_bottom: Variant = "auto":
74
- set(value):
75
- if is_same(padding_bottom,value) or not lengths.assign("padding_bottom",value): return
76
- padding_bottom = value
77
- _changed()
78
- var padding_left: Variant = "auto":
79
- set(value):
80
- if is_same(padding_left,value) or not lengths.assign("padding_left",value): return
81
- padding_left = value
82
- _changed()
83
- func _get_property_list() -> Array[Dictionary]:
84
- var result: Array[Dictionary] = super._get_property_list()
85
- result.append_array(Length.properties(["padding","padding_top","padding_right","padding_bottom","padding_left"]))
86
- return result
87
-
88
- func _padding_insets() -> Vector4:
89
- layout.model.prepare(layout.model.parent_reference,layout.model.viewport_size)
90
- return layout.model.padding
@@ -3,13 +3,37 @@ class_name EstragonButton
3
3
  extends "text.gd"
4
4
  ## Native primary-pointer button. No Control widget or polling wrapper.
5
5
  signal pressed
6
- const PADDING := Vector2(14,8)
6
+ const ESTRAGON_BUTTON_STYLE := true
7
+ var hover_background_color: Variant = Color("#705a9e"):
8
+ set(value):
9
+ if is_same(hover_background_color,value) or not _visual_style.assign("hover_background_color",value): return
10
+ hover_background_color = value
11
+ _queue_style_redraw()
12
+ var pressed_background_color: Variant = Color("#302440"):
13
+ set(value):
14
+ if is_same(pressed_background_color,value) or not _visual_style.assign("pressed_background_color",value): return
15
+ pressed_background_color = value
16
+ _queue_style_redraw()
17
+ var disabled_background_color: Variant = Color("#38343f"):
18
+ set(value):
19
+ if is_same(disabled_background_color,value) or not _visual_style.assign("disabled_background_color",value): return
20
+ disabled_background_color = value
21
+ _queue_style_redraw()
22
+ func _init() -> void:
23
+ background_color = Color("#514174")
24
+ padding = "auto"
25
+ func _default_padding() -> Vector4:
26
+ return Vector4(14,8,14,8)
27
+ func _get_property_list() -> Array[Dictionary]:
28
+ var result: Array[Dictionary] = super._get_property_list()
29
+ result.append_array(Length.properties(["hover_background_color","pressed_background_color","disabled_background_color"]))
30
+ return result
7
31
  @export var disabled: bool = false:
8
32
  set(value):
9
33
  if disabled == value: return
10
34
  disabled = value
11
35
  _cancel_pointer()
12
- queue_redraw()
36
+ _queue_style_redraw()
13
37
  var _router: WeakRef
14
38
  var _hovered: bool = false
15
39
  var _held: bool = false
@@ -39,21 +63,20 @@ func _set_pointer_state(hovered: bool, held: bool) -> void:
39
63
  if _hovered == hovered and _held == held: return
40
64
  _hovered = hovered
41
65
  _held = held
42
- queue_redraw()
66
+ _queue_style_redraw()
43
67
  func _pointer_contains(position_in_viewport: Vector2) -> bool:
44
68
  var transform := get_global_transform_with_canvas()
45
69
  # Transform2D.determinant() is absent from the 4.0 public API.
46
70
  if is_zero_approx(transform.x.cross(transform.y)): return false
47
71
  return Rect2(Vector2.ZERO,layout_size).has_point(transform.affine_inverse()*position_in_viewport)
48
- func _measure_native() -> Vector2:
49
- return _measure_label()+PADDING*2
50
72
  func get_background_color() -> Color:
51
- if disabled: return Color("38343f")
52
- if _held and _hovered: return Color("302440")
53
- return Color("705a9e") if _hovered else Color("514174")
73
+ if disabled: return _visual_style.colors.disabled_background_color
74
+ if _held and _hovered: return _visual_style.colors.pressed_background_color
75
+ return _visual_style.colors.hover_background_color if _hovered else super.get_background_color()
76
+ func get_label_origin() -> Vector2:
77
+ var content := get_content_rect()
78
+ var remaining := (content.size-_measure_label())*0.5
79
+ return content.position+Vector2(maxf(0,remaining.x),maxf(0,remaining.y))
54
80
  func _draw() -> void:
55
- if layout_size.x <= 0 or layout_size.y <= 0: return
56
- draw_rect(Rect2(Vector2.ZERO,layout_size),get_background_color())
57
- var offset := (layout_size-_measure_label())*0.5
58
- offset = Vector2(maxf(0,offset.x),maxf(0,offset.y))
59
- _draw_label(offset,Color(1,1,1,0.5) if disabled else Color.WHITE)
81
+ if get_content_rect().size.x<=0 or get_content_rect().size.y<=0: return
82
+ _draw_label(get_label_origin(),Color(1,1,1,0.5) if disabled else Color.WHITE)
@@ -1,3 +1,4 @@
1
+ @icon("internal/component_2d_icon.tres")
1
2
  @tool
2
3
  class_name EstragonComponent2D
3
4
  extends Node2D
@@ -50,6 +51,31 @@ var border_left_width: Variant = "auto":
50
51
  border_left_width = value
51
52
  _changed()
52
53
  _queue_style_redraw()
54
+ var padding: Variant = 0.0:
55
+ set(value):
56
+ if is_same(padding,value) or not lengths.assign("padding",value,Length.domain("padding",get_script())): return
57
+ padding = value
58
+ _changed()
59
+ var padding_top: Variant = "auto":
60
+ set(value):
61
+ if is_same(padding_top,value) or not lengths.assign("padding_top",value): return
62
+ padding_top = value
63
+ _changed()
64
+ var padding_right: Variant = "auto":
65
+ set(value):
66
+ if is_same(padding_right,value) or not lengths.assign("padding_right",value): return
67
+ padding_right = value
68
+ _changed()
69
+ var padding_bottom: Variant = "auto":
70
+ set(value):
71
+ if is_same(padding_bottom,value) or not lengths.assign("padding_bottom",value): return
72
+ padding_bottom = value
73
+ _changed()
74
+ var padding_left: Variant = "auto":
75
+ set(value):
76
+ if is_same(padding_left,value) or not lengths.assign("padding_left",value): return
77
+ padding_left = value
78
+ _changed()
53
79
  var width: Variant = "auto":
54
80
  set(value):
55
81
  if is_same(width,value) or not lengths.assign("width",value): return
@@ -120,7 +146,7 @@ var layout_size: Vector2:
120
146
  var _layout_size := Vector2.ZERO
121
147
  var layout = Coordinator.new(self, 2, Coordinator.Mode.ENTRY if _is_layout_entry() else Coordinator.Mode.PARTICIPANT)
122
148
  func _get_property_list() -> Array[Dictionary]:
123
- var properties := Length.properties(["width","height","x","y","gap","margin","margin_top","margin_right","margin_bottom","margin_left"])
149
+ var properties := Length.properties(["width","height","x","y","gap","padding","padding_top","padding_right","padding_bottom","padding_left","margin","margin_top","margin_right","margin_bottom","margin_left"])
124
150
  if VisualStyle.supported(get_script()): properties.append_array(Length.properties(["border_width","border_top_width","border_right_width","border_bottom_width","border_left_width","background_color","border_color"]))
125
151
  return properties
126
152
  static func valid_length(value) -> bool:
@@ -142,6 +168,17 @@ func _layout_axis() -> int:
142
168
  func _measure_native() -> Vector2:
143
169
  return Vector2.ZERO
144
170
 
171
+ func _default_padding() -> Vector4:
172
+ return Vector4.ZERO
173
+
174
+ func _padding_insets() -> Vector4:
175
+ layout.model.prepare(layout.model.parent_reference,layout.model.viewport_size)
176
+ return layout.model.padding
177
+
178
+ func get_content_rect() -> Rect2:
179
+ var insets: Vector4 = layout.model.padding+layout.model.border
180
+ return Rect2(Vector2(insets.x,insets.y),Vector2(maxf(0,layout_size.x-insets.x-insets.z),maxf(0,layout_size.y-insets.y-insets.w)))
181
+
145
182
  func _layout_options() -> Dictionary:
146
183
  var natural := _measure_native()
147
184
  return {"axis":_layout_axis(),"fill":Vector3.ZERO,"intrinsic":Vector3(natural.x,natural.y,0)}
@@ -199,11 +236,13 @@ func _queue_style_redraw() -> void:
199
236
  _visual_style.redraw_count += 1
200
237
  queue_redraw()
201
238
  func _paint_visual_style() -> void:
202
- _visual_style.paint(self,layout_size,layout.model.border)
239
+ _visual_style.paint(self,layout_size,layout.model.border,get_background_color())
240
+ func get_background_color() -> Color:
241
+ return _visual_style.colors.background_color
203
242
  func get_visual_style_stats() -> Dictionary:
204
243
  return {"parse":_visual_style.parse_count,"draw":_visual_style.draw_count,"commands":_visual_style.command_count,"redraw":_visual_style.redraw_count}
205
244
 
206
245
  func _style_supported() -> bool:
207
246
  if VisualStyle.supported(get_script()): return true
208
- push_error("Estragon style: Text/Rect/Button painters retain their local API until S02")
247
+ push_error("Estragon style: shared visual styling is unsupported on this participant")
209
248
  return false
@@ -0,0 +1,4 @@
1
+ [gd_resource type="PlaceholderTexture2D" format=3]
2
+
3
+ [resource]
4
+ size = Vector2(16, 16)
@@ -135,8 +135,8 @@ func changed() -> void:
135
135
  model.set_policy(options.get("alignment",["start","start","start"]))
136
136
  if "lengths" in host:
137
137
  for property in host._get_property_list():
138
- if not Core.Length.domain(property.name).is_empty() and not host.lengths.specs.has(property.name): host.lengths.assign(property.name,host.get(property.name))
139
- model.set_lengths(host.lengths.specs,host.grow,host.stretch,host.pixels_per_unit if _dimension==3 else 1.0,options.axis)
138
+ if not Core.Length.domain(property.name).is_empty() and not host.lengths.specs.has(property.name): host.lengths.assign(property.name,host.get(property.name),Core.Length.domain(property.name,host.get_script()))
139
+ model.set_lengths(host.lengths.specs,host.grow,host.stretch,host.pixels_per_unit if _dimension==3 else 1.0,options.axis,host._default_padding() if host.has_method("_default_padding") else Vector4.ZERO)
140
140
  model.configure(host.requested_extent(),model.gap,host.center,options.axis,options.fill,options.intrinsic,model.padding if "lengths" in host else options.get("padding",Vector4.ZERO),model.margin if "lengths" in host else options.get("margin",Vector4.ZERO))
141
141
  else: model.configure(host.requested_extent(), host.gap, host.center)
142
142
 
@@ -50,8 +50,11 @@ var _measure_dirty: bool = true
50
50
  var _arrange_dirty: bool = true
51
51
  var _parent: WeakRef
52
52
 
53
- func set_lengths(specs: Dictionary, growth: float, cross: int, scale: float, stack_axis: int) -> void:
54
- if length_specs==specs and grow==growth and stretch==cross and pixels_per_unit==scale and axis==stack_axis: return
53
+ var default_padding := Vector4.ZERO
54
+
55
+ func set_lengths(specs: Dictionary, growth: float, cross: int, scale: float, stack_axis: int, padding_fallback: Vector4 = Vector4.ZERO) -> void:
56
+ if default_padding==padding_fallback and length_specs==specs and grow==growth and stretch==cross and pixels_per_unit==scale and axis==stack_axis: return
57
+ default_padding = padding_fallback
55
58
  length_specs = specs.duplicate(true)
56
59
  grow = growth
57
60
  stretch = cross
@@ -87,7 +90,9 @@ func _edges(prefix: String) -> Vector4:
87
90
  var index: int = edge%2
88
91
  var key: String = prefix+"_"+names[edge]+("_width" if prefix=="border" else "")
89
92
  var value := _length(key,index,-1)
90
- result[edge] = _length("border_width" if prefix=="border" else prefix,index,0) if value<0 else value
93
+ var uniform := _length("border_width" if prefix=="border" else prefix,index,0)
94
+ if prefix=="padding" and uniform<0: uniform = default_padding[edge]
95
+ result[edge] = uniform if value<0 else value
91
96
  return result
92
97
 
93
98
  # Resolve specs only on a changed parent/viewport/spec context. No property
@@ -13,7 +13,8 @@ const OFFSETS := ["x","y","z"]
13
13
  const EDGES := ["padding","padding_top","padding_right","padding_bottom","padding_left","margin","margin_top","margin_right","margin_bottom","margin_left"]
14
14
  var specs: Dictionary = {}
15
15
  var parse_count := 0
16
- static func domain(name: String) -> String:
16
+ static func domain(name: String, script = null) -> String:
17
+ if name=="padding" and VisualStyle.marked(script,"ESTRAGON_BUTTON_STYLE"): return "edge"
17
18
  if name in DIMENSIONS: return "extent"
18
19
  if name=="border_width": return "inset"
19
20
  if name in BORDER_EDGES: return "edge"
@@ -50,8 +51,8 @@ static func parse(value, kind: String) -> Dictionary:
50
51
  return {"unit":unit,"value":number}
51
52
  static func valid(value, kind: String) -> bool:
52
53
  return not parse(value,kind).has("error")
53
- func assign(name: String, value) -> bool:
54
- var parsed := parse(value,domain(name))
54
+ func assign(name: String, value, kind: String = "") -> bool:
55
+ var parsed := parse(value,domain(name) if kind.is_empty() else kind)
55
56
  parse_count += 1
56
57
  if parsed.has("error"):
57
58
  push_error("Estragon length '"+name+"': "+parsed.error)
@@ -1,12 +1,17 @@
1
1
  @tool
2
2
  extends RefCounted
3
3
  ## Local values and native paint only. No parent lookup, cascade or Nodes.
4
- const COLORS := ["background_color","border_color"]
5
- var colors := {"background_color":Color.TRANSPARENT,"border_color":Color.TRANSPARENT}
4
+ const COLORS := ["background_color","border_color","hover_background_color","pressed_background_color","disabled_background_color","checked_background_color"]
5
+ var colors := {"background_color":Color.TRANSPARENT,"border_color":Color.TRANSPARENT,"hover_background_color":Color("#705a9e"),"pressed_background_color":Color("#302440"),"disabled_background_color":Color("#38343f"),"checked_background_color":Color("#227a60")}
6
6
  var parse_count := 0
7
7
  var draw_count := 0
8
8
  var command_count := 0
9
9
  var redraw_count := 0
10
+ static func marked(script, marker: String) -> bool:
11
+ while script is Script:
12
+ if script.get_script_constant_map().get(marker,false): return true
13
+ script = script.get_base_script()
14
+ return false
10
15
  static func has_api(script) -> bool:
11
16
  while script is Script:
12
17
  if script.get_script_constant_map().get("ESTRAGON_VISUAL_STYLE",false): return true
@@ -21,7 +26,12 @@ static func supported(script) -> bool:
21
26
  static func property(name: String) -> bool:
22
27
  return name in COLORS or name in ["border_width","border_top_width","border_right_width","border_bottom_width","border_left_width"]
23
28
  static func registered(script, name: String) -> bool:
24
- return name in COLORS and supported(script)
29
+ if not supported(script): return false
30
+ if name in ["background_color","border_color"]: return true
31
+ if name=="checked_background_color": return marked(script,"ESTRAGON_TOGGLE_STYLE")
32
+ return name in COLORS and marked(script,"ESTRAGON_BUTTON_STYLE")
33
+ static func rect_conflict(script, names: Array) -> bool:
34
+ return marked(script,"ESTRAGON_RECT_STYLE") and "fill" in names and "background_color" in names
25
35
  static func parse_color(value) -> Dictionary:
26
36
  if value is Color:
27
37
  for channel in [value.r,value.g,value.b,value.a]:
@@ -48,10 +58,10 @@ func _rect(canvas: CanvasItem, rect: Rect2, color: Color) -> void:
48
58
  if rect.size.x<=0 or rect.size.y<=0 or color.a<=0: return
49
59
  canvas.draw_rect(rect,color)
50
60
  command_count += 1
51
- func paint(canvas: CanvasItem, extent: Vector2, border: Vector4) -> void:
61
+ func paint(canvas: CanvasItem, extent: Vector2, border: Vector4, background: Color) -> void:
52
62
  draw_count += 1
53
63
  if extent.x<=0 or extent.y<=0: return
54
- _rect(canvas,Rect2(Vector2.ZERO,extent),colors.background_color)
64
+ _rect(canvas,Rect2(Vector2.ZERO,extent),background)
55
65
  # Filled strips stay inside the border-box, including fractional/huge edges.
56
66
  # Top/bottom own the corners; side strips never double-blend those pixels.
57
67
  var left := minf(border.x,extent.x)
@@ -1,16 +1,15 @@
1
1
  @tool
2
2
  class_name EstragonRect
3
3
  extends "component_2d.gd"
4
- const ESTRAGON_LEGACY_PAINT := true
5
- ## Native rectangle drawing. Width/height are inherited layout inputs.
6
- @export var fill := Color.WHITE:
7
- set(value):
8
- if fill == value: return
9
- fill = value
10
- queue_redraw()
11
- func apply_layout_size(size: Vector3) -> void:
12
- super.apply_layout_size(size)
13
- queue_redraw()
14
- func _draw() -> void:
15
- if layout_size.x > 0 and layout_size.y > 0:
16
- draw_rect(Rect2(Vector2.ZERO,layout_size),fill)
4
+ ## background_color is canonical; fill is the legacy native Color view.
5
+ const ESTRAGON_RECT_STYLE := true
6
+ var fill: Color:
7
+ get: return _visual_style.colors.background_color
8
+ set(value): background_color = value
9
+ func _init() -> void:
10
+ background_color = Color.WHITE
11
+ func _get_property_list() -> Array[Dictionary]:
12
+ var result: Array[Dictionary] = super._get_property_list()
13
+ # Store only the canonical value, preserving its authored String/Color type.
14
+ result.append({"name":"fill","type":TYPE_COLOR,"usage":PROPERTY_USAGE_EDITOR})
15
+ return result
@@ -1,7 +1,6 @@
1
1
  @tool
2
2
  class_name EstragonText
3
3
  extends "component_2d.gd"
4
- const ESTRAGON_LEGACY_PAINT := true
5
4
  ## Native Font measure/draw, explicit lines only. No wrapping or rich text.
6
5
  @export var text: String = "":
7
6
  set(value):
@@ -62,6 +61,8 @@ func _draw_label(offset: Vector2 = Vector2.ZERO, tint: Color = Color.WHITE) -> v
62
61
  for line in text.split("\n"):
63
62
  if not line.is_empty(): draw_string(font,offset+Vector2(0,font.get_ascent(font_size)),line,HORIZONTAL_ALIGNMENT_LEFT,-1,font_size,color*tint)
64
63
  offset.y += font.get_height(font_size)
64
+ func get_label_origin() -> Vector2:
65
+ return get_content_rect().position
65
66
  func _draw() -> void:
66
- if layout_size.x <= 0 or layout_size.y <= 0: return
67
- _draw_label()
67
+ if get_content_rect().size.x <= 0 or get_content_rect().size.y <= 0: return
68
+ _draw_label(get_label_origin())
@@ -3,12 +3,23 @@ class_name EstragonToggle
3
3
  extends "button.gd"
4
4
  ## Controlled boolean input. Only pointer activation emits a user edit.
5
5
  signal value_changed(value: bool)
6
+ const ESTRAGON_TOGGLE_STYLE := true
7
+ var checked_background_color: Variant = Color("#227a60"):
8
+ set(next):
9
+ if is_same(checked_background_color,next) or not _visual_style.assign("checked_background_color",next): return
10
+ checked_background_color = next
11
+ _queue_style_redraw()
12
+ func _get_property_list() -> Array[Dictionary]:
13
+ var result: Array[Dictionary] = super._get_property_list()
14
+ result.append_array(Length.properties(["checked_background_color"]))
15
+ return result
6
16
  @export var value: bool = false:
7
17
  set(next):
8
18
  if value == next: return
9
19
  value = next
10
- queue_redraw()
20
+ _queue_style_redraw()
11
21
  func _init() -> void:
22
+ super._init()
12
23
  pressed.connect(_activate)
13
24
  func _activate() -> void:
14
25
  if disabled: return
@@ -16,8 +27,10 @@ func _activate() -> void:
16
27
  value_changed.emit(value)
17
28
  func get_background_color() -> Color:
18
29
  if disabled: return super.get_background_color()
19
- return Color("227a60") if value else super.get_background_color()
30
+ return _visual_style.colors.checked_background_color if value else super.get_background_color()
20
31
  func _draw() -> void:
21
32
  super._draw()
22
- if value and layout_size.x>0 and layout_size.y>0:
23
- draw_line(Vector2(2,layout_size.y-3),Vector2(layout_size.x-2,layout_size.y-3),Color("65f4b0"),3)
33
+ var border: Vector4 = layout.model.border
34
+ var inner := Rect2(Vector2(border.x,border.y),layout_size-Vector2(border.x+border.z,border.y+border.w))
35
+ if value and inner.size.x>4 and inner.size.y>4:
36
+ draw_line(inner.position+Vector2(2,inner.size.y-3),inner.position+Vector2(inner.size.x-2,inner.size.y-3),Color("65f4b0"),3)
package/package.json CHANGED
@@ -29,5 +29,5 @@
29
29
  "tag": "beta",
30
30
  "registry": "https://registry.npmjs.org/"
31
31
  },
32
- "version": "0.1.0-beta.20"
32
+ "version": "0.1.0-beta.21"
33
33
  }