Skip to content

Commit

Permalink
Merge pull request #76 from Clemapfel/mac-menubar-docs
Browse files Browse the repository at this point in the history
Merge
  • Loading branch information
Clemapfel authored Feb 8, 2024
2 parents c4609b4 + 4f16e9f commit b5dc8c2
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 153 deletions.
44 changes: 32 additions & 12 deletions src/Mousetrap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -376,11 +376,6 @@ module Mousetrap
push!(out.args, esc(
:(is_native_widget(::$Type) = return true)
))
#=
push!(out.args, esc(
:(Mousetrap.get_top_level_widget(x::$Type) = return x)
))
=#
return out
end

Expand Down Expand Up @@ -4162,7 +4157,7 @@ module Mousetrap
row_i = 1
for i in 1:get_n_columns(column_view)
column = get_column_at(column_view, i)
set_widget_at!(column_view, column, row_i, widgets[i]
set_widget_at!(column_view, column, row_i, widgets[i])
end
end
export push_front_row!
Expand Down Expand Up @@ -5548,45 +5543,70 @@ end # else MOUSETRAP_ENABLE_OPENGL_COMPONENT
connect_signal_name = :connect_signal_ * signal * :!
push!(out.args, esc(:(
function Mousetrap.$connect_signal_name(f, x::Widget)
$connect_signal_name(f, Mousetrap.get_top_level_widget(x))
if Mousetrap.is_native_widget(x)
log_critical(Mousetrap.MOUSETRAP_DOMAIN, "In " * $(string(connect_signal_name)) * ": object of type `$(typeof(x))` has no signal with ID `" * $(string(signal)) * "`")
else
$connect_signal_name(f, Mousetrap.get_top_level_widget(x))
end
end
)))

push!(out.args, esc(:(
function Mousetrap.$connect_signal_name(f, x::Widget, data::Data_t) where Data_t
$connect_signal_name(f, Mousetrap.get_top_level_widget(x), data)
if Mousetrap.is_native_widget(x)
log_critical(Mousetrap.MOUSETRAP_DOMAIN, "In " * $(string(connect_signal_name)) * ": object of type `$(typeof(x))` has no signal with ID `" * $(string(signal)) * "`")
else
$connect_signal_name(f, Mousetrap.get_top_level_widget(x), data)
end
end
)))

emit_signal_name = :emit_signal_ * signal

push!(out.args, esc(:(
function $emit_signal_name(x::Widget, args...)
$emit_signal_name(Mousetrap.get_top_level_widget(x), args)
if Mousetrap.is_native_widget(x)
log_critical(Mousetrap.MOUSETRAP_DOMAIN, "In " * $(string(emit_signal_name)) * ": object of type `$(typeof(x))` has no signal with ID `" * $(string(signal)) * "`")
else
$emit_signal_name(Mousetrap.get_top_level_widget(x), args)
end
end
)))

disconnect_signal_name = :disconnect_signal_ * signal * :!

push!(out.args, esc(:(
function $disconnect_signal_name(x::Widget)
$disconnect_signal_name(Mousetrap.get_top_level_widget(x))
if Mousetrap.is_native_widget(x)
log_critical(Mousetrap.MOUSETRAP_DOMAIN, "In " * $(string(disconnect_signal_name)) * ": object of type `$(typeof(x))` has no signal with ID `" * $(string(signal)) * "`")
else
$disconnect_signal_name(Mousetrap.get_top_level_widget(x))
end
end
)))

set_signal_blocked_name = :set_signal_ * signal * :_blocked * :!

push!(out.args, esc(:(
function $set_signal_blocked_name(x::Widget, b)
$set_signal_blocked_name(Mousetrap.get_top_level_widget(x), b)
if Mousetrap.is_native_widget(x)
log_critical(Mousetrap.MOUSETRAP_DOMAIN, "In " * $(string(set_signal_blocked_name)) * ": object of type `$(typeof(x))` has no signal with ID `" * $(string(signal)) * "`")
else
$set_signal_blocked_name(Mousetrap.get_top_level_widget(x), b)
end
end
)))

get_signal_blocked_name = :get_signal_ * signal * :_blocked

push!(out.args, esc(:(
function $get_signal_blocked_name(x::Widget)
return $get_signal_blocked_name(Mousetrap.get_top_level_widget(x))
if Mousetrap.is_native_widget(x)
log_critical(Mousetrap.MOUSETRAP_DOMAIN, "In " * $(string(get_signal_blocked_name)) * ": object of type `$(typeof(x))` has no signal with ID `" * $(string(signal)) * "`")
return false
else
return $get_signal_blocked_name(Mousetrap.get_top_level_widget(x))
end
end
)))
end
Expand Down
2 changes: 0 additions & 2 deletions src/docgen/signals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,8 @@ macro signal_table(T, signals...)

for signal_id in signals
push!(ids, string(signal_id))

signature = signal_descriptors[signal_id][1]
push!(signatures, replace(signature, "T" => string(T)))

push!(descriptions, signal_descriptors[signal_id][2])
end

Expand Down
16 changes: 15 additions & 1 deletion test/example.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
# File used for debugging and for dosc examples, why are you snooping through this file?

# File used for debugging and for dosc examples, why are you snooping through this file?
using Mousetrap

main() do app::Application
window = Window(app)
aspect_frame = AspectFrame(1.0)

set_child!(window, aspect_frame)

connect_signal_motion!(aspect_frame) do _, x, y
println((x,y))
end

present!(window)
end

#==
main() do app::Application
window = Window(app)
Expand Down
167 changes: 29 additions & 138 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2335,81 +2335,44 @@ end
function test_window(::Container)
@testset "Window" begin

window = Window(Main.app[])
other_window = Window(Main.app[])

Base.show(devnull, window)
@test Mousetrap.is_native_widget(window)

close_request_called = Ref{Bool}(false)
connect_signal_close_request!(window, close_request_called) do self::Window, close_request_called
close_request_called[] = true
return WINDOW_CLOSE_REQUEST_RESULT_ALLOW_CLOSE
end

activate_default_widget_called = Ref{Bool}(false)
connect_signal_activate_default_widget!(window, activate_default_widget_called) do self::Window, activate_default_widget_called
activate_default_widget_called[] = true
return nothing
end

activate_focused_widget_called = Ref{Bool}(false)
connect_signal_activate_focused_widget!(window, activate_focused_widget_called) do self::Window, activate_focused_widget_called
activate_focused_widget_called[] = true
return nothing
end

@test get_destroy_with_parent(window) == false
set_destroy_with_parent!(window, true)
@test get_destroy_with_parent(window) == true

@test get_focus_visible(window) == true
set_focus_visible!(window, false)
@test get_focus_visible(window) == false
main() do app::Application
window = Window(app)

@test get_has_close_button(window) == true
set_has_close_button!(window, false)
@test get_has_close_button(window) == false
# create column view with columns
column_view = ColumnView()

@test get_is_decorated(window) == true
set_is_decorated!(window, false)
@test get_is_decorated(window) == false
row_index_column = push_back_column!(column_view, " ")
count_column = push_back_column!(column_view, "#")
name_column = push_back_column!(column_view, "Name")
weight_column = push_back_column!(column_view, "Weight")
unit_column = push_back_column!(column_view, "Units")

@test get_is_modal(window) == false
set_is_modal!(window, true)
@test get_is_modal(window) == true
set_expand!.((row_index, count_column, name_column, weight_column, unit_column), true)

set_title!(window, "test")
@test get_title(window) == "test"
# fill columns with text
for i in 1:100
row = [
Label(string(i)), # row index
Label(string(rand(0:99))), # count
Label(rand(["Apple", "Orange", "Banana", "Kumquat", "Durian", "Mangosteen"])), # name
Label(string(rand(0:100))), # weight
Label(string(rand(["mg", "g", "kg", "ton"]))) # unit
]

button = Entry()
set_child!(window, button)
set_default_widget!(window, button)
activate!(button)

set_transient_for!(other_window, window)

#@test activate_default_widget_called[] == true
#@test activate_focused_widget_called[] == true

@test get_header_bar(window) isa HeaderBar
set_horizontal_alignment!.(row, ALIGNMENT_START)
push_back_row!(column_view, row...)
end

@test get_hide_on_close(window) == false
set_hide_on_close!(window, true)
@test get_hide_on_close(window) == true
# create viewport, this will add a scrollbar
scrolled_viewport = Viewport()
set_propagate_natural_width!(scrolled_viewport, true) # hides horizontal scrollbar
set_child!(scrolled_viewport, column_view)

@test get_is_closed(window) == true
present!(window)
@test get_is_closed(window) == false
set_minimized!(window, true)
set_maximized!(window, true)
# show both in window
set_child!(window, scrolled_viewport)
present!(window)

close!(other_window)
close!(window)
@test get_is_closed(window) == true
destroy!(window)
destroy!(other_window)
end
end

### WIDGET
Expand Down Expand Up @@ -2803,7 +2766,6 @@ end

main(Main.app_id) do app::Application

#=
Main.app[] = app
Main.window[] = Window(app)
set_is_decorated!(window, false) # prevent user from closing the window during tests
Expand Down Expand Up @@ -2889,78 +2851,7 @@ main(Main.app_id) do app::Application
present!(window)
close!(window)
#quit!(app)
=#

window = Window(Main.app[])
Base.show(devnull, window)
@test Mousetrap.is_native_widget(window)

close_request_called = Ref{Bool}(false)
connect_signal_close_request!(window, close_request_called) do self::Window, close_request_called
close_request_called[] = true
return WINDOW_CLOSE_REQUEST_RESULT_ALLOW_CLOSE
end

activate_default_widget_called = Ref{Bool}(false)
connect_signal_activate_default_widget!(window, activate_default_widget_called) do self::Window, activate_default_widget_called
activate_default_widget_called[] = true
return nothing
end

activate_focused_widget_called = Ref{Bool}(false)
connect_signal_activate_focused_widget!(window, activate_focused_widget_called) do self::Window, activate_focused_widget_called
activate_focused_widget_called[] = true
return nothing
end

@test get_destroy_with_parent(window) == false
set_destroy_with_parent!(window, true)
@test get_destroy_with_parent(window) == true

@test get_focus_visible(window) == true
set_focus_visible!(window, false)
@test get_focus_visible(window) == false

@test get_has_close_button(window) == true
set_has_close_button!(window, false)
@test get_has_close_button(window) == false

@test get_is_decorated(window) == true
set_is_decorated!(window, false)
@test get_is_decorated(window) == false

@test get_is_modal(window) == false
set_is_modal!(window, true)
@test get_is_modal(window) == true

set_title!(window, "test")
@test get_title(window) == "test"

button = Entry()
set_child!(window, button)
set_default_widget!(window, button)
activate!(button)

#@test activate_default_widget_called[] == true
#@test activate_focused_widget_called[] == true

@test get_header_bar(window) isa HeaderBar

@test get_hide_on_close(window) == false
set_hide_on_close!(window, true)
@test get_hide_on_close(window) == true

other_window = Window(app)
set_transient_for!(other_window, window)

@test get_is_closed(window) == true
present!(window)
@test get_is_closed(window) == false
set_minimized!(window, true)
set_maximized!(window, true)
close!(window)
@test get_is_closed(window) == true
destroy!(window)

println("TODO: done.")
end

0 comments on commit b5dc8c2

Please sign in to comment.