This commit is contained in:
2025-08-27 20:27:22 -05:00
parent 4361d7b5cf
commit f41e583089
4 changed files with 77 additions and 17 deletions

View File

@@ -422,7 +422,9 @@ func (w *LinearLayout) updateLLHWidgetSize(wd Widget) {
}
}
}
wd.HandleResize((&Coord{X: w.getWeightedW(wd), Y: rH}).ResizeEvent())
c := &Coord{X: w.getWeightedW(wd), Y: rH}
w.Log("%s.updateLLHWidgetSize(%s) { %d, %d }", w.Id(), wd.Id(), c.X, c.Y)
wd.HandleResize(c.ResizeEvent())
}
// The Layout should have a static Size set at this point that we can use
@@ -551,9 +553,7 @@ func (w *LinearLayout) getWeightedW(wd Widget) int {
}
func (w *LinearLayout) SetStacked(s bool) { w.stacked = s }
func (w *LinearLayout) SetBordered(b bool) { w.insetBorder = b }
func (w *LinearLayout) SetLogger(l func(string, ...any)) { w.logger = l }
func (w *LinearLayout) Log(txt string, args ...any) {
if w.logger != nil {

View File

@@ -243,6 +243,7 @@ func (w *Menu) SetType(tp MenuType) { w.menuType = tp }
func (w *Menu) SetLabel(lbl string) { w.label = lbl }
func (w *Menu) SetFocusable(f bool) {}
func (w *Menu) GetItems() []*MenuItem { return w.items }
func (w *Menu) GetItem(idx int) *MenuItem {
if len(w.items) > idx {
return w.items[idx]
@@ -299,7 +300,14 @@ func (w *Menu) MoveUp(ev *tcell.EventKey) bool {
if w.menuType != MenuTypeV {
return false
}
st := w.cursor
w.cursor = (w.cursor - 1 + len(w.items)) % len(w.items)
for !w.items[w.cursor].Visible() {
w.cursor = (w.cursor - 1 + len(w.items)) % len(w.items)
if w.cursor == st {
return true
}
}
return true
}
@@ -307,7 +315,14 @@ func (w *Menu) MoveDown(ev *tcell.EventKey) bool {
if w.menuType != MenuTypeV {
return false
}
st := w.cursor
w.cursor = (w.cursor + 1) % len(w.items)
for !w.items[w.cursor].Visible() {
w.cursor = (w.cursor + 1) % len(w.items)
if w.cursor == st {
return true
}
}
return true
}
@@ -320,3 +335,14 @@ func (w *Menu) CreateMenuItem(lbl string, do func() bool, subItems ...*MenuItem)
}
return d
}
func (w *Menu) FindItem(id string) *MenuItem {
for _, itm := range w.items {
if itm.Id() == id {
return itm
} else if wrk := itm.FindItem(id); wrk != nil {
return wrk
}
}
return nil
}

View File

@@ -95,15 +95,7 @@ func (w *MenuItem) Draw(screen tcell.Screen) {
if !w.visible {
return
}
st := w.style
if w.active {
st = w.style.Reverse(true)
}
if w.disabled {
st = st.Dim(true)
st = st.Italic(true)
}
st := w.style.Reverse(w.active).Dim(w.disabled).Italic(w.disabled)
x, y := w.x, w.y
wd := w.w
wh.DrawText(x, y, wh.PadR(w.label, wd), st, screen)
@@ -188,7 +180,7 @@ func (w *MenuItem) MoveUp(ev *tcell.EventKey) bool {
st := w.cursor
i := (w.cursor - 1 + len(w.items)) % len(w.items)
for ; i != st; i = (i - 1 + len(w.items)) % len(w.items) {
if !w.items[i].IsDisabled() {
if !w.items[i].IsDisabled() && w.items[i].Visible() {
break
}
}
@@ -202,7 +194,7 @@ func (w *MenuItem) MoveDown(ev *tcell.EventKey) bool {
st := w.cursor
i := (st + 1) % len(w.items)
for ; i != st; i = (i + 1) % len(w.items) {
if !w.items[i].IsDisabled() {
if !w.items[i].IsDisabled() && w.items[i].Visible() {
break
}
}
@@ -214,6 +206,7 @@ func (w *MenuItem) SetLabel(lbl string) { w.label = lbl }
func (w *MenuItem) SetDisabled(d bool) { w.disabled = d }
func (w *MenuItem) IsDisabled() bool { return w.disabled }
func (w *MenuItem) GetItems() []*MenuItem { return w.items }
func (w *MenuItem) AddItems(iL ...*MenuItem) {
w.items = append(w.items, iL...)
for i := range w.items {
@@ -221,3 +214,14 @@ func (w *MenuItem) AddItems(iL ...*MenuItem) {
}
}
func (w *MenuItem) SetOnPressed(p func() bool) { w.onPressed = p }
func (w *MenuItem) FindItem(id string) *MenuItem {
for _, itm := range w.items {
if itm.Id() == id {
return itm
} else if wrk := itm.FindItem(id); wrk != nil {
return wrk
}
}
return nil
}

View File

@@ -15,7 +15,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
LIABILITY, .HETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
@@ -166,3 +166,33 @@ func (w *TopMenuLayout) Log(txt string, args ...any) {
w.logger(txt, args...)
}
}
func (w *TopMenuLayout) CreateMenuItem(id, lbl string, do func() bool, subItems ...*MenuItem) *MenuItem {
d := NewMenuItem(id, tcell.StyleDefault)
d.SetLabel(lbl)
d.SetOnPressed(do)
if len(subItems) > 0 {
d.AddItems(subItems...)
}
return d
}
func (w *TopMenuLayout) SetItemVisible(id string, v bool) bool {
if mi := w.FindItem(id); mi != nil {
w.Log("%s.SetItemVisible: Found Item: %s (Set Visible: %t)", w.Id(), id, v)
mi.SetVisible(v)
return true
}
w.Log("%s.SetItemVisible: Didn't find item with id: %s", w.Id(), id)
return false
}
func (w *TopMenuLayout) SetItemDisabled(id string, d bool) bool {
if mi := w.FindItem(id); mi != nil {
mi.SetDisabled(d)
return true
}
return false
}
func (w *TopMenuLayout) FindItem(id string) *MenuItem { return w.menu.FindItem(id) }