| 1 |
# Rule.nas : horizontal or vertical dividing line, |
| 2 |
# optionally with a text label, eg to name a section |
| 3 |
# SPDX-FileCopyrightText: (C) 2022 James Turner <[email protected]> |
| 4 |
# SPDX-License-Identifier: GPL-2.0-or-later |
| 5 |
|
| 6 |
|
| 7 |
gui.widgets.HorizontalRule = { |
| 8 |
new: func(parent, style = nil, cfg = nil) |
| 9 |
{ |
| 10 |
style = style or canvas.style; |
| 11 |
cfg = Config.new(cfg); |
| 12 |
var m = gui.Widget.new(gui.widgets.HorizontalRule, cfg); |
| 13 |
m._focus_policy = m.NoFocus; |
| 14 |
m._setView( style.createWidget(parent, "rule", m._cfg) ); |
| 15 |
|
| 16 |
# should ask Style the rule height, not hard-code 1px |
| 17 |
m.setLayoutMinimumSize([16, 2]); |
| 18 |
m.setLayoutSizeHint([m._MAX_SIZE, 2]); # expand to fill |
| 19 |
m.setLayoutMaximumSize([m._MAX_SIZE, 2]); |
| 20 |
|
| 21 |
m.setText(m._cfg.get("text", "")); |
| 22 |
return m; |
| 23 |
}, |
| 24 |
setText: func(text) |
| 25 |
{ |
| 26 |
me._view.setText(me, text); |
| 27 |
return me; |
| 28 |
} |
| 29 |
}; |
| 30 |
|
| 31 |
gui.widgets.VerticalRule = { |
| 32 |
new: func(parent, style = nil, cfg = nil) |
| 33 |
{ |
| 34 |
style = style or canvas.style; |
| 35 |
cfg = Config.new(cfg); |
| 36 |
var m = gui.Widget.new(gui.widgets.VerticalRule, cfg); |
| 37 |
m._focus_policy = m.NoFocus; |
| 38 |
m._setView( style.createWidget(parent, "rule", m._cfg) ); |
| 39 |
|
| 40 |
# should ask Style the rule height, not hard-code 1px |
| 41 |
m.setLayoutMinimumSize([2, 16]); |
| 42 |
m.setLayoutSizeHint([2, m._MAX_SIZE]); # expand to fill |
| 43 |
m.setLayoutMaximumSize([2, m._MAX_SIZE]); |
| 44 |
|
| 45 |
m.setText(m._cfg.get("text", "")); |
| 46 |
return m; |
| 47 |
}, |
| 48 |
setText: func(text) |
| 49 |
{ |
| 50 |
me._view.setText(me, text); |
| 51 |
return me; |
| 52 |
} |
| 53 |
}; |